|
terp - the Codemesh Modular Template Interpreter v1.3.304 |
|||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | |||||||||
See:
Description
| Class Summary | |
|---|---|
| PathTokenStream | A tokenizer for path expressions. |
| TerpContextImpl | The public portion of the context in which bindings and general evaluation settings are specified. |
| TerpEvaluatorImpl | The default evaluator for terp templates and expressions. |
| TerpParser | The parser that converts expression and template sources into abstract syntax trees. |
| TerpRegistrarImpl | The default implementation of a registrar for the terp framework. |
| TextTokenStream | A token stream that distinguishes between text and embedded tokens. |
| TokenStream | The baseclass for token-producing streams. |
The com.codemesh.terp.eval package contains most of the types that you would use when you embed terp into your own application. When you use terp programmatically, you need to first parse the template or expression using a TerpParser instance. You need to create a context in which the template or expression is going to be evaluated. The default context implemenetation is provided by the TerpContextImpl type. The parser and the context are then handed to a TerpEvaluatorImpl instance which performs the expansion or evaluation.
The following snippet demonstrates this usage in an expression evaluation:
TerpParser parser = new TerpParser( "2*pi", TokenizerState.EXPRESSION );
TerpContext ctx = new TerpContextImpl();
TerpEvaluator eval = TerpEvaluatorImpl.getInstance();
Object result;
try {
result = eval.evaluate( parser, ctx );
}
catch( TerpException te ) {
// ...
}
The following snippet demonstrates this usage in a template expansion:
TerpParser parser = new TerpParser( "The value of 2*pi is ${(2*pi)['%4.2f']}", TokenizerState.TEXT );
TerpContext ctx = new TerpContextImpl();
TerpEvaluator eval = TerpEvaluatorImpl.getInstance();
try {
eval.expand( parser, ctx );
System.out.println( ctx.getAppendable().toString() );
}
catch( TerpException te ) {
// ...
}
It is important to keep the following points in mind:
|
terp - the Codemesh Modular Template Interpreter v1.3.304 |
|||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | |||||||||