Package rife.render
Class RenderUtils
java.lang.Object
rife.render.RenderUtils
Collection of utility-type methods commonly used by the renderers.
- Since:
- 1.0
- Author:
- Erik C. Thauvin
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The encoding property.static final DateTimeFormatter
ISO 8601 date formatter.static final DateTimeFormatter
ISO 8601 date and time formatter.static final DateTimeFormatter
ISO 8601 time formatter.static final DateTimeFormatter
ISO 8601 Year formatter.static final DateTimeFormatter
RFC 2822 date and time formatter. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
abbreviate
(String src, int max, String marker) Abbreviates aString
to the given length using a replacement marker.static String
beatTime
(ZonedDateTime zonedDateTime) Returns the Swatch Internet (.beat) Time for the give date-time.static String
capitalizeWords
(String src) Returns aString
with the first letter of each word capitalized.static String
encode
(String src, Properties properties) Encodes the sourceString
to the specified encoding.static String
Encodes aString
to JavaScript/ECMAScript.static String
Fetches the content (body) of a URL.static String
formatCreditCard
(String src) Returns the last 4 digits a credit card number.static String
htmlEntities
(String src) Converts a textString
to HTML decimal entities.static String
Masks characters in a String.static String
Normalizes aString
for inclusion in a URL path.static Properties
Returns a newProperties
containing the properties specified in the givenString
.static String
Returns the plural form of a word, if count > 1.static String
Generates an SVG QR Code from the givenString
using goQR.me.static String
Translates aString
to/from ROT13.static String
shortenUrl
(String url) Shortens a URL using is.gid.static String
Swaps the case of a String.static String
uptime
(long uptime, Properties properties) Returns the formatted server uptime.static boolean
Validates a credit card number using the Luhn algorithm.
-
Field Details
-
ENCODING_PROPERTY
The encoding property.- See Also:
-
ISO_8601_DATE_FORMATTER
ISO 8601 date formatter.- See Also:
-
ISO_8601_FORMATTER
ISO 8601 date and time formatter.- See Also:
-
ISO_8601_TIME_FORMATTER
ISO 8601 time formatter.- See Also:
-
ISO_8601_YEAR_FORMATTER
ISO 8601 Year formatter.- See Also:
-
RFC_2822_FORMATTER
RFC 2822 date and time formatter.- See Also:
-
-
Method Details
-
abbreviate
Abbreviates aString
to the given length using a replacement marker.- Parameters:
src
- the sourceString
max
- the maximum length of the resultingString
marker
- theString
used as a replacement marker- Returns:
- the abbreviated
String
-
beatTime
Returns the Swatch Internet (.beat) Time for the give date-time.- Parameters:
zonedDateTime
- the date and time- Returns:
- the .beat time. (eg.:
@248
)
-
capitalizeWords
Returns aString
with the first letter of each word capitalized.- Parameters:
src
- the sourceString
- Returns:
- the capitalized
String
-
encode
Encodes the source
String
to the specified encoding.The supported encodings are:
html
js
json
unicode
url
xml
- Parameters:
src
- the sourceString
to encodeproperties
- the properties containing theencoding property
.- Returns:
- the encoded
String
-
encodeJs
Encodes aString
to JavaScript/ECMAScript.- Parameters:
src
- the sourceString
- Returns:
- the encoded
String
-
fetchUrl
Fetches the content (body) of a URL.- Parameters:
url
- the URLString
defaultContent
- the default content to return if none fetched- Returns:
- the url content, or empty
-
formatCreditCard
Returns the last 4 digits a credit card number.
- The number must satisfy the Luhn algorithm
- Non-digits are stripped from the number
- Parameters:
src
- the credit card number- Returns:
- the last 4 digits of the credit card number or empty
-
htmlEntities
Converts a textString
to HTML decimal entities.- Parameters:
src
- theString
to convert- Returns:
- the converted
String
-
mask
Masks characters in a String.- Parameters:
src
- the sourceString
mask
- theString
to mask characters withunmasked
- the number of characters to leave unmaskedfromStart
- to unmask characters from the start of theString
- Returns:
- the masked
String
-
normalize
Normalizes aString
for inclusion in a URL path.- Parameters:
src
- the sourceString
- Returns:
- the normalized
String
-
parsePropertiesString
Returns a newProperties
containing the properties specified in the givenString
.- Parameters:
src
- the String containing the properties- Returns:
- the new
Properties
-
plural
Returns the plural form of a word, if count > 1.- Parameters:
count
- the countword
- the singular wordplural
- the plural word- Returns:
- the singular or plural
String
-
qrCode
Generates an SVG QR Code from the givenString
using goQR.me.- Parameters:
src
- the dataString
size
- the QR Code size. (e.g.150x150
)- Returns:
- the QR code
-
rot13
Translates aString
to/from ROT13.- Parameters:
src
- the sourceString
- Returns:
- the translated
String
-
shortenUrl
Shortens a URL using is.gid.
The URL
String
must be a valid http or https URL.Based on isgd-shorten
- Parameters:
url
- the source URL- Returns:
- the short URL
-
swapCase
Swaps the case of a String.- Parameters:
src
- theString
to swap the case of- Returns:
- the modified
String
or null
-
uptime
Returns the formatted server uptime.
The default Properties are:
year=\ year⧵u0020 years=\ years⧵u0020 month=\ month⧵u0020 months=\ months⧵u0020 week=\ week⧵u0020 weeks=\ weeks⧵u0020 day=\ day⧵u0020 days=\ days⧵u0020 hour=\ hour⧵u0020 hours=\ hours⧵u0020 minute=\ minute minutes=\ minutes
- Parameters:
uptime
- the uptime in millisecondsproperties
- the format properties- Returns:
- the formatted uptime
-
validateCreditCard
Validates a credit card number using the Luhn algorithm.- Parameters:
cc
- the credit card number- Returns:
true
if the credit card number is valid
-