net.sourceforge.templat.parser
Class TemplateParser

java.lang.Object
  extended by net.sourceforge.templat.parser.TemplateParser

public class TemplateParser
extends Object

Parser to render a (tokenized) template, given optional arguments. The parse method performs this action. The other methods are for use by the tokens, who manipulate the context and parse position of this parser.

Author:
Chris Mosher

Field Summary
static String VAR_ARGS
          Internal variable holding the arguments to the template
static String VAR_IF
          Internal variable used by IF statements
static String VAR_LOOP_INDEX
          Internal variable used by LOOP statements
static String VAR_LOOP_TIMES
          Internal variable used by LOOP statements
static String VAR_URL
          Internal variable holding the URL of the template
 
Constructor Summary
TemplateParser(List<TemplateToken> rToken, List<Object> rArg, URL url)
          Initializes this parser to use the given tokenized template (tToken), passing it the given arguments.
 
Method Summary
 void forgetParsePosition()
          Discards the parse position (from the internal stack) that was saved by a previous call to saveParsePosition.
 ContextStack getContext()
          Gets this parser's stack of contexts.
 void parse(Appendable appendTo)
          Parses this template and appends the rendered result to the given Appendable.
 void restoreParsePosition()
          Restores the parse position (from the internal stack) that was saved by a previous call to saveParsePosition.
 void saveParsePosition()
          Saves the current parse position (on an internal stack).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VAR_IF

public static final String VAR_IF
Internal variable used by IF statements

See Also:
Constant Field Values

VAR_LOOP_INDEX

public static final String VAR_LOOP_INDEX
Internal variable used by LOOP statements

See Also:
Constant Field Values

VAR_LOOP_TIMES

public static final String VAR_LOOP_TIMES
Internal variable used by LOOP statements

See Also:
Constant Field Values

VAR_ARGS

public static final String VAR_ARGS
Internal variable holding the arguments to the template

See Also:
Constant Field Values

VAR_URL

public static final String VAR_URL
Internal variable holding the URL of the template

See Also:
Constant Field Values
Constructor Detail

TemplateParser

public TemplateParser(List<TemplateToken> rToken,
                      List<Object> rArg,
                      URL url)
Initializes this parser to use the given tokenized template (tToken), passing it the given arguments.

Parameters:
rToken - tokenized template
rArg - arguments to pass into the template
url - the URL of the template (which is used to locate any included templates)
Method Detail

parse

public void parse(Appendable appendTo)
           throws TemplateParsingException
Parses this template and appends the rendered result to the given Appendable. This method calls each token's parse method to have that token perform its action. This parser maintains the context (variables and their values) for use by the tokens.

Parameters:
appendTo - Appendable to append the result to
Throws:
TemplateParsingException

saveParsePosition

public void saveParsePosition()
Saves the current parse position (on an internal stack). Used by some tokens.


restoreParsePosition

public void restoreParsePosition()
Restores the parse position (from the internal stack) that was saved by a previous call to saveParsePosition. Used by some tokens.


forgetParsePosition

public void forgetParsePosition()
Discards the parse position (from the internal stack) that was saved by a previous call to saveParsePosition. Used by some tokens.


getContext

public ContextStack getContext()
Gets this parser's stack of contexts.

Returns:
the context stack