ICEfaces ACE Components 3.3.0
Java API Documentation

org.icefaces.ace.util
Class JSONBuilder

java.lang.Object
  extended by org.icefaces.ace.util.JSONBuilder

public class JSONBuilder
extends java.lang.Object

Utility API that builds the parameter strings, performs param escaping. Output is a JSON string as specified at json.org. Based on spec. from Mark Collette and code from YUI. List of escaped characters can be found at json.org.


Constructor Summary
JSONBuilder()
           
 
Method Summary
 JSONBuilder beginArray()
          Begins an anonymous array.
 JSONBuilder beginArray(java.lang.String key)
           
 JSONBuilder beginFunction(java.lang.String name)
           
 JSONBuilder beginMap()
          Begins an anonymous object.
 JSONBuilder beginMap(java.lang.String key)
          Begins a named object.
static JSONBuilder create()
          Makes a new instance of JSONBuilder.
 JSONBuilder endArray()
           
 JSONBuilder endFunction()
           
 JSONBuilder endMap()
          Ends an object.
 JSONBuilder entry(java.lang.String key, boolean value)
          Adds a boolean property to a map.
 JSONBuilder entry(java.lang.String key, double value)
          Adds a double property to a map.
 JSONBuilder entry(java.lang.String key, float value)
          Adds a float property to a map.
 JSONBuilder entry(java.lang.String key, int value)
          Adds an int property to a map.
 JSONBuilder entry(java.lang.String key, long value)
          Adds a long property to a map.
 JSONBuilder entry(java.lang.String key, java.lang.String value)
          Adds a String property to a map.
 JSONBuilder entry(java.lang.String key, java.lang.String[] keyValuePairs)
          Append a key bound String array that is itself a set of key-value pairs to a map.
 JSONBuilder entry(java.lang.String key, java.lang.String value, boolean isStringLiteral)
          Adds a String property as String literal optionally to a map.
 JSONBuilder entryNonNullValue(java.lang.String key, java.lang.Boolean value)
          Adds a Boolean property to a map only if the value is non-null, otherwise the key/value pair will not be added at all.
 JSONBuilder entryNonNullValue(java.lang.String key, java.lang.Double value)
          Adds a Double property to a map only if the value is non-null, otherwise the key/value pair will not be added at all.
 JSONBuilder entryNonNullValue(java.lang.String key, java.lang.Float value)
          Adds a Float property to a map only if the value is non-null, otherwise the key/value pair will not be added at all.
 JSONBuilder entryNonNullValue(java.lang.String key, java.lang.Integer value)
          Adds an Integer property to a map only if the value is non-null, otherwise the key/value pair will not be added at all.
 JSONBuilder entryNonNullValue(java.lang.String key, java.lang.Long value)
          Adds a Long property to a map only if the value is non-null, otherwise the key/value pair will not be added at all.
 JSONBuilder entryNonNullValue(java.lang.String key, java.lang.String value)
          Adds a String property to a map only if the value is non-null, otherwise the key/value pair will not be added at all.
static java.lang.String escapeString(java.lang.String value)
           
 JSONBuilder initialiseVar(java.lang.String varName)
           
 JSONBuilder initialiseWindowVar(java.lang.String varName)
           
 JSONBuilder item(boolean value)
          Adds a boolean to an array or function call.
 JSONBuilder item(double value)
          Adds a double to an array or function call.
 JSONBuilder item(float value)
          Adds a float to an array or function call.
 JSONBuilder item(int value)
          Adds an int to an array or function call.
 JSONBuilder item(long value)
          Adds a long to an array or function call.
 JSONBuilder item(java.lang.String value)
          Adds an escaped String to an array or function call.
 JSONBuilder item(java.lang.String value, boolean escaped)
          Adds a String to an array or function call.
 java.lang.String toString()
          Outputs the JSON string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JSONBuilder

public JSONBuilder()
Method Detail

create

public static JSONBuilder create()
Makes a new instance of JSONBuilder.

Returns:
a reference to this object.

initialiseVar

public JSONBuilder initialiseVar(java.lang.String varName)

initialiseWindowVar

public JSONBuilder initialiseWindowVar(java.lang.String varName)

beginMap

public JSONBuilder beginMap()
Begins an anonymous object.

Returns:
a reference to this object.

beginMap

public JSONBuilder beginMap(java.lang.String key)
Begins a named object.

Parameters:
key - name of the object.
Returns:
a reference to this object.

endMap

public JSONBuilder endMap()
Ends an object.

Returns:
a reference to this object.

beginArray

public JSONBuilder beginArray()
Begins an anonymous array.

Returns:
a reference to this object.

beginArray

public JSONBuilder beginArray(java.lang.String key)

endArray

public JSONBuilder endArray()

beginFunction

public JSONBuilder beginFunction(java.lang.String name)

endFunction

public JSONBuilder endFunction()

entry

public JSONBuilder entry(java.lang.String key,
                         int value)
Adds an int property to a map.

Parameters:
key - name of the property.
value - value of the property.
Returns:
a reference to this object.

entry

public JSONBuilder entry(java.lang.String key,
                         long value)
Adds a long property to a map.

Parameters:
key - name of the property.
value - value of the property.
Returns:
a reference to this object.

entry

public JSONBuilder entry(java.lang.String key,
                         float value)
Adds a float property to a map.

Parameters:
key - name of the property.
value - value of the property.
Returns:
a reference to this object.

entry

public JSONBuilder entry(java.lang.String key,
                         double value)
Adds a double property to a map.

Parameters:
key - name of the property.
value - value of the property.
Returns:
a reference to this object.

entry

public JSONBuilder entry(java.lang.String key,
                         boolean value)
Adds a boolean property to a map.

Parameters:
key - name of the property.
value - value of the property.
Returns:
a reference to this object.

entry

public JSONBuilder entry(java.lang.String key,
                         java.lang.String[] keyValuePairs)
Append a key bound String array that is itself a set of key-value pairs to a map. Even array indexes = key, odd array index = values

Parameters:
key - overall key to put entry under
keyValuePairs - Array of key value pair string entries
Returns:
The builder object

entryNonNullValue

public JSONBuilder entryNonNullValue(java.lang.String key,
                                     java.lang.Integer value)
Adds an Integer property to a map only if the value is non-null, otherwise the key/value pair will not be added at all.

Parameters:
key - name of the property.
value - value of the property.
Returns:
a reference to this object.

entryNonNullValue

public JSONBuilder entryNonNullValue(java.lang.String key,
                                     java.lang.Long value)
Adds a Long property to a map only if the value is non-null, otherwise the key/value pair will not be added at all.

Parameters:
key - name of the property.
value - value of the property.
Returns:
a reference to this object.

entryNonNullValue

public JSONBuilder entryNonNullValue(java.lang.String key,
                                     java.lang.Float value)
Adds a Float property to a map only if the value is non-null, otherwise the key/value pair will not be added at all.

Parameters:
key - name of the property.
value - value of the property.
Returns:
a reference to this object.

entryNonNullValue

public JSONBuilder entryNonNullValue(java.lang.String key,
                                     java.lang.Double value)
Adds a Double property to a map only if the value is non-null, otherwise the key/value pair will not be added at all.

Parameters:
key - name of the property.
value - value of the property.
Returns:
a reference to this object.

entryNonNullValue

public JSONBuilder entryNonNullValue(java.lang.String key,
                                     java.lang.Boolean value)
Adds a Boolean property to a map only if the value is non-null, otherwise the key/value pair will not be added at all.

Parameters:
key - name of the property.
value - value of the property.
Returns:
a reference to this object.

entryNonNullValue

public JSONBuilder entryNonNullValue(java.lang.String key,
                                     java.lang.String value)
Adds a String property to a map only if the value is non-null, otherwise the key/value pair will not be added at all. Adds quotes and does JSON string escaping, as described at json.org.

Parameters:
key - name of the property.
value - value of the property.
Returns:
a reference to this object.

entry

public JSONBuilder entry(java.lang.String key,
                         java.lang.String value)
Adds a String property to a map. Adds quotes and does JSON string escaping, as described at json.org.

Parameters:
key - name of the property.
value - value of the property.
Returns:
a reference to this object.

entry

public JSONBuilder entry(java.lang.String key,
                         java.lang.String value,
                         boolean isStringLiteral)
Adds a String property as String literal optionally to a map. Adds quotes and does JSON string escaping, as described at json.org.

Parameters:
key - name of the property.
value - value of the property.
Returns:
a reference to this object.

item

public JSONBuilder item(int value)
Adds an int to an array or function call.

Parameters:
value - value of the item.
Returns:
a reference to this object.

item

public JSONBuilder item(long value)
Adds a long to an array or function call.

Parameters:
value - value of the item.
Returns:
a reference to this object.

item

public JSONBuilder item(float value)
Adds a float to an array or function call.

Parameters:
value - value of the item.
Returns:
a reference to this object.

item

public JSONBuilder item(double value)
Adds a double to an array or function call.

Parameters:
value - value of the item.
Returns:
a reference to this object.

item

public JSONBuilder item(boolean value)
Adds a boolean to an array or function call.

Parameters:
value - value of the item.
Returns:
a reference to this object.

item

public JSONBuilder item(java.lang.String value)
Adds an escaped String to an array or function call.

Parameters:
value - value of the item.
Returns:
a reference to this object.

item

public JSONBuilder item(java.lang.String value,
                        boolean escaped)
Adds a String to an array or function call.

Parameters:
value - value of the item.
Returns:
a reference to this object.

escapeString

public static java.lang.String escapeString(java.lang.String value)

toString

public java.lang.String toString()
Outputs the JSON string.

Overrides:
toString in class java.lang.Object
Returns:
the JSON string.

ICEfaces ACE Components 3.3.0
Java API Documentation

Copyright 2013 ICEsoft Technologies Canada Corp., All Rights Reserved.