|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.stripes.ajax.JavaScriptBuilder
public class JavaScriptBuilder
Builds a set of JavaScript statements that will re-construct the value of a Java object, including all Number, String, Enum, Boolean, Collection, Map and Array properties. Safely handles object graph circularities - each object will be translated only once, and all references will be valid.
The JavaScript created by the builder can be evaluated in JavaScript using:
var myObject = eval(generatedFragment);
Constructor Summary | |
---|---|
JavaScriptBuilder(Object root,
Object... objectsToExclude)
Constructs a new JavaScriptBuilder to build JS for the root object supplied. |
Method Summary | |
---|---|
JavaScriptBuilder |
addClassExclusion(Class<?>... clazz)
Adds one or more properties to the list of properties to exclude when translating to JavaScript. |
JavaScriptBuilder |
addPropertyExclusion(String... property)
Adds one or more properties to the list of property to exclude when translating to JavaScript. |
String |
build()
Causes the JavaScriptBuilder to navigate the properties of the supplied object and convert them to JavaScript. |
void |
build(Writer writer)
Causes the JavaScriptBuilder to navigate the properties of the supplied object and convert them to JavaScript, writing them to the supplied writer as it goes. |
String |
getRootVariableName()
Returns the name used to declare the root variable to which the built JavaScript object is assigned. |
String |
getScalarAsString(Object in)
Fetches the value of a scalar type as a String. |
boolean |
isExcludedType(Class<?> type)
Returns true if the supplied type should be excluded from conversion, otherwise returns false. |
boolean |
isScalarType(Object in)
Returns true if the object is of a type that can be converted to a simple JavaScript scalar, and false otherwise. |
static String |
quote(String string)
Quotes the supplied String and escapes all characters that could be problematic when eval()'ing the String in JavaScript. |
void |
setRootVariableName(String rootVariableName)
Sets an optional user-supplied root variable name. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JavaScriptBuilder(Object root, Object... objectsToExclude)
root
- The root object from which to being translation into JavaScriptobjectsToExclude
- Zero or more Strings and/or Classes to be excluded
from translation.Method Detail |
---|
public JavaScriptBuilder addPropertyExclusion(String... property)
property
- one or more property names to be excluded
public JavaScriptBuilder addClassExclusion(Class<?>... clazz)
clazz
- one or more classes to exclude
public void setRootVariableName(String rootVariableName)
rootVariableName
- the name to use when declaring the root variablepublic String getRootVariableName()
public String build()
public void build(Writer writer)
public boolean isExcludedType(Class<?> type)
public boolean isScalarType(Object in)
public String getScalarAsString(Object in)
public static String quote(String string)
string
- a String to be escaped and quoted
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |