Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.fujitsu.iflow.common
Class JSConversions

    java.lang.Object
      com.fujitsu.iflow.common.JSConversions

public class JSConversions
extends java.lang.Object

This class contains some static utility routines to handle JavaScript. Most importantly, it contains routines for converting strings to and from literal form.

Method Summary
`static java.lang.String` | `quote4JS(java.lang.String val)` Encodes a single `String` value to JavaScript literal expression.
`static void` | `quote4JS(java.lang.StringBuffer res, java.lang.String val)` Encodes a single `String` value to a JavaScript literal expression.
`static java.lang.String` | `unquote4JS(java.lang.String val)` Converts a single JavaScript literal back to a String value and returns it.
`static void` | `unquote4JS(java.lang.StringBuffer res, java.lang.String literalString)` Takes a single JavaScript literal and converts it back to a String value, removing the start and end quotes, and then converting any backslash escaped value into its actual value.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### quote4JS

    public static void quote4JS(java.lang.StringBuffer res,
                                java.lang.String val)

  Encodes a single `String` value to a JavaScript literal expression.

  If you are constructing a JavaScript expression and you have a String value that you want to be expressed as a String literal in the JavaScript, you must use this method to scan the String and convert any embedded problematic characters into their escaped equivalents. The result of the conversion is written into the String buffer that you pass in. This routine also adds start and end quotes.

  Do NOT simply paste quotes before and after the string!

  Parameters:
    `res` - The `StringBuffer` object to which the encoded String value is added.
    `val` - The `String` value to encode.
  Returns:
    The JavaScript literal expression encoded from the supplied value.

### unquote4JS

    public static void unquote4JS(java.lang.StringBuffer res,
                                  java.lang.String literalString)
                           throws java.lang.Exception

  Takes a single JavaScript literal and converts it back to a String value, removing the start and end quotes, and then converting any backslash escaped value into its actual value.

  Note: This method does not recognize the terminating quote in any position except the last. It allows characters in the String that JavaScript will not allow. This means you can "trick" this conversion by passing an invalid literal, such as:

  "abc" + "def" | (this is an expression not a single literal)
  "abc |
  def" | (invalid line end in literal not detected)
  "abc"def" | (invalid quote in middle not detected)

  Parameters:
    `res` - The `StringBuffer` object to which the converted literalString is added.
    `literalString` - The JavaScript literal to be converted.
  Returns:
    The String value generated from the supplied JavaScript literal.
  Throws:
    `java.lang.Exception` - Thrown if the supplied literalString value is empty, `null` or not surrounded by double quotes. Furthermore this exception is thrown if the supplied res value is null.

### quote4JS

    public static java.lang.String quote4JS(java.lang.String val)

  Encodes a single `String` value to JavaScript literal expression.

  Parameters:
    `val` - The `String` value to encode.
  Returns:
    The JavaScript literal expression encoded from the supplied value.

### unquote4JS

    public static java.lang.String unquote4JS(java.lang.String val)
                                       throws java.lang.Exception

  Converts a single JavaScript literal back to a String value and returns it.

  The conversion starts with removing the start and end quotes and then converting any backslash escaped value into its actual value.

  Note: This method does not recognize the terminating quote in any position except the last. It allows characters in the String that `JavaScript` will not allow. This means you can "trick" this conversion by passing an invalid literal, such as:

  "abc" + "def" | (this is an expression not a single literal)
  "abc |
  def" | (invalid line end in literal not detected)
  "abc"def" | (invalid quote in middle not detected)

  Parameters:
    `val` - The JavaScript literal to be converted.
  Returns:
    The String value generated from the supplied JavaScript literal.
  Throws:
    `java.lang.Exception` - Thrown if the supplied value is not surrounded by double quotes or if the value is `null`.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD