public interface TemplateTokenRetriever
To use the TemplateStreamer, you have to supply a TemplateTokenRetriever to stream token values for the specific tokens. Create a class that implements this interface, and pass an instance into the TemplateStreamer.
There is only one method to implement, writeTokenValue(). This is given a Writer object to stream the value to, and the token name (the text that was between the double curley braces).
For example, consider the following template:
You have a balance of {{amt}} in your account.
This template there is one token. The name of that token is "amt". The template will stream out all of the text up to the "{{". Then it will call the TemplateTokenRetrieve, passing the Writer object, and the string template name "amt". Your TemplateTokenRetriever will use the "amt" name to find the real amount value, and stream that to the Writer. After returning from the call, the TemplateStreamer will write the rest of the text of the template, everything after the "}}".
That is really all there is to it. Use the token "name" to find the value, and then stream it to the output. There are no constraints on the name and there is no reason this has to be a simple value. If you wish, you could have multiple parameters, or even a complex expression of any syntax. The only constraint is that the name can NOT contain two curley braces in a row.
User proper encoding: If your template is supposed to be HTML output, then be sure that when you stream the value, that you encode that value properly for HTML.
| 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.
|
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
|
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.
|
void writeTokenValue(java.io.Writer out,
java.lang.String token)
throws java.lang.Exception
java.lang.Exceptionvoid writeTokenValueRaw(java.io.Writer out,
java.lang.String token)
throws java.lang.Exception
java.lang.Exceptionvoid writeTokenDate(java.io.Writer out,
java.lang.String token,
java.lang.String format)
throws java.lang.Exception
java.lang.Exceptionint initLoop(java.lang.String id,
java.lang.String token)
throws java.lang.Exception
java.lang.Exceptionvoid setIteration(java.lang.String id,
int loopCount)
throws java.lang.Exception
java.lang.Exceptionvoid closeLoop(java.lang.String id)
throws java.lang.Exception
java.lang.Exceptionboolean ifValue(java.lang.String token)
throws java.lang.Exception
java.lang.Exceptionvoid debugDump(java.io.Writer out)
throws java.lang.Exception
java.lang.Exception