Package rife.render

Class RenderUtils

java.lang.Object
rife.render.RenderUtils

public final class RenderUtils extends Object
Collection of utility-type methods commonly used by the renderers.
Since:
1.0
Author:
Erik C. Thauvin
  • Field Details

    • ENCODING_PROPERTY

      public static final String ENCODING_PROPERTY
      The encoding property.
      See Also:
    • ISO_8601_DATE_FORMATTER

      public static final DateTimeFormatter ISO_8601_DATE_FORMATTER
      ISO 8601 date formatter.
      See Also:
    • ISO_8601_FORMATTER

      public static final DateTimeFormatter ISO_8601_FORMATTER
      ISO 8601 date and time formatter.
      See Also:
    • ISO_8601_TIME_FORMATTER

      public static final DateTimeFormatter ISO_8601_TIME_FORMATTER
      ISO 8601 time formatter.
      See Also:
    • ISO_8601_YEAR_FORMATTER

      public static final DateTimeFormatter ISO_8601_YEAR_FORMATTER
      ISO 8601 Year formatter.
      See Also:
    • RFC_2822_FORMATTER

      public static final DateTimeFormatter RFC_2822_FORMATTER
      RFC 2822 date and time formatter.
      See Also:
  • Method Details

    • abbreviate

      public static String abbreviate(String src, int max, String marker)
      Abbreviates a String to the given length using a replacement marker.
      Parameters:
      src - the source String
      max - the maximum length of the resulting String
      marker - the String used as a replacement marker
      Returns:
      the abbreviated String
    • beatTime

      public static String beatTime(ZonedDateTime zonedDateTime)
      Returns the Swatch Internet (.beat) Time for the give date-time.
      Parameters:
      zonedDateTime - the date and time
      Returns:
      the .beat time. (eg.: @248)
    • encode

      public static String encode(String src, Properties properties)

      Encodes the source String to the specified encoding.

      The supported encodings are:

      • html
      • js
      • json
      • unicode
      • url
      • xml
      Parameters:
      src - the source String to encode
      properties - the properties containing the encoding property.
      Returns:
      the encoded String
    • encodeJs

      public static String encodeJs(String src)
      Encodes a String to JavaScript/ECMAScript.
      Parameters:
      src - the source String
      Returns:
      the encoded String
    • fetchUrl

      public static String fetchUrl(String url, String defaultContent)
      Fetches the content (body) of a URL.
      Parameters:
      url - the URL String
      defaultContent - the default content to return if none fetched
      Returns:
      the url content, or empty
    • formatCreditCard

      public static String formatCreditCard(String src)

      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

      public static String htmlEntities(String src)
      Converts a text String to HTML decimal entities.
      Parameters:
      src - the String to convert
      Returns:
      the converted String
    • mask

      public static String mask(String src, String mask, int unmasked, boolean fromStart)
      Masks characters in a String.
      Parameters:
      src - the source String
      mask - the String to mask characters with
      unmasked - the number of characters to leave unmasked
      fromStart - to unmask characters from the start of the String
      Returns:
      the masked String
    • normalize

      public static String normalize(String src)
      Normalizes a String for inclusion in a URL path.
      Parameters:
      src - the source String
      Returns:
      the normalized String
    • parsePropertiesString

      public static Properties parsePropertiesString(String src)
      Returns a new Properties containing the properties specified in the given String.
      Parameters:
      src - the String containing the properties
      Returns:
      the new Properties
    • plural

      public static String plural(long count, String word, String plural)
      Returns the plural form of a word, if count > 1.
      Parameters:
      count - the count
      word - the singular word
      plural - the plural word
      Returns:
      the singular or plural String
    • qrCode

      public static String qrCode(String src, String size)
      Generates an SVG QR Code from the given String using goQR.me.
      Parameters:
      src - the data String
      size - the QR Code size. (e.g. 150x150)
      Returns:
      the QR code
    • rot13

      public static String rot13(String src)
      Translates a String to/from ROT13.
      Parameters:
      src - the source String
      Returns:
      the translated String
    • shortenUrl

      public static String shortenUrl(String url)

      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

      public static String swapCase(String src)
      Swaps the case of a String.
      Parameters:
      src - the String to swap the case of
      Returns:
      the modified String or null
    • uptime

      public static String uptime(long uptime, Properties properties)

      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 milliseconds
      properties - the format properties
      Returns:
      the formatted uptime
    • validateCreditCard

      public static boolean validateCreditCard(String cc)
      Validates a credit card number using the Luhn algorithm.
      Parameters:
      cc - the credit card number
      Returns:
      true if the credit card number is valid