Class Utils

java.lang.Object
eu.webtoolkit.jwt.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

    Modifier and Type Method Description
    static void assignFontMatch​(eu.webtoolkit.jwt.FontSupport.FontMatch fm1, eu.webtoolkit.jwt.FontSupport.FontMatch fm2)  
    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 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 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 Details

  • Method Details

    • 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)
    • 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​(java.lang.String text)
    • 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>).
    • htmlEncode

      public static java.lang.String htmlEncode​(WString text)
    • htmlEncode

      public static java.lang.String htmlEncode​(java.lang.String value, Utils.HtmlEncodingFlag flag, Utils.HtmlEncodingFlag... flags)
      Performs HTML encoding of text.

      Calls Utils.htmlEncode(text, flags)

    • 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)
    • 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)
    • hmac_sha1

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

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