Class JSUtils

java.lang.Object
com.webmethods.caf.faces.render.util.JSUtils

public class JSUtils extends Object
Helper functions for rendering JavaScript.
  • Field Details

    • JS_IDENTIFIER

      public static final Pattern JS_IDENTIFIER
      Regex which matches legal javascript identifiers.
    • RFC3339_DATE_FORMAT

      public static SimpleDateFormat RFC3339_DATE_FORMAT
      Formats a date to conform to rfc3339 (like "2000-07-04T07:00:00.000Z").
    • JS_RESERVED

      public static final Set<String> JS_RESERVED
      Current and future javascript reserved words.
    • s_jsonSerializer

      protected static JSUtils.JSONSerializer s_jsonSerializer
  • Constructor Details

    • JSUtils

      public JSUtils()
  • Method Details

    • quote

      public static String quote(String s)
      Escapes string for printing as a javascript string.
      Returns:
      Escaped string. Never null.
    • identifier

      public static String identifier(String s)
      Creates a javascript identifier out of the specifed string. Beginning with JavaScript 1.5 (mozilla 1.0, ie 5.0), unicode letters can be used as identifiers.
      Returns:
      Legal javascript identifier. Never null.
    • asciiIdentifier

      public static String asciiIdentifier(String s)
      Creates an ascii javascript identifier out of the specifed string.
      Returns:
      Legal javascript identifier, containing only alphanumeric ascii chars. Never null.
    • jsonProperty

      public static String jsonProperty(String name, Object value)
      Creates a json property name:value pair. For example, name="foo", value="bar" returns "foo:'bar'"; name="foot baal", value=12 returns "'foot baal':12".
    • jsonProperty

      public static void jsonProperty(Appendable b, String name, Object value) throws IOException
      Creates a json property name:value pair. For example, name="foo", value="bar" returns "foo:'bar'"; name="foot baal", value=12 returns "'foot baal':12".
      Throws:
      IOException
    • jsonPropertyName

      public static void jsonPropertyName(Appendable b, Object o) throws IOException
      Writes the specified json property name (ie "foo:" or "'foo bar':").
      Throws:
      IOException
    • jsonProperties

      public static String jsonProperties(Map<String,Object> properties, Collection<String> skip, Map<String,String> remap)
      Creates list of json property name:value pairs.
      Parameters:
      properties - Properties to output to json.
      skip - Property names to skip. May be null.
      remap - Property names to remap. May be null.
    • jsonProperties

      public static boolean jsonProperties(Appendable b, Map<String,Object> properties, Collection<String> skip, Map<String,String> remap) throws IOException
      Creates list of json property name:value pairs.
      Parameters:
      properties - Properties to output to json.
      skip - Property names to skip. May be null.
      remap - Property names to remap. May be null.
      Throws:
      IOException