org.ujac.util.template
Class BaseTemplateInterpreter

java.lang.Object
  extended by org.ujac.util.template.BaseTemplateInterpreter
All Implemented Interfaces:
TemplateInterpreter
Direct Known Subclasses:
DefaultTemplateInterpreter

public abstract class BaseTemplateInterpreter
extends Object
implements TemplateInterpreter

Name: TemplateInterpreter
Description: Description of the class.

Author:
lauerc

Field Summary
protected  ExpressionInterpreter exi
          The expression interpeter to use.
protected  ExpressionFilter expressionFilter
          The expression filter.
protected  Map tokenTypes
          The template token registry (_if_, _foreach_, _loop_, ...)
 
Constructor Summary
  BaseTemplateInterpreter()
          Constructs a TemplateInterpreter instance with specific attributes.
  BaseTemplateInterpreter(ExpressionInterpreter exi)
          Constructs a TemplateInterpreter instance with specific attributes.
protected BaseTemplateInterpreter(ExpressionInterpreter exi, Map tokenTypes)
          Constructs a TemplateInterpreter instance with specific attributes.
 
Method Summary
 TemplateToken createToken(String tokenName)
          Gets the token type that matches the given text.
 boolean evalBooleanExpr(Operand operand, TemplateContext ctx)
          Evaluates an expression as a boolean value.
 boolean evalBooleanExpr(String expression, TemplateContext ctx)
          Evaluates an expression as a boolean value.
 Date evalDateExpr(Operand operand, TemplateContext ctx)
          Evaluates an expression as a Date value.
 Date evalDateExpr(String expression, TemplateContext ctx)
          Evaluates an expression as a Date value.
 double evalDoubleExpr(Operand operand, TemplateContext ctx)
          Evaluates an expression as a double value.
 double evalDoubleExpr(String expression, TemplateContext ctx)
          Evaluates an expression as a double value.
 float evalFloatExpr(Operand operand, TemplateContext ctx)
          Evaluates an expression as a float value.
 float evalFloatExpr(String expression, TemplateContext ctx)
          Evaluates an expression as a float value.
 int evalIntExpr(Operand operand, TemplateContext ctx)
          Evaluates an expression as an int value.
 int evalIntExpr(String expression, TemplateContext ctx)
          Evaluates an expression as an int value.
 long evalLongExpr(Operand operand, TemplateContext ctx)
          Evaluates an expression as a long value.
 long evalLongExpr(String expression, TemplateContext ctx)
          Evaluates an expression as a long value.
 Object evalObjectExpr(Operand operand, TemplateContext ctx)
          Evaluates an expression as an Object.
 Object evalObjectExpr(String expression, TemplateContext ctx)
          Evaluates an expression as an Object.
 String evalStringExpr(Operand operand, TemplateContext ctx)
          Evaluates an expression as a String value.
 String evalStringExpr(String expression, TemplateContext ctx)
          Evaluates an expression as a String value.
 Time evalTimeExpr(Operand operand, TemplateContext ctx)
          Evaluates an expression as a Time value.
 Time evalTimeExpr(String expression, TemplateContext ctx)
          Evaluates an expression as a Time value.
 Timestamp evalTimestampExpr(Operand operand, TemplateContext ctx)
          Evaluates an expression as a Timestamp value.
 Timestamp evalTimestampExpr(String expression, TemplateContext ctx)
          Evaluates an expression as a Timestamp value.
 String execute(String template, TemplateContext ctx)
          Executes the given template.
 void execute(String template, Writer writer, TemplateContext ctx)
          Executes the given template.
 void execute(TemplateRoot template, Writer writer, TemplateContext ctx)
          Executes the given template.
 ExpressionFilter getExpressionFilter()
          Getter method for the the property expressionFilter.
 Class getTokenType(String tokenName)
          Gets the statement type that matches the given name.
 TemplateRoot parse(char[] source, int offset, int length)
          Parses the given template source code.
 TemplateRoot parse(String source)
          Parses the given template source code.
abstract  int parse(TemplateTokenContainer tokenContainer)
          Parses the given template token.
 ExpressionTuple parseExpr(char[] source, int offset, int lastPos)
          Parses an expression from the given source code range.
 ExpressionTuple parseExpr(String source)
          Parses an expression from the given source code range.
protected  void registerTokenTypes()
          Registers the token types.
 void setExpressionFilter(ExpressionFilter expressionFilter)
          Setter method for the the property expressionFilter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

exi

protected ExpressionInterpreter exi
The expression interpeter to use.


tokenTypes

protected Map tokenTypes
The template token registry (_if_, _foreach_, _loop_, ...)


expressionFilter

protected ExpressionFilter expressionFilter
The expression filter.

Constructor Detail

BaseTemplateInterpreter

public BaseTemplateInterpreter()
Constructs a TemplateInterpreter instance with specific attributes.


BaseTemplateInterpreter

public BaseTemplateInterpreter(ExpressionInterpreter exi)
Constructs a TemplateInterpreter instance with specific attributes.

Parameters:
exi - The expression interpreter to use.

BaseTemplateInterpreter

protected BaseTemplateInterpreter(ExpressionInterpreter exi,
                                  Map tokenTypes)
Constructs a TemplateInterpreter instance with specific attributes.

Parameters:
exi - The expression interpreter to use.
tokenTypes - The template token registry (_if_, _foreach_, _loop_, ...)
Method Detail

registerTokenTypes

protected void registerTokenTypes()
Registers the token types.


parse

public TemplateRoot parse(String source)
                   throws TemplateException,
                          IOException
Parses the given template source code.

Specified by:
parse in interface TemplateInterpreter
Parameters:
source - The source to parse.
Returns:
The parsed statement.
Throws:
TemplateException - If the expression could not be successfuly resolved
IOException - In case a I/O problem occured while writing the expression result.

parse

public TemplateRoot parse(char[] source,
                          int offset,
                          int length)
                   throws TemplateException,
                          IOException
Parses the given template source code.

Parameters:
source - The source to parse.
offset - The start position within the source.
length - The length of the area to parse.
Returns:
The parsed statement.
Throws:
TemplateException - If the expression could not be successfuly resolved
IOException - In case a I/O problem occured while writing the expression result.

parse

public abstract int parse(TemplateTokenContainer tokenContainer)
                   throws TemplateException,
                          IOException
Parses the given template token.

Parameters:
tokenContainer - The token container to fill.
Returns:
The continue position for the next parse step.
Throws:
TemplateException - If the expression could not be successfuly resolved
IOException - In case a I/O problem occured while writing the expression result.

execute

public String execute(String template,
                      TemplateContext ctx)
               throws TemplateException
Executes the given template.

Specified by:
execute in interface TemplateInterpreter
Parameters:
template - The source code of the template to execute.
ctx - The template context to use.
Returns:
The template execution result.
Throws:
TemplateException - If the an expression could not be successfuly resolved

execute

public void execute(String template,
                    Writer writer,
                    TemplateContext ctx)
             throws TemplateException,
                    IOException
Executes the given template.

Specified by:
execute in interface TemplateInterpreter
Parameters:
template - The source code of the template to execute.
writer - The writer to output the result to.
ctx - The template context to use.
Throws:
TemplateException - If the an expression could not be successfuly resolved
IOException - If something went wrong while writing the result to the given writer.

execute

public void execute(TemplateRoot template,
                    Writer writer,
                    TemplateContext ctx)
             throws TemplateException,
                    IOException
Executes the given template.

Specified by:
execute in interface TemplateInterpreter
Parameters:
template - The root element of the template parse result.
writer - The writer to output the result to.
ctx - The template context to use.
Throws:
TemplateException - If the an expression could not be successfuly resolved
IOException - If something went wrong while writing the result to the given writer.

parseExpr

public final ExpressionTuple parseExpr(String source)
                                throws ExpressionException
Parses an expression from the given source code range.

Parameters:
source - The source code, to be parsed.
Returns:
The parsed expression.
Throws:
ExpressionException - If the expression could not be successfuly resolved

parseExpr

public final ExpressionTuple parseExpr(char[] source,
                                       int offset,
                                       int lastPos)
                                throws ExpressionException
Parses an expression from the given source code range.

Parameters:
source - The source code, to be parsed.
offset - The offset from which to parse the expression string.
lastPos - The last position to which to parse the expression string.
Returns:
The parsed expression.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalBooleanExpr

public final boolean evalBooleanExpr(Operand operand,
                                     TemplateContext ctx)
                              throws ExpressionException
Evaluates an expression as a boolean value.

Parameters:
operand - The operand to evaluate.
ctx - The template context.
Returns:
The evaluated boolean.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalBooleanExpr

public final boolean evalBooleanExpr(String expression,
                                     TemplateContext ctx)
                              throws ExpressionException
Evaluates an expression as a boolean value.

Specified by:
evalBooleanExpr in interface TemplateInterpreter
Parameters:
expression - The expression to evaluate.
ctx - The template context.
Returns:
The evaluated boolean.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalIntExpr

public int evalIntExpr(Operand operand,
                       TemplateContext ctx)
                throws ExpressionException
Evaluates an expression as an int value.

Parameters:
operand - The operand to evaluate.
ctx - The template context.
Returns:
The evaluated boolean.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalIntExpr

public int evalIntExpr(String expression,
                       TemplateContext ctx)
                throws ExpressionException
Evaluates an expression as an int value.

Specified by:
evalIntExpr in interface TemplateInterpreter
Parameters:
expression - The expression to evaluate.
ctx - The template context.
Returns:
The evaluated boolean.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalLongExpr

public long evalLongExpr(Operand operand,
                         TemplateContext ctx)
                  throws ExpressionException
Evaluates an expression as a long value.

Parameters:
operand - The operand to evaluate.
ctx - The template context.
Returns:
The evaluated boolean.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalLongExpr

public long evalLongExpr(String expression,
                         TemplateContext ctx)
                  throws ExpressionException
Evaluates an expression as a long value.

Specified by:
evalLongExpr in interface TemplateInterpreter
Parameters:
expression - The expression to evaluate.
ctx - The template context.
Returns:
The evaluated boolean.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalFloatExpr

public float evalFloatExpr(Operand operand,
                           TemplateContext ctx)
                    throws ExpressionException
Evaluates an expression as a float value.

Parameters:
operand - The operand to evaluate.
ctx - The template context.
Returns:
The evaluated boolean.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalFloatExpr

public float evalFloatExpr(String expression,
                           TemplateContext ctx)
                    throws ExpressionException
Evaluates an expression as a float value.

Specified by:
evalFloatExpr in interface TemplateInterpreter
Parameters:
expression - The expression to evaluate.
ctx - The template context.
Returns:
The evaluated boolean.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalDoubleExpr

public double evalDoubleExpr(Operand operand,
                             TemplateContext ctx)
                      throws ExpressionException
Evaluates an expression as a double value.

Parameters:
operand - The operand to evaluate.
ctx - The template context.
Returns:
The evaluated boolean.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalDoubleExpr

public double evalDoubleExpr(String expression,
                             TemplateContext ctx)
                      throws ExpressionException
Evaluates an expression as a double value.

Specified by:
evalDoubleExpr in interface TemplateInterpreter
Parameters:
expression - The expression to evaluate.
ctx - The template context.
Returns:
The evaluated boolean.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalDateExpr

public Date evalDateExpr(Operand operand,
                         TemplateContext ctx)
                  throws ExpressionException
Evaluates an expression as a Date value.

Parameters:
operand - The operand to evaluate.
ctx - The template context.
Returns:
The evaluated boolean.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalDateExpr

public Date evalDateExpr(String expression,
                         TemplateContext ctx)
                  throws ExpressionException
Evaluates an expression as a Date value.

Specified by:
evalDateExpr in interface TemplateInterpreter
Parameters:
expression - The expression to evaluate.
ctx - The template context.
Returns:
The evaluated boolean.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalTimeExpr

public Time evalTimeExpr(Operand operand,
                         TemplateContext ctx)
                  throws ExpressionException
Evaluates an expression as a Time value.

Parameters:
operand - The operand to evaluate.
ctx - The template context.
Returns:
The evaluated boolean.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalTimeExpr

public Time evalTimeExpr(String expression,
                         TemplateContext ctx)
                  throws ExpressionException
Evaluates an expression as a Time value.

Specified by:
evalTimeExpr in interface TemplateInterpreter
Parameters:
expression - The expression to evaluate.
ctx - The template context.
Returns:
The evaluated boolean.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalTimestampExpr

public Timestamp evalTimestampExpr(Operand operand,
                                   TemplateContext ctx)
                            throws ExpressionException
Evaluates an expression as a Timestamp value.

Parameters:
operand - The operand to evaluate.
ctx - The template context.
Returns:
The evaluated boolean.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalTimestampExpr

public Timestamp evalTimestampExpr(String expression,
                                   TemplateContext ctx)
                            throws ExpressionException
Evaluates an expression as a Timestamp value.

Specified by:
evalTimestampExpr in interface TemplateInterpreter
Parameters:
expression - The expression to evaluate.
ctx - The template context.
Returns:
The evaluated boolean.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalStringExpr

public String evalStringExpr(Operand operand,
                             TemplateContext ctx)
                      throws ExpressionException
Evaluates an expression as a String value.

Parameters:
operand - The operand to evaluate.
ctx - The template context.
Returns:
The evaluated boolean.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalStringExpr

public String evalStringExpr(String expression,
                             TemplateContext ctx)
                      throws ExpressionException
Evaluates an expression as a String value.

Specified by:
evalStringExpr in interface TemplateInterpreter
Parameters:
expression - The expression to evaluate.
ctx - The template context.
Returns:
The evaluated boolean.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalObjectExpr

public final Object evalObjectExpr(Operand operand,
                                   TemplateContext ctx)
                            throws ExpressionException
Evaluates an expression as an Object.

Parameters:
operand - The operand to evaluate.
ctx - The template context.
Returns:
The evaluated object.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalObjectExpr

public final Object evalObjectExpr(String expression,
                                   TemplateContext ctx)
                            throws ExpressionException
Evaluates an expression as an Object.

Specified by:
evalObjectExpr in interface TemplateInterpreter
Parameters:
expression - The expression to evaluate.
ctx - The template context.
Returns:
The evaluated object.
Throws:
ExpressionException - If the expression could not be successfuly resolved

createToken

public final TemplateToken createToken(String tokenName)
                                throws StatementException
Gets the token type that matches the given text.

Parameters:
tokenName - The token name.
Returns:
Integer The detected type or null.
Throws:
StatementException - In case the instantiation failed.

getTokenType

public final Class getTokenType(String tokenName)
Gets the statement type that matches the given name.

Parameters:
tokenName - The token name.
Returns:
Integer The detected type or null.

getExpressionFilter

public ExpressionFilter getExpressionFilter()
Getter method for the the property expressionFilter.

Specified by:
getExpressionFilter in interface TemplateInterpreter
Returns:
The current value of property expressionFilter.

setExpressionFilter

public void setExpressionFilter(ExpressionFilter expressionFilter)
Setter method for the the property expressionFilter.

Specified by:
setExpressionFilter in interface TemplateInterpreter
Parameters:
expressionFilter - The value to set for the property expressionFilter.


Copyright © 2003-2004 UJAC.org. All Rights Reserved.