Package com.day.text

Class Text


  • public final class Text
    extends java.lang.Object
    This class holds a collection of useful string operations that are not available in java.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DEFAULT_DATE_FORMAT_PATTERN
      The default format pattern used in strftime() if no pattern parameter has been supplied.
      static char[] hexTable
      used for the md5
      static java.lang.String NON_VALID_CHARS
      Non-valid handle characters: / \ : * ? " < > | and carriage return.
      (That's slash, backslash, colon, asterisk, question mark, quotation mark, less than symbol, greater than symbol, pipe, and carriage return.)
      static java.util.TimeZone TIMEZONE_LOCAL
      The local timezone
      static java.util.TimeZone TIMEZONE_UTC
      The UTC timezone
      static java.util.BitSet URISave
      The list of characters that are not encoded by the escape() and unescape() methods.
      static java.util.BitSet URISaveEx
      Same as URISave but also contains the '/'
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static int compareHandles​(java.lang.String h1, java.lang.String h2)
      compares to handles lexigographically with one exception: the '/' character is always considered smaller than all other chars.
      static java.lang.String createValidLabel​(java.lang.String labelhint)
      Create a valid label out of an arbitrary string.
      static java.lang.String dateToRfc1123String​(java.util.Date date)
      Returns a stringified date accoring to the date format specified in RTF1123.
      static java.lang.String digest​(java.lang.String algorithm, byte[] data)
      Digest the plain string using the given algorithm.
      static java.lang.String digest​(java.lang.String algorithm, java.lang.String data)
      static java.lang.String digest​(java.lang.String algorithm, java.lang.String data, java.lang.String enc)
      Digest the plain string using the given algorithm.
      static java.lang.String escape​(java.lang.String string)
      Does a URL encoding of the string.
      static java.lang.String escape​(java.lang.String string, char escape)
      Does an URL encoding of the string using the escape character.
      static java.lang.String escape​(java.lang.String string, char escape, boolean isPath)
      Does an URL encoding of the string using the escape character.
      static java.lang.String escapePath​(java.lang.String path)
      Does a URL encoding of the path.
      static java.lang.String escapeXml​(java.lang.String string)
      Escapes all character that have specific meaning in XMl/HTML, namely '<', '>', '"', '&' by their isolating encoding aequivalents "&lt;", "&gt", "&quot;", "&amp;"
      static java.lang.String[] explode​(java.lang.String str, int ch)
      returns an array of strings decomposed of the original string, split at every occurance of 'ch'.
      static java.lang.String[] explode​(java.lang.String str, int ch, boolean respectEmpty)
      returns an array of strings decomposed of the original string, split at every occurance of 'ch'.
      static java.lang.String formatISO8601​(java.util.Calendar cal)
      Formats a Calendar value into an ISO8601-compliant date/time string.
      static java.lang.String fullFilePath​(java.lang.String parent, java.lang.String path)
      this method does the similar than the fullPath(String, String) but it considers the parent as parent directory rather than a base handle.
      static java.lang.String fullPath​(java.lang.String base, java.lang.String path)
      returns a full path.
      static java.lang.String getAbsoluteParent​(java.lang.String handle, int level)
      Returns the nth absolute parent of the handle, where n=level.
      static java.lang.String getLabel​(java.lang.String handle)
      Deprecated.
      static java.lang.String getLabel​(java.lang.String handle, char delim)
      Deprecated.
      static java.lang.String getLocalName​(java.lang.String qname)
      Returns the local name of the given qname.
      static java.lang.String getName​(java.lang.String path)
      Returns the name part of the path
      static java.lang.String getName​(java.lang.String path, boolean ignoreTrailingSlash)
      Same as getName(String) but adding the possibility to pass paths that end with a trailing '/'
      static java.lang.String getName​(java.lang.String path, char delim)
      Returns the name part of the path, delimited by the given delim
      static java.lang.String getNamespacePrefix​(java.lang.String qname)
      Returns the namespace prefix of the given qname.
      static java.lang.String getRelativeParent​(java.lang.String handle, int level)
      Returns the nth relative parent of the handle, where n=level.
      static java.lang.String implode​(java.lang.String[] arr, java.lang.String delim)
      Concatenates all strings in the string array using the specified delimiter.
      static boolean isDescendant​(java.lang.String handle, java.lang.String descendant)
      Determines if the descendant handle is hierarchical a descendant of handle.
      static boolean isDescendantOrEqual​(java.lang.String handle, java.lang.String descendant)
      Determines if the descendant handle is hierarchical a descendant of handle or equal to it.
      static boolean isSibling​(java.lang.String h1, java.lang.String h2)
      Determines, if two handles are sister-pages, that meens, if they represent the same hierarchic level and share the same parent page.
      static java.lang.String joinFixSlash​(java.lang.String first, java.lang.String second)
      Deprecated.
      static java.lang.String makeCanonicalPath​(char[] source)
      make a cannonical path.
      static java.lang.String makeCanonicalPath​(java.lang.String path)
      Make a path canonical.
      static java.lang.String makeCanonicalPath​(java.lang.StringBuffer source)
      Deprecated.
      static java.lang.String md5​(java.lang.String data)
      Deprecated.
      static java.lang.String md5​(java.lang.String data, java.lang.String enc)
      Calculate an MD5 hash of the string given.
      static java.util.Date parseDate​(java.lang.String dateString)
      Parses the date string based on the format pattern which is in the default format dd.MM.yyyy HH:mm:ss.
      static java.util.Date parseDate​(java.lang.String dateString, boolean isUTC)
      Parses the date string based on the format pattern which is in the default format dd.MM.yyyy HH:mm:ss.
      static java.util.Date parseDate​(java.lang.String dateString, java.lang.String formatPattern)
      Parses the date string based on the format pattern which is in the format used by the Java platfrom SimpleDateFormat class.
      static java.util.Date parseDate​(java.lang.String dateString, java.lang.String formatPattern, boolean isUTC)
      Parses the date string based on the format pattern which is in the format used by the Java platfrom SimpleDateFormat class.
      static java.util.Calendar parseISO8601​(java.lang.String text)
      Parses an ISO8601-compliant date/time string.
      static java.lang.String replace​(java.lang.String text, java.lang.String oldString, java.lang.String newString)
      Replaces all occurences of oldString in text with newString.
      static java.lang.String replaceVariables​(java.util.Properties variables, java.lang.String value, boolean ignoreMissing)
      Performs variable replacement on the given string value.
      static java.lang.String[] split​(java.lang.String str, int ch)
      Deprecated.
      static java.lang.String[] split​(java.lang.String str, int ch, boolean respectEmpty)
      static java.lang.String sprintf​(java.lang.String format, java.lang.Object a0)
      Formats a string according to format and argument.
      static java.lang.String sprintf​(java.lang.String format, java.lang.Object[] args)
      This method implements the famous and ubiquituous sprintf formatter in Java.
      static java.lang.String sprintf​(java.lang.String format, java.lang.Object a0, java.lang.Object a1)
      Formats a string according to format and argument.
      static java.lang.String sprintf​(java.lang.String format, java.lang.Object a0, java.lang.Object a1, java.lang.Object a2)
      Formats a string according to format and argument.
      static java.lang.String sprintf​(java.lang.String format, java.lang.Object a0, java.lang.Object a1, java.lang.Object a2, java.lang.Object a3)
      Formats a string according to format and argument.
      static java.lang.String sprintf​(java.lang.String format, java.lang.Object a0, java.lang.Object a1, java.lang.Object a2, java.lang.Object a3, java.lang.Object a4)
      Formats a string according to format and argument.
      static java.lang.String strftime​(java.util.Date date)
      Implements a date formatting routine supporting (a subset) of the POSIX strftime() function.
      static java.lang.String strftime​(java.util.Date date, boolean asUTC)
      Implements a date formatting routine supporting (a subset) of the POSIX strftime() function.
      static java.lang.String strftime​(java.util.Date date, java.lang.String formatPattern, boolean asUTC)
      Implements a date formatting routine supporting (a subset) of the POSIX strftime() function.
      static java.lang.String strftime​(java.util.Date date, java.lang.String formatPattern, java.util.TimeZone zone)
      Implements a date formatting routine supporting (a subset) of the POSIX strftime() function.
      static java.lang.String unescape​(java.lang.String string)
      Does a URL decoding of the string.
      static java.lang.String unescape​(java.lang.String string, char escape)
      Does a URL decoding of the string using the escape character.
      static void validateLabel​(java.lang.String labelhint)
      Checks if the label is not empty and contains all valid label chars.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_DATE_FORMAT_PATTERN

        public static final java.lang.String DEFAULT_DATE_FORMAT_PATTERN
        The default format pattern used in strftime() if no pattern parameter has been supplied. This is the default format used to format dates in Communiqué 2
        See Also:
        Constant Field Values
      • TIMEZONE_UTC

        public static final java.util.TimeZone TIMEZONE_UTC
        The UTC timezone
      • TIMEZONE_LOCAL

        public static final java.util.TimeZone TIMEZONE_LOCAL
        The local timezone
      • hexTable

        public static final char[] hexTable
        used for the md5
      • URISave

        public static java.util.BitSet URISave
        The list of characters that are not encoded by the escape() and unescape() methods. They contains the characters as defined 'unreserved' in section 2.3 of the RFC 2396 'URI genric syntax':
         unreserved  = alphanum | mark
         mark        = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"
         
      • URISaveEx

        public static java.util.BitSet URISaveEx
        Same as URISave but also contains the '/'
      • NON_VALID_CHARS

        public static final java.lang.String NON_VALID_CHARS
        Non-valid handle characters: / \ : * ? " < > | and carriage return.
        (That's slash, backslash, colon, asterisk, question mark, quotation mark, less than symbol, greater than symbol, pipe, and carriage return.)
        See Also:
        Constant Field Values
    • Method Detail

      • split

        public static java.lang.String[] split​(java.lang.String str,
                                               int ch)
        Deprecated.
        returns an array of strings decomposed of the original string, split at every occurance of 'ch'. if 2 'ch' follow each other with no intermediate characters, empty "" entries are avoided.
        Parameters:
        str - the string to decompose
        ch - the character to use a split pattern
        Returns:
        an array of strings
      • split

        public static java.lang.String[] split​(java.lang.String str,
                                               int ch,
                                               boolean respectEmpty)
        returns an array of strings decomposed of the original string, split at every occurance of 'ch'.
        Parameters:
        str - the string to decompose
        ch - the character to use a split pattern
        respectEmpty - if true, empty elements are generated
        Returns:
        an array of strings
      • explode

        public static java.lang.String[] explode​(java.lang.String str,
                                                 int ch)
        returns an array of strings decomposed of the original string, split at every occurance of 'ch'. if 2 'ch' follow each other with no intermediate characters, empty "" entries are avoided.
        Parameters:
        str - the string to decompose
        ch - the character to use a split pattern
        Returns:
        an array of strings
      • explode

        public static java.lang.String[] explode​(java.lang.String str,
                                                 int ch,
                                                 boolean respectEmpty)
        returns an array of strings decomposed of the original string, split at every occurance of 'ch'.
        Parameters:
        str - the string to decompose
        ch - the character to use a split pattern
        respectEmpty - if true, empty elements are generated
        Returns:
        an array of strings
      • implode

        public static java.lang.String implode​(java.lang.String[] arr,
                                               java.lang.String delim)
        Concatenates all strings in the string array using the specified delimiter.
        Parameters:
        arr -
        delim -
        Returns:
        the concatenated string
      • replace

        public static java.lang.String replace​(java.lang.String text,
                                               java.lang.String oldString,
                                               java.lang.String newString)
        Replaces all occurences of oldString in text with newString.
        Parameters:
        text -
        oldString - old substring to be replaced with newString
        newString - new substring to replace occurences of oldString
        Returns:
        a string
      • getName

        public static java.lang.String getName​(java.lang.String path)
        Returns the name part of the path
        Parameters:
        path - the path
        Returns:
        the name part
      • getName

        public static java.lang.String getName​(java.lang.String path,
                                               char delim)
        Returns the name part of the path, delimited by the given delim
        Parameters:
        path - the path
        delim - the delimiter
        Returns:
        the name part
      • getName

        public static java.lang.String getName​(java.lang.String path,
                                               boolean ignoreTrailingSlash)
        Same as getName(String) but adding the possibility to pass paths that end with a trailing '/'
        Parameters:
        path - the path
        ignoreTrailingSlash - if true a trailing slash is ignored
        Returns:
        the name part
        See Also:
        getName(String)
      • getNamespacePrefix

        public static java.lang.String getNamespacePrefix​(java.lang.String qname)
        Returns the namespace prefix of the given qname. If the prefix is missing, an empty string is returned. Please note, that this method does not validate the name or prefix.

        the qname has the format: qname := [prefix ':'] local;
        Parameters:
        qname - a qualified name
        Returns:
        the prefix of the name or "".
        Throws:
        java.lang.NullPointerException - if qname is null
        See Also:
        getLocalName(String)
      • getLocalName

        public static java.lang.String getLocalName​(java.lang.String qname)
        Returns the local name of the given qname. Please note, that this method does not validate the name.

        the qname has the format: qname := [prefix ':'] local;
        Parameters:
        qname - a qualified name
        Returns:
        the localname
        Throws:
        java.lang.NullPointerException - if qname is null
        See Also:
        getNamespacePrefix(String)
      • compareHandles

        public static int compareHandles​(java.lang.String h1,
                                         java.lang.String h2)
        compares to handles lexigographically with one exception: the '/' character is always considered smaller than all other chars. this results in a ordering, in which the parent pages come first (it's about 6 times slower than the string impl. of compareTo).
          example (normal string compare):
        • /foo
        • /foo-bar
        • /foo/bar
          example (this handle compare):
        • /foo
        • /foo/bar
        • /foo-bar
        Parameters:
        h1 - the first handle
        h2 - the second handle
        Returns:
        the return is positive, if the first handle is bigger than the second; negative, if the first handle is smaller than the second; and zero, if the two handles are equal.
      • fullFilePath

        public static java.lang.String fullFilePath​(java.lang.String parent,
                                                    java.lang.String path)
        this method does the similar than the fullPath(String, String) but it considers the parent as parent directory rather than a base handle. if further respects full qualified uri's.
        examples: parent | path | result ----------+----------+------------ "" | "" | / /foo | "" | /foo "" | /foo | /foo "." | foo | foo /foo/bar | bla | /foo/bar/bla /foo/bar | /bla | /bla /foo/bar | ../bla | /foo/bla /foo/bar | ./bla | /foo/bar/bla foo | bar | foo/bar c:/bla | gurk | c:/bla/gurk /foo | c:/bar | c:/bar
        Parameters:
        parent - the base handle
        path - the path
      • fullPath

        public static java.lang.String fullPath​(java.lang.String base,
                                                java.lang.String path)
        returns a full path. if base is empty, '/' is assumed if base and path are relative, a relative path will be generated.
        examples:
         base      | path     | result
         ----------+----------+------------
         ""        | ""       | /
         /foo      | ""       | /foo
         ""        | /foo     | /foo
         "."       | foo      | foo
         /foo/bar  | bla      | /foo/bla
         /foo/bar  | /bla     | /bla
         /foo/bar  | ../bla   | /bla
         /foo/bar  | ./bla    | /foo/bla
         foo       | bar      | bar
         
        Parameters:
        base - the base handle
        path - the path
      • makeCanonicalPath

        public static java.lang.String makeCanonicalPath​(java.lang.String path)
        Make a path canonical. This is a shortcut for Text.makeCanonicalPath(new StringBuffer(path));
        Parameters:
        path - path to make canonical
      • makeCanonicalPath

        public static java.lang.String makeCanonicalPath​(java.lang.StringBuffer source)
        Deprecated.
        make a cannonical path. removes all /./ and /../ and multiple slashes.
        Parameters:
        source - the input source
        Returns:
        a string containing the cannonical path
      • makeCanonicalPath

        public static java.lang.String makeCanonicalPath​(char[] source)
        make a cannonical path. removes all /./ and /../ and multiple slashes.
        Parameters:
        source - the input source
        Returns:
        a string containing the cannonical path
      • isSibling

        public static boolean isSibling​(java.lang.String h1,
                                        java.lang.String h2)
        Determines, if two handles are sister-pages, that meens, if they represent the same hierarchic level and share the same parent page.
        Parameters:
        h1 - first handle
        h2 - second handle
        Returns:
        true if on same level, false otherwise
      • isDescendant

        public static boolean isDescendant​(java.lang.String handle,
                                           java.lang.String descendant)
        Determines if the descendant handle is hierarchical a descendant of handle. /content/playground/en isDescendantOf /content/playground /content/playground/en isDescendantOf /content /content/playground/en isNOTDescendantOf /content/designground /content/playground/en isNOTDescendantOf /content/playground/en
        Parameters:
        handle - the current handle
        descendant - the potential descendant
        Returns:
        true if the descendant is a descendant; false otherwise.
        Since:
        gumbear
      • isDescendantOrEqual

        public static boolean isDescendantOrEqual​(java.lang.String handle,
                                                  java.lang.String descendant)
        Determines if the descendant handle is hierarchical a descendant of handle or equal to it. /content/playground/en isDescendantOrEqualOf /content/playground /content/playground/en isDescendantOrEqualOf /content /content/playground/en isDescendantOrEqualOf /content/playground/en /content/playground/en isNOTDescendantOrEqualOf /content/designground
        Parameters:
        handle - the current handle
        descendant - the potential descendant
        Returns:
        true if the descendant is a descendant or equal; false otherwise.
        Since:
        gumbear
      • getLabel

        public static java.lang.String getLabel​(java.lang.String handle)
        Deprecated.
        Returns the label of a handle
        Parameters:
        handle - the handle
        Returns:
        the label
      • getLabel

        public static java.lang.String getLabel​(java.lang.String handle,
                                                char delim)
        Deprecated.
        Returns the label of a string
        Parameters:
        handle - the string
        delim - the delimiter
        Returns:
        the label
      • md5

        public static java.lang.String md5​(java.lang.String data,
                                           java.lang.String enc)
                                    throws java.io.UnsupportedEncodingException
        Calculate an MD5 hash of the string given.
        Parameters:
        data - the data to encode
        enc - the character encoding to use
        Returns:
        a hex encoded string of the md5 digested input
        Throws:
        java.io.UnsupportedEncodingException - if the given encoding is not supported
      • md5

        public static java.lang.String md5​(java.lang.String data)
        Deprecated.
        Calculate an MD5 hash of the string given.
        Parameters:
        data - the data to encode
        Returns:
        a hex encoded string of the md5 digested input
      • digest

        public static java.lang.String digest​(java.lang.String algorithm,
                                              java.lang.String data,
                                              java.lang.String enc)
                                       throws java.security.NoSuchAlgorithmException,
                                              java.io.UnsupportedEncodingException
        Digest the plain string using the given algorithm.
        Parameters:
        algorithm - The alogrithm for the digest. This algorithm must be supported by the MessageDigest class.
        data - The plain text String to be digested.
        enc - The character encoding to use
        Returns:
        The digested plain text String represented as Hex digits.
        Throws:
        java.security.NoSuchAlgorithmException - if the desired algorithm is not supported by the MessageDigest class.
        java.io.UnsupportedEncodingException - if the encoding is not supported
      • digest

        public static java.lang.String digest​(java.lang.String algorithm,
                                              java.lang.String data)
                                       throws java.security.NoSuchAlgorithmException
        Digest the plain string using the given algorithm.
        Parameters:
        algorithm - The alogrithm for the digest. This algorithm must be supported by the MessageDigest class.
        data - The plain text String to be digested.
        Returns:
        The digested plain text String represented as Hex digits.
        Throws:
        java.security.NoSuchAlgorithmException - if the desired algorithm is not supported by the MessageDigest class.
      • digest

        public static java.lang.String digest​(java.lang.String algorithm,
                                              byte[] data)
                                       throws java.security.NoSuchAlgorithmException
        Digest the plain string using the given algorithm.
        Parameters:
        algorithm - The alogrithm for the digest. This algorithm must be supported by the MessageDigest class.
        data - the data to digest with the given algorithm
        Returns:
        The digested plain text String represented as Hex digits.
        Throws:
        java.security.NoSuchAlgorithmException - if the desired algorithm is not supported by the MessageDigest class.
      • getRelativeParent

        public static java.lang.String getRelativeParent​(java.lang.String handle,
                                                         int level)
        Returns the nth relative parent of the handle, where n=level.

        Example:
        Text.getRelativeParent("/en/home/index/about", 1) == "/en/home/index"

        Parameters:
        handle - the handle of the page
        level - the level of the parent
      • getAbsoluteParent

        public static java.lang.String getAbsoluteParent​(java.lang.String handle,
                                                         int level)
        Returns the nth absolute parent of the handle, where n=level.

        Example:
        Text.getAbsoluteParent("/en/home/index/about", 1) == "/en/home"

        Parameters:
        handle - the handle of the page
        level - the level of the parent
      • escape

        public static java.lang.String escape​(java.lang.String string,
                                              char escape)
        Does an URL encoding of the string using the escape character. The characters that don't need encoding are those defined 'unreserved' in section 2.3 of the 'URI genric syntax' RFC 2396, but without the escape character.
        Parameters:
        string - the string to encode.
        escape - the escape character.
        Returns:
        the escaped string
        Throws:
        java.lang.NullPointerException - if string is null.
      • escape

        public static java.lang.String escape​(java.lang.String string,
                                              char escape,
                                              boolean isPath)
        Does an URL encoding of the string using the escape character. The characters that don't need encoding are those defined 'unreserved' in section 2.3 of the 'URI genric syntax' RFC 2396, but without the escape character. If isPath is true, additionally the slash '/' is ignored, too.
        Parameters:
        string - the string to encode.
        escape - the escape character.
        isPath - if true, the string is treated as path
        Returns:
        the escaped string
        Throws:
        java.lang.NullPointerException - if string is null.
      • escapeXml

        public static java.lang.String escapeXml​(java.lang.String string)
        Escapes all character that have specific meaning in XMl/HTML, namely '<', '>', '"', '&' by their isolating encoding aequivalents "&lt;", "&gt", "&quot;", "&amp;"
        Parameters:
        string - the string to escape
        Returns:
        the escaped string or null if the input string was null
      • escape

        public static java.lang.String escape​(java.lang.String string)
        Does a URL encoding of the string. The characters that don't need encoding are those defined 'unreserved' in section 2.3 of the 'URI genric syntax' RFC 2396.
        Parameters:
        string - the string to encode
        Returns:
        the escaped string
        Throws:
        java.lang.NullPointerException - if string is null.
      • escapePath

        public static java.lang.String escapePath​(java.lang.String path)
        Does a URL encoding of the path. The characters that don't need encoding are those defined 'unreserved' in section 2.3 of the 'URI genric syntax' RFC 2396. In contrast to the escape(String) method, not the entire path string is escaped, but every individual part (i.e. the slashes are not escaped).
        Parameters:
        path - the path to encode
        Returns:
        the escaped path
        Throws:
        java.lang.NullPointerException - if path is null.
      • unescape

        public static java.lang.String unescape​(java.lang.String string,
                                                char escape)
        Does a URL decoding of the string using the escape character. Please note that in opposite to the URLDecoder it does not transform the + into spaces.
        Parameters:
        string - the string to decode
        escape - the escape character
        Returns:
        the decoded string
        Throws:
        java.lang.NullPointerException - if string is null.
        java.lang.ArrayIndexOutOfBoundsException - if not enough character follow an escape character
        java.lang.IllegalArgumentException - if the 2 characters following the escape character do not represent a hex-number.
      • unescape

        public static java.lang.String unescape​(java.lang.String string)
        Does a URL decoding of the string. Please note that in opposite to the URLDecoder it does not transform the + into spaces.
        Parameters:
        string - the string to decode
        Returns:
        the decoded string
        Throws:
        java.lang.NullPointerException - if string is null.
        java.lang.ArrayIndexOutOfBoundsException - if not enough character follow an escape character
        java.lang.IllegalArgumentException - if the 2 characters following the escape character do not represent a hex-number.
      • dateToRfc1123String

        public static java.lang.String dateToRfc1123String​(java.util.Date date)
        Returns a stringified date accoring to the date format specified in RTF1123. this is of the form: "Sun, 06 Nov 1994 08:49:37 GMT"
      • strftime

        public static java.lang.String strftime​(java.util.Date date,
                                                java.lang.String formatPattern,
                                                java.util.TimeZone zone)
        Implements a date formatting routine supporting (a subset) of the POSIX strftime() function.
        Parameters:
        date - The date value to be formatted
        formatPattern - The pattern used to format the date. This pattern supports a subset of the pattern characters of the POSIX strftime() function. If this pattern is empty or null the default pattern dd.MM.yyyy HH:mm:ss is used.
        zone - Defines for which time zone the date should be outputted. If this parameter is null, then the local time zone is taken.
        Returns:
        the formatted date as a String.
      • strftime

        public static java.lang.String strftime​(java.util.Date date,
                                                java.lang.String formatPattern,
                                                boolean asUTC)
        Implements a date formatting routine supporting (a subset) of the POSIX strftime() function.
        Parameters:
        date - The date value to be formatted
        formatPattern - The pattern used to format the date. This pattern supports a subset of the pattern characters of the POSIX strftime() function. If this pattern is empty or null the default pattern dd.MM.yyyy HH:mm:ss is used.
        asUTC - Defines whether to interpret the date as belong to the UTC time zone or the local time zone.
      • strftime

        public static java.lang.String strftime​(java.util.Date date,
                                                boolean asUTC)
        Implements a date formatting routine supporting (a subset) of the POSIX strftime() function. The default pattern dd.MM.yyyy HH:mm:ss is used to format the date.
        Parameters:
        date - The date value to be formatted
        asUTC - Defines whether to interpret the date as belong to the UTC time zone or the local time zone.
      • strftime

        public static java.lang.String strftime​(java.util.Date date)
        Implements a date formatting routine supporting (a subset) of the POSIX strftime() function. The default pattern dd.MM.yyyy HH:mm:ss is used to format the date, which is interpreted to be in the local time zone.
        Parameters:
        date - The date value to be formatted
      • parseDate

        public static java.util.Date parseDate​(java.lang.String dateString,
                                               java.lang.String formatPattern)
                                        throws java.text.ParseException
        Parses the date string based on the format pattern which is in the format used by the Java platfrom SimpleDateFormat class.
        Parameters:
        dateString - The date string to be parsed
        formatPattern - the pattern to use for parsing. If null or empty, the same default pattern is used as with strftime(Date, String, boolean), namely dd.MM.yyyy HH:mm:ss.
        Throws:
        java.text.ParseException - if the date string cannot be parsed accordinung to the format pattern.
      • parseDate

        public static java.util.Date parseDate​(java.lang.String dateString,
                                               java.lang.String formatPattern,
                                               boolean isUTC)
                                        throws java.text.ParseException
        Parses the date string based on the format pattern which is in the format used by the Java platfrom SimpleDateFormat class.
        Parameters:
        dateString - The date string to be parsed
        formatPattern - the pattern to use for parsing. If null or empty, the same default pattern is used as with strftime(Date, String, boolean), namely dd.MM.yyyy HH:mm:ss.
        isUTC - if true the date string is considered in UTC, otherwise the default timezone of the host is used.
        Throws:
        java.text.ParseException - if the date string cannot be parsed accordinung to the format pattern.
      • parseDate

        public static java.util.Date parseDate​(java.lang.String dateString)
                                        throws java.text.ParseException
        Parses the date string based on the format pattern which is in the default format dd.MM.yyyy HH:mm:ss.
        Parameters:
        dateString - The date string to be parsed
        Throws:
        java.text.ParseException - if the date string cannot be parsed accordinung to the format pattern.
      • parseDate

        public static java.util.Date parseDate​(java.lang.String dateString,
                                               boolean isUTC)
                                        throws java.text.ParseException
        Parses the date string based on the format pattern which is in the default format dd.MM.yyyy HH:mm:ss.
        Parameters:
        dateString - The date string to be parsed
        isUTC - if true the date string is considered in UTC, otherwise the default timezone of the host is used.
        Throws:
        java.text.ParseException - if the date string cannot be parsed accordinung to the format pattern.
      • sprintf

        public static java.lang.String sprintf​(java.lang.String format,
                                               java.lang.Object[] args)
        This method implements the famous and ubiquituous sprintf formatter in Java. The arguments to the method are the formatting string and the list of arguments defined by the formatting instructions contained in the formatting string.

        Each element in the argument array is either a Number object or any other Object type. Whenever the formatting string stipulates the corresponding argument to be numeric, it is assumed this array element to be a Number. If this is not the case an IllegalArgumentException is thrown. If a String argument is stipulated by the formatting string, a simple call to the toString() method of the object yields the String required.

        SPECIFICATION

        sprintf accepts a series of arguments, applies to each a format specifier from format, and stores the formatted data to the result Strint. The method throws an IllegalArgumentException if either the format is incorrect, there are not enough arguments for the format or if any of the argument's type is wrong. sprintf returns when it reaches the end of the format string. If there are more arguments than the format requires, excess arguments are ignored.

        format is a String containing two types of objects: ordinary characters (other than %), which are copied unchanged to the output, and conversion specifications, each of which is introduced by %. (To include % in the output, use %% in the format string.) A conversion specification has the following form:

        [ flags ] [ width ] [ "." prec ] [ size ] type

        The fields of the conversion specification have the following meanings:

        flags
        an optional sequence of characters which control output justification, numeric signs, decimal points, trailing zeroes, and octal and hex prefixes. The flag characters are minus (-), plus (+), space (" "), zero (0), and sharp (# ). They can appear in any combination.
        - The result of the conversion is left justified, and the right is padded with blanks. If you do not use this flag, the result is right justified, and padded on the left.
        + The result of a signed conversion (as determined by type) will always begin with a plus or minus sign. (If you do not use this flag, positive values do not begin with a plus sign.)
        " " (space) If the first character of a signed conversion specification is not a sign, or if a signed conversion results in no characters, the result will begin with a space. If the space ( ) flag and the plus (+) flag both appear, the space flag is ignored.
        0 If the type is d, i, o, u, x, X, e, E, f, g, or G: leading zeroes, are used to pad the field width (following any indication of sign or base); no spaces are used for padding. If the zero (0) and minus (-) flags both appear, the zero (0) flag will be ignored. For d, i, o, u, x, X conversions, if a precision prec is specified, the zero (0) flag is ignored.
        Note that 0 is interpreted as a flag, not as the beginning of a field width.
        # The result is to be converted to an alternative form, according to the type character:
        o
        Increases precision to force the first digit of the result to be a zero.
        x
        A non-zero result will have a 0x prefix.
        X
        A non-zero result will have a 0X prefix.
        e, E, or f
        The result will always contain a decimal point even if no digits follow the point. (Normally, a decimal point appears only if a digit follows it.) Trailing zeroes are removed.
        g or G
        Same as e or E, but trailing zeroes arenot removed.
        all others
        Undefined.
        width
        width is an optional minimum field width. You can either specify it directly as a decimal integer, or indirectly by using instead an asterisk (*), in which case an integral numeric argument is used as the field width. Negative field widths are not supported; if you attempt to specify a negative field width, it is interpreted as a minus (i) flag followed by a positive field width.
        prec
        an optional field; if present, it is introduced with `.' (a period). This field gives the maximum number of characters to print in a conversion; the minimum number of digits of an integer to print, for conversions with type d, i, o, u, x, and X; the maximum number of significant digits, for the g and G conversions; or the number of digits to print after the decimal point, for e, E, and f conversions. You can specify the precision either directly as a decimal integer or indirectly by using an asterisk (*), in which case an integral numeric argument is used as the precision. Supplying a negative precision is equivalent to omitting the precision. If only a period is specified the precision is zero. If a precision appears with any other conversion type than those listed here, the behavior is undefined.
        size
        h, l, and L are optional size characters which override the default way that sprintf interprets the data type of the corresponding argument. h forces the following d, i, o, u, x, or X conversion type to apply to a short or unsigned short. Similarily, an l forces the following d, i, o, u, x, or X conversion type to apply to a long or unsigned long. If an h or an l appears with another conversion specifier, the behavior is undefined. L forces a following e, E, f, g, or G conversion type to apply to a long double argument. If L appears with any other conversion type, the behavior is undefined.
        type
        type specifies what kind of conversion sprintf performs. Here is a table of these:
        %
        prints the percent character (%)
        c
        prints arg as single character. That is the argument is converted to a String of which only the first character is printed.
        s
        Prints characters until precision is reached or the String ends; takes any Object whose toString() method is called to get the String to print.
        d
        prints a signed decimal integer; takes a Number (same as i)
        d
        prints a signed decimal integer; takes a Number (same as d)
        d
        prints a signed octal integer; takes a Number
        u
        prints a unsigned decimal integer; takes a Number. This conversion is not supported correctly by the Java implementation and is really the same as i.
        x
        prints an unsigned hexadecimal integer (using abcdef as digits beyond 9; takes a Number
        X
        prints an unsigned hexadecimal integer (using ABCDEF as digits beyond 9; takes a Number
        f
        prints a signed value of the form [-]9999.9999; takes a Number
        e
        prints a signed value of the form [-]9.9999e[+|-]999; takes a Number
        E
        prints the same way as e, but using E to introduce the exponent; takes a Number
        g
        prints a signed value in either f or e form, based on given value and precision &emdash; trailing zeros and the decimal point are printed only if necessary; takes a Number
        G
        prints the same way as g, but using E for the exponent if an exponent is needed; takes a Number
        n
        Not supported in the Java implementation, throws an IllegalArgumentException if used.
        p
        Not supported in the Java implementation, throws an IllegalArgumentException if used.

        IMPLEMENTATION NOTES

        Due to the nature of the Java programming language, neither pointer conversions, nor unsigned and long double conversions are supported.

        Also the Java implementation only distinguishes between Number and other Object arguments. If a numeric argument is expected as per the format String, the current argument must be a Number object that is converted to a basic type as expected. If a String or char argument is expected, any Object is valid, whose toString() method is used to convert to a String.

        Parameters:
        format - The format string as known from the POSIX sprintf() C function.
        args - The list of arguments to accomodate the format string. This argument list is supposed to contain at least as much entries as there are formatting options in the format string. If for a numeric option, the entry is not a number an IllegalArgumentException is thrown.
        Returns:
        The formatted String. An empty String is only returned if the format String is empty. A null value is never returned.
        Throws:
        java.lang.NullPointerException - if the formatting string or any of the argument values is null.
        java.lang.IllegalArgumentException - if the formatting string has wrong format tags, if the formatting string has an incomplete formatting pattern at the end of the string, if the argument vector has not enough values to satisfy the formatting string or if an argument's type does not match the requirements of the format string.
      • sprintf

        public static java.lang.String sprintf​(java.lang.String format,
                                               java.lang.Object a0)
        Formats a string according to format and argument. This method only supports string formats. See sprintf(String, Object[]) for details.
        Parameters:
        format - The format string
        a0 - The single parameter
        Returns:
        the result from sprintf(format, new Object[]{ a0 }).
        Throws:
        java.lang.IllegalArgumentException - from sprintf(String, Object[]).
      • sprintf

        public static java.lang.String sprintf​(java.lang.String format,
                                               java.lang.Object a0,
                                               java.lang.Object a1)
        Formats a string according to format and argument. This method only supports string formats. See sprintf(String, Object[]) for details.
        Parameters:
        format - The format string
        a0 - The first parameter
        a1 - The second parameter
        Returns:
        the result from sprintf(format, new Object[]{ ... }).
        Throws:
        java.lang.IllegalArgumentException - from sprintf(String, Object[]).
      • sprintf

        public static java.lang.String sprintf​(java.lang.String format,
                                               java.lang.Object a0,
                                               java.lang.Object a1,
                                               java.lang.Object a2)
        Formats a string according to format and argument. This method only supports string formats. See sprintf(String, Object[]) for details.
        Parameters:
        format - The format string
        a0 - The first parameter
        a1 - The second parameter
        a2 - The thrid parameter
        Returns:
        the result from sprintf(format, new Object[]{ ... }).
        Throws:
        java.lang.IllegalArgumentException - from sprintf(String, Object[]).
      • sprintf

        public static java.lang.String sprintf​(java.lang.String format,
                                               java.lang.Object a0,
                                               java.lang.Object a1,
                                               java.lang.Object a2,
                                               java.lang.Object a3)
        Formats a string according to format and argument. This method only supports string formats. See sprintf(String, Object[]) for details.
        Parameters:
        format - The format string
        a0 - The first parameter
        a1 - The second parameter
        a2 - The thrid parameter
        a3 - The fourth parameter
        Returns:
        the result from sprintf(format, new Object[]{ ... }).
        Throws:
        java.lang.IllegalArgumentException - from sprintf(String, Object[]).
      • sprintf

        public static java.lang.String sprintf​(java.lang.String format,
                                               java.lang.Object a0,
                                               java.lang.Object a1,
                                               java.lang.Object a2,
                                               java.lang.Object a3,
                                               java.lang.Object a4)
        Formats a string according to format and argument. This method only supports string formats. See sprintf(String, Object[]) for details.
        Parameters:
        format - The format string
        a0 - The first parameter
        a1 - The second parameter
        a2 - The thrid parameter
        a3 - The fourth parameter
        a4 - The fifth parameter
        Returns:
        the result from sprintf(format, new Object[]{ ... }).
        Throws:
        java.lang.IllegalArgumentException - from sprintf(String, Object[]).
      • createValidLabel

        public static java.lang.String createValidLabel​(java.lang.String labelhint)
        Create a valid label out of an arbitrary string.
        Parameters:
        labelhint - the given label string that we will examine and convert any illegal character if necessary
        Returns:
        a valid label string
      • validateLabel

        public static void validateLabel​(java.lang.String labelhint)
        Checks if the label is not empty and contains all valid label chars.
        Parameters:
        labelhint - the labelhint to check
        Throws:
        java.lang.IllegalArgumentException - if the label does not contain all valid chars.
      • joinFixSlash

        public static java.lang.String joinFixSlash​(java.lang.String first,
                                                    java.lang.String second)
        Deprecated.
        Join two paths or handles, fixing the slashes. All these will go to "/a/b": /a/ + /b/ (trailing slashes are removed) /a + /b /a/ + b /a/ + b/ /a// + /////b (i am paranoid) Note that leading slashes are untouched, so variations on the above without the leading slash on 'a' would go to "a/b".
      • replaceVariables

        public static java.lang.String replaceVariables​(java.util.Properties variables,
                                                        java.lang.String value,
                                                        boolean ignoreMissing)
                                                 throws java.lang.IllegalArgumentException
        Performs variable replacement on the given string value. Each ${...} sequence within the given value is replaced with the value of the named parser variable. If a variable is not found in the properties an IllegalArgumentException is thrown unless ignoreMissing is true. In the later case, the missing variable is replaced by the empty string.
        Parameters:
        value - the original value
        ignoreMissing - if true, missing variables are replaced by the empty string.
        Returns:
        value after variable replacements
        Throws:
        java.lang.IllegalArgumentException - if the replacement of a referenced variable is not found
      • parseISO8601

        public static java.util.Calendar parseISO8601​(java.lang.String text)
        Parses an ISO8601-compliant date/time string. (see ISO 8601).

        The currently supported format is:

           ±YYYY-MM-DDThh:mm:ss.SSSTZD
         
        where:
           ±YYYY = four-digit year with optional sign where values <= 0 are
                   denoting years BCE and values > 0 are denoting years CE,
                   e.g. -0001 denotes the year 2 BCE, 0000 denotes the year 1 BCE,
                   0001 denotes the year 1 CE, and so on...
           MM    = two-digit month (01=January, etc.)
           DD    = two-digit day of month (01 through 31)
           hh    = two digits of hour (00 through 23) (am/pm NOT allowed)
           mm    = two digits of minute (00 through 59)
           ss    = two digits of second (00 through 59)
           SSS   = three digits of milliseconds (000 through 999)
           TZD   = time zone designator, Z for Zulu (i.e. UTC) or an offset from UTC
                   in the form of +hh:mm or -hh:mm
         
        Parameters:
        text - the date/time string to be parsed
        Returns:
        a Calendar, or null if the input could not be parsed
        Throws:
        java.lang.IllegalArgumentException - if a null argument is passed
      • formatISO8601

        public static java.lang.String formatISO8601​(java.util.Calendar cal)
        Formats a Calendar value into an ISO8601-compliant date/time string.
        Parameters:
        cal - the time value to be formatted into a date/time string.
        Returns:
        the formatted date/time string.
        Throws:
        java.lang.IllegalArgumentException - if a null argument is passed