Class Utils


  • public class Utils
    extends java.lang.Object
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Utils.HtmlEncodingFlag
      An enumeration for HTML encoding flags.
    • Constructor Summary

      Constructors 
      Constructor Description
      Utils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void assignFontMatch​(eu.webtoolkit.jwt.FontSupport.FontMatch fm1, eu.webtoolkit.jwt.FontSupport.FontMatch fm2)  
      static byte[] base32Decode​(java.lang.String s)
      Performs Base32-decoding of data.
      static java.lang.String base32DecodeS​(java.lang.String s)  
      static java.lang.String base32Encode​(byte[] bytes)
      Performs Base32-encoding of data.
      static java.lang.String base32Encode​(byte[] bytes, boolean crlf)  
      static java.lang.String base32Encode​(java.lang.String s)
      Performs Base32-encoding of data.
      static java.lang.String base32Encode​(java.lang.String s, boolean crlf)  
      static byte[] base64Decode​(java.lang.String s)
      Performs Base64-decoding of data.
      static java.lang.String base64DecodeS​(java.lang.String s)  
      static java.lang.String base64Encode​(byte[] bytes)
      Performs Base64-encoding of data.
      static java.lang.String base64Encode​(byte[] bytes, boolean crlf)  
      static java.lang.String base64Encode​(java.lang.String s)
      Performs Base64-encoding of data.
      static java.lang.String base64Encode​(java.lang.String s, boolean crlf)  
      static void copyList​(byte[] source, java.util.List<java.lang.Byte> destination)  
      static void copyList​(java.util.List source, java.util.List destination)  
      static java.lang.String createDataUrl​(byte[] data, java.lang.String mimeType)  
      static java.util.List<java.lang.String> getWidgetStyleClasses​(WWidget widget)  
      static byte[] hexStrToBytes​(long value)
      Converts the long value to a byte array containing the hexstring.
      static int hexToInt​(java.lang.String s)  
      static byte[] hmac​(java.lang.String msg, java.lang.String key, java.lang.String algo)  
      static byte[] hmac_md5​(java.lang.String msg, java.lang.String key)  
      static byte[] hmac_sha1​(java.lang.String msg, java.lang.String key)  
      static java.lang.String hmac_sha1WithEncoding​(long msg, byte[] key)  
      static java.lang.String hmacWithEncoding​(byte[] msg, byte[] key, java.lang.String algo)  
      static java.lang.String htmlAttributeValue​(java.lang.String text)
      Escape the given text for inclusion in an HTML attribute
      static java.lang.String htmlEncode​(WString text)
      Performs HTML encoding of text.
      static java.lang.String htmlEncode​(WString text, java.util.EnumSet<Utils.HtmlEncodingFlag> flags)
      Performs HTML encoding of text.
      static java.lang.String htmlEncode​(java.lang.String text)
      Performs HTML encoding of text.
      static java.lang.String htmlEncode​(java.lang.String value, Utils.HtmlEncodingFlag flag, Utils.HtmlEncodingFlag... flags)
      Performs HTML encoding of text.
      static java.lang.String htmlEncode​(java.lang.String text, java.util.EnumSet<Utils.HtmlEncodingFlag> flags)
      Performs HTML encoding of text.
      static byte[] md5​(java.lang.String msg)
      Computes an MD5 hash.
      static void parseFormUrlEncoded​(java.lang.String s, java.util.Map<java.lang.String,​java.lang.String[]> parameters)  
      static boolean removeScript​(java.lang.CharSequence text)
      Remove tags/attributes from text that are not passive.
      static byte[] sha1​(java.lang.String input)  
      static java.lang.String strip​(java.lang.String s, java.lang.String whiteSpaces)  
      static java.lang.String urlDecode​(java.lang.String scope)
      Performs url decoding.
      static java.lang.String urlEncode​(java.lang.String scope)
      Performs url encoding (aka percentage encoding).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Utils

        public Utils()
    • Method Detail

      • md5

        public static byte[] md5​(java.lang.String msg)
        Computes an MD5 hash. This utility function computes an MD5 hash, and returns the hash value.
      • sha1

        public static byte[] sha1​(java.lang.String input)
      • urlEncode

        public static java.lang.String urlEncode​(java.lang.String scope)
        Performs url encoding (aka percentage encoding). This utility function percent encodes a text so that it can be embodied verbatim in a URL (e.g. as a fragment).
        See Also:
        urlDecode(String scope)
      • urlDecode

        public static java.lang.String urlDecode​(java.lang.String scope)
        Performs url decoding. This utility function percent encodes a text so that it can be embodied verbatim in a URL (e.g. as a fragment).
        See Also:
        urlEncode(String scope)
      • parseFormUrlEncoded

        public static void parseFormUrlEncoded​(java.lang.String s,
                                               java.util.Map<java.lang.String,​java.lang.String[]> parameters)
      • base64Encode

        public static java.lang.String base64Encode​(java.lang.String s)
        Performs Base64-encoding of data.
      • base64Encode

        public static java.lang.String base64Encode​(java.lang.String s,
                                                    boolean crlf)
      • base64Encode

        public static java.lang.String base64Encode​(byte[] bytes)
        Performs Base64-encoding of data.
      • base64Encode

        public static java.lang.String base64Encode​(byte[] bytes,
                                                    boolean crlf)
      • base64Decode

        public static byte[] base64Decode​(java.lang.String s)
                                   throws java.io.IOException
        Performs Base64-decoding of data.
        Throws:
        java.io.IOException
      • base64DecodeS

        public static java.lang.String base64DecodeS​(java.lang.String s)
      • base32Encode

        public static java.lang.String base32Encode​(java.lang.String s)
        Performs Base32-encoding of data.
      • base32Encode

        public static java.lang.String base32Encode​(java.lang.String s,
                                                    boolean crlf)
      • base32Encode

        public static java.lang.String base32Encode​(byte[] bytes)
        Performs Base32-encoding of data.
      • base32Encode

        public static java.lang.String base32Encode​(byte[] bytes,
                                                    boolean crlf)
      • base32Decode

        public static byte[] base32Decode​(java.lang.String s)
                                   throws java.io.IOException
        Performs Base32-decoding of data.
        Throws:
        java.io.IOException
      • base32DecodeS

        public static java.lang.String base32DecodeS​(java.lang.String s)
      • htmlEncode

        public static java.lang.String htmlEncode​(java.lang.String text,
                                                  java.util.EnumSet<Utils.HtmlEncodingFlag> flags)
        Performs HTML encoding of text. This utility function escapes characters so that the text can be embodied verbatim in a HTML text block.
      • htmlEncode

        public static java.lang.String htmlEncode​(WString text,
                                                  java.util.EnumSet<Utils.HtmlEncodingFlag> flags)
        Performs HTML encoding of text. This utility function escapes characters so that the text can be embodied verbatim in a HTML text block. By default, newlines are ignored. By passing the Utils.HtmlEncodingFlag.EncodeNewLines flag, these may be encoded as line breaks (<br>).
      • htmlAttributeValue

        public static java.lang.String htmlAttributeValue​(java.lang.String text)
        Escape the given text for inclusion in an HTML attribute

        This utility function escapes characters so that the \p text can be used as the value of an HTML attribute between double quotes.

        The double quotes are not included in the output.

        Example usage:

        
         String attribute = "name=\"" + htmlAttributeValue(value) + "\"";
         
      • removeScript

        public static boolean removeScript​(java.lang.CharSequence text)
        Remove tags/attributes from text that are not passive. This removes tags and attributes from XHTML-formatted text that do not simply display something but may trigger scripting, and could have been injected by a malicious user for Cross-Site Scripting (XSS). This method is used by the library to sanitize XHTML-formatted text set in WText, but it may also be useful outside the library to sanitize user content when directly using JavaScript. Modifies the text if needed. When the text is not proper XML, returns false.
      • strip

        public static java.lang.String strip​(java.lang.String s,
                                             java.lang.String whiteSpaces)
      • assignFontMatch

        public static void assignFontMatch​(eu.webtoolkit.jwt.FontSupport.FontMatch fm1,
                                           eu.webtoolkit.jwt.FontSupport.FontMatch fm2)
      • copyList

        public static void copyList​(java.util.List source,
                                    java.util.List destination)
      • copyList

        public static void copyList​(byte[] source,
                                    java.util.List<java.lang.Byte> destination)
      • hexToInt

        public static int hexToInt​(java.lang.String s)
      • hexStrToBytes

        public static byte[] hexStrToBytes​(long value)
        Converts the long value to a byte array containing the hexstring.

        The hexstring of a long value is simple its hexadecimal representation in string format. i.e. 12 would be C. The string will always be then converted to be 16 bytes long.

        The string is then converted to an array of bytes.

      • createDataUrl

        public static java.lang.String createDataUrl​(byte[] data,
                                                     java.lang.String mimeType)
      • hmac

        public static byte[] hmac​(java.lang.String msg,
                                  java.lang.String key,
                                  java.lang.String algo)
      • hmacWithEncoding

        public static java.lang.String hmacWithEncoding​(byte[] msg,
                                                        byte[] key,
                                                        java.lang.String algo)
      • hmac_sha1

        public static byte[] hmac_sha1​(java.lang.String msg,
                                       java.lang.String key)
      • hmac_sha1WithEncoding

        public static java.lang.String hmac_sha1WithEncoding​(long msg,
                                                             byte[] key)
      • hmac_md5

        public static byte[] hmac_md5​(java.lang.String msg,
                                      java.lang.String key)
      • getWidgetStyleClasses

        public static java.util.List<java.lang.String> getWidgetStyleClasses​(WWidget widget)