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 char[]Common separators.static final StringThe encoding property.static final DateTimeFormatterISO 8601 date formatter.static final DateTimeFormatterISO 8601 date and time formatter.static final DateTimeFormatterISO 8601 time formatter.static final DateTimeFormatterISO 8601 Year formatter.static final DateTimeFormatterRFC 2822 date and time formatter. -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringabbreviate(String src, int max, String marker) Abbreviates aStringto the given length using a replacement marker.static StringbeatTime(ZonedDateTime zonedDateTime) Returns the Swatch Internet (.beat) Time for the give date-time.static StringcapitalizeWords(String src) Returns aStringwith the first letter of each word capitalized.static Stringencode(String src, Properties properties) Encodes the sourceStringto the specified encoding.static StringEncodes aStringto JavaScript/ECMAScript.static StringFetches the content (body) of a URL.static StringformatCreditCard(String src) Returns the last 4 digits a credit card number.static StringhtmlEntities(String src) Converts a textStringto HTML decimal entities.static StringMasks characters in a String.static StringNormalizes aStringfor inclusion in a URL path.static PropertiesReturns a newPropertiescontaining the properties specified in the givenString.static StringReturns the plural form of a word, if count > 1.static StringGenerates an SVG QR Code from the givenStringusing goQR.me.static StringTranslates aStringto/from ROT13.static StringshortenUrl(String url) Shortens a URL using is.gid.static StringSwaps the case of a String.static Stringuptime(long uptime, Properties properties) Returns the formatted server uptime.static booleanValidates a credit card number using the Luhn algorithm.
-
Field Details
-
COMMON_SEPARATORS
public static final char[] COMMON_SEPARATORSCommon separators. -
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 aStringto the given length using a replacement marker.- Parameters:
src- the sourceStringmax- the maximum length of the resultingStringmarker- theStringused 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 aStringwith the first letter of each word capitalized.- Parameters:
src- the sourceString- Returns:
- the capitalized
String
-
encode
Encodes the source
Stringto the specified encoding.The supported encodings are:
htmljsjsonunicodeurlxml
- Parameters:
src- the sourceStringto encodeproperties- the properties containing theencoding property.- Returns:
- the encoded
String
-
encodeJs
Encodes aStringto JavaScript/ECMAScript.- Parameters:
src- the sourceString- Returns:
- the encoded
String
-
fetchUrl
Fetches the content (body) of a URL.- Parameters:
url- the URLStringdefaultContent- 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 textStringto HTML decimal entities.- Parameters:
src- theStringto convert- Returns:
- the converted
String
-
mask
Masks characters in a String.- Parameters:
src- the sourceStringmask- theStringto mask characters withunmasked- the number of characters to leave unmaskedfromStart- to unmask characters from the start of theString- Returns:
- the masked
String
-
normalize
Normalizes aStringfor inclusion in a URL path.- Parameters:
src- the sourceString- Returns:
- the normalized
String
-
parsePropertiesString
Returns a newPropertiescontaining 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 givenStringusing goQR.me.- Parameters:
src- the dataStringsize- the QR Code size. (e.g.150x150)- Returns:
- the QR code
-
rot13
Translates aStringto/from ROT13.- Parameters:
src- the sourceString- Returns:
- the translated
String
-
shortenUrl
Shortens a URL using is.gid.
The URL
Stringmust 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- theStringto swap the case of- Returns:
- the modified
Stringor 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:
trueif the credit card number is valid
-