public class TemplateJSONRetriever extends java.lang.Object implements TemplateTokenRetriever
This is a TemplateStreamer that gets all the information for the tokens from JSON object tree. The token values are expressed as path expressions with dots between them. For example, for a JSON structure like this:
{
cust: [
{
address: {
street: "666 bottom row",
city: "Pittsburg"
},
name: "Jones"
},
{
address: {
street: "1 Elm St.",
city: "Highland Park"
},
name: "Smith"
}
]
}
cust.0.name == Jones
cust.1.name == Smith
cust.1.address.street == 1 Elm St.
Expressions that accurately address leaf nodes will write that string value If the leaf is a number it will write a string representation of that. If the expression ends at an object or an array, it will write nothing. If the expression addresses a member that does not exist, it writes nothing.
| Constructor and Description |
|---|
TemplateJSONRetriever(JSONObject _data) |
| Modifier and Type | Method and Description |
|---|---|
void |
closeLoop(java.lang.String id)
When a loop is finished, this is called so that the id can be freed up
and references to this id value will no longer work.
|
void |
debugDump(java.io.Writer out)
Produce an output which represents all of the tokens that can be used
in the current template given the specific context.
|
boolean |
ifValue(java.lang.String token)
Looks at the value specified, and returns boolean
scalar:
true means for a scalar that there is a value there, and that the
value is not 0, false, or null.
|
int |
initLoop(java.lang.String id,
java.lang.String token)
A loop has an identifier which functions as the iterated data item,
and a token which refers to the array that you are iterating over.
|
static int |
safeConvertInt(java.lang.String val)
designed primarily for returning date long values works only for positive
integer (long) values considers all numeral, ignores all letter and
punctuation never throws an exception if you give this something that is
not a number, you get surprising result.
|
static long |
safeConvertLong(java.lang.String val) |
void |
setIteration(java.lang.String id,
int loopCount)
Before each time through a loop, this will be called to say which
iteration of the loop it is in, and therevore which index element of the
chosen array (see initLoop) should be accessed
|
static java.util.ArrayList<java.lang.String> |
splitDots(java.lang.String val)
Breaks a string into a list of strings using dots (periods)
as separators of the token, and trimming each token of
spaces if there are any.
|
void |
writeTokenDate(java.io.Writer out,
java.lang.String token,
java.lang.String format)
token specifies a date, and this will format the date for
inclusion in the form using the format specified in the last parameter.
|
void |
writeTokenValue(java.io.Writer out,
java.lang.String token)
The token passed will be all text between the double curly brace
delimiter.
|
void |
writeTokenValueRaw(java.io.Writer out,
java.lang.String token)
List writeTokenValue, but without the HTML encoding.
|
public TemplateJSONRetriever(JSONObject _data)
public void writeTokenValue(java.io.Writer out,
java.lang.String token)
throws java.lang.Exception
TemplateTokenRetrieverwriteTokenValue in interface TemplateTokenRetrieverjava.lang.Exceptionpublic void writeTokenValueRaw(java.io.Writer out,
java.lang.String token)
throws java.lang.Exception
TemplateTokenRetrieverwriteTokenValueRaw in interface TemplateTokenRetrieverjava.lang.Exceptionpublic void writeTokenDate(java.io.Writer out,
java.lang.String token,
java.lang.String format)
throws java.lang.Exception
TemplateTokenRetrieverwriteTokenDate in interface TemplateTokenRetrieverjava.lang.Exceptionpublic int initLoop(java.lang.String id,
java.lang.String token)
throws java.lang.Exception
TemplateTokenRetrieverinitLoop in interface TemplateTokenRetrieverjava.lang.Exceptionpublic void setIteration(java.lang.String id,
int loopCount)
throws java.lang.Exception
TemplateTokenRetrieversetIteration in interface TemplateTokenRetrieverjava.lang.Exceptionpublic void closeLoop(java.lang.String id)
throws java.lang.Exception
TemplateTokenRetrievercloseLoop in interface TemplateTokenRetrieverjava.lang.Exceptionpublic boolean ifValue(java.lang.String token)
throws java.lang.Exception
TemplateTokenRetrieverifValue in interface TemplateTokenRetrieverjava.lang.Exceptionpublic void debugDump(java.io.Writer out)
throws java.lang.Exception
TemplateTokenRetrieverdebugDump in interface TemplateTokenRetrieverjava.lang.Exceptionpublic static int safeConvertInt(java.lang.String val)
public static long safeConvertLong(java.lang.String val)
public static java.util.ArrayList<java.lang.String> splitDots(java.lang.String val)