Class TemplateRunner
The mechanism used to map templates into sessions is inadaquate, and should be fixed in a future version. In the current implementation, Each session maintains its own set of template instances. Instance variables in template classes may be used to hold session specific state. Calls to a template are synchronized on the session id; only one request per session is dealt with simultaneously.
- Version:
- %W
- Author:
- Colin Stevens, Stephen Uhler
-
Constructor Summary
ConstructorsConstructorDescriptionTemplateRunner
(Server server, String prefix, String names) Process an HTML template with a template processing class. -
Method Summary
Modifier and TypeMethodDescriptiongetError()
Return the last error message generated, or null of no errors have occurred since the last call to "process".Process an html template file, using the supplied template processing Return the content of the template just processed, or null if there was no template processed.void
Processes the next token in the HTML document represented by the givenRewriteContext
.int
Return the # of tags replaced in the previous call to "process".int
tagsSeen()
Return the # of HTML tags seen in the previous call to "process".protected Template
templateFromTag
(RewriteContext hr, String tag) Return the object instance of the template that will process this tag (if any).
-
Constructor Details
-
TemplateRunner
public TemplateRunner(Server server, String prefix, String names) throws ClassNotFoundException, ClassCastException Process an HTML template with a template processing class. We peruse the template class, looking at all of its methods. When when we process a template, we match the html tags against the declared methods in the template class. Each method name of the formtag_xxx
ortag_slash_xxx
is invoked when the corrosponding <xxx> or </xxx> tag is found.Each instance of
_xnn
in the method name is replaced by the corrosponding hex code for the character. This allows non-printable tags to to be processed with templates.The methods
init
anddone
are each called once, at the beginning and end of the page respectively. These methods are called for all templates, in the order they are specified in the templates parameter.There are three methods that may be defined that don't follow the naming convention described above. They are:
comment
is called for each html/XML comment.string
is called for all text between any tags.defaultTag
is called for every tag that does not specifically have a tag method. If more than one template defines one of these methods, only the first template's method will be called.
If the server property "tagPrefix" associated with each template's properties prefix exists, it is used to prefix each tag name (this feature is for experimental support of XML namespaces, and probably doesn't belong here).
- Parameters:
server
- The HTTP server that created theHandler
orFilter
that invoked thisTemplateRunner
prefix
- The prefix associated with the parentHandler
orFilter
names
- The names of the Template classes or property prefixes (i.e. tokens) that, when concatenated with ".class" define a property that names a Template class. This TemplateRunner will dispatch to the methods described by the union of all the tag methods in the given Template classes.The
init
anddone
methods for each template specified will be called in order. If any of the calls returnsfalse
, this handler terminates and no output is generated.The names "comment", "string", and "defaultTag" are handled specially.
- Throws:
ClassNotFoundException
ClassCastException
-
-
Method Details
-
process
Process an html template file, using the supplied template processing Return the content of the template just processed, or null if there was no template processed.- Parameters:
content
- The template.sessionId
- An arbitrary identifier used to locate the correct instance of the template class for processing this template. The first time an identifier is used, a new instance is created.args
- The arguments passed to the templates init method.- Returns:
- content or null
-
process
Processes the next token in the HTML document represented by the givenRewriteContext
. Processing a token involves either dispatching to a tag-handling method in one of theTemplate
objects, or just advancing to the next token if noTemplate
was interested.- Parameters:
hr
- The RewriteContext holding the state of the HTML document.
-
getError
Return the last error message generated, or null of no errors have occurred since the last call to "process". XXX not thread safe between calls to process() and getError(). -
tagsSeen
public int tagsSeen()Return the # of HTML tags seen in the previous call to "process". -
tagsProcessed
public int tagsProcessed()Return the # of tags replaced in the previous call to "process". -
templateFromTag
Return the object instance of the template that will process this tag (if any). This allows templates to cooperate with each other. If you need to use this method, then one of us did something wrong.
-