Class Util


  • public class Util
    extends Api
    Utility APIs, available to scripting environments under the util variable.
    Version:
    $Id: a581bc36e2fa571ef7793f8d2b730a8217edb2c9 $
    • Constructor Detail

    • Method Detail

      • decodeURI

        public String decodeURI​(String text)
        Decodes a application/x-www-form-urlencoded string.
        Parameters:
        text - the encoded text
        Returns:
        decoded text
        Since:
        1.3 Milestone 2
      • getDate

        @Deprecated
        public Date getDate()
        Deprecated.
        use $datetool.date instead
        Creates a new Date object corresponding to the current time. This is useful from Velocity since new objects cannot be created.
        Returns:
        the current date
        Since:
        1.3 Milestone 2
      • getDate

        @Deprecated
        public Date getDate​(long time)
        Deprecated.
        use $datetool.toDate(time) instead
        Creates a new Date object corresponding to the specified time. This is useful from Velocity since new objects cannot be created.
        Parameters:
        time - time in milliseconds since 1970, 00:00:00 GMT
        Returns:
        Date a date from a time in milliseconds since 01/01/1970 as a Java Date Object
        Since:
        1.3 Milestone 2
      • getTimeDelta

        public int getTimeDelta​(long time)
        Compute the elapsed time, in milliseconds, since the specified unix-epoch timestamp. This is useful from Velocity since new objects cannot be created.
        Parameters:
        time - the time in milliseconds
        Returns:
        the time delta in milliseconds between the current date and the time passed as parameter
        Since:
        1.3 Milestone 2
      • printStrackTrace

        public String printStrackTrace​(Throwable e)
        Get a stack trace as a String.
        Parameters:
        e - the exception to convert to a String
        Returns:
        the exception stack trace as a String
        Since:
        1.3 Milestone 2
      • generateRandomString

        public String generateRandomString​(int size)
        Generate a random string, containing only alpha-numeric characters.
        Parameters:
        size - the desired size of the string
        Returns:
        the randomly generated string
        Since:
        1.3 Milestone 2
      • outputImage

        public void outputImage​(BufferedImage image)
                         throws IOException
        Output a BufferedImage object into the response outputstream. Once this method has been called, no further action is possible. Users should set $xcontext.setFinished(true) to avoid template output. The image is served as image/jpeg.
        Parameters:
        image - the BufferedImage to output
        Throws:
        IOException - if the output fails
        Since:
        1.3 Milestone 2
      • getNull

        public Object getNull()
        Get a Null value. This is useful in Velocity where there is no real null object for comparisons.
        Returns:
        a null Object
        Since:
        1.3 Milestone 2
      • getNewline

        public String getNewline()
        Get a New Line character. This is useful in Velocity where there is no real new line character for inclusion in texts.
        Returns:
        a new line character
        Since:
        1.3 Milestone 2
      • parseBoolean

        public Boolean parseBoolean​(String str)
        Convert a String to a Boolean object.
        Parameters:
        str - the String containing the boolean representation to be parsed
        Returns:
        the boolean represented by the string argument, false if the string is not representing a boolean
        Since:
        1.8 Milestone 2
      • clearAccents

        public String clearAccents​(String text)
        Replace all accented characters by their ASCII equivalent.
        Parameters:
        text - the text to parse
        Returns:
        a string with accents replaced with their alpha equivalent
        Since:
        1.3 Milestone 2
      • clearName

        public String clearName​(String documentName)
        Cleans up the passed text by removing all accents and special characters to make it a valid page name.
        Parameters:
        documentName - the document name to normalize
        Returns:
        the equivalent valid document name
        Since:
        1.3 Milestone 2
      • convertToAlphaNumeric

        public String convertToAlphaNumeric​(String text)
        Removes all non alpha numerical characters from the passed text. First tries to convert accented chars to their ASCII representation. Then it removes all the remaining non-alphanumeric non-ASCII characters.
        Parameters:
        text - the text to convert
        Returns:
        the alpha numeric equivalent
        Since:
        1.3 Milestone 2