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.voidProcesses the next token in the HTML document represented by the givenRewriteContext.intReturn the # of tags replaced in the previous call to "process".inttagsSeen()Return the # of HTML tags seen in the previous call to "process".protected TemplatetemplateFromTag(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_xxxortag_slash_xxxis invoked when the corrosponding <xxx> or </xxx> tag is found.Each instance of
_xnnin 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
initanddoneare 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 theHandlerorFilterthat invoked thisTemplateRunnerprefix- The prefix associated with the parentHandlerorFilternames- 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
initanddonemethods 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:
ClassNotFoundExceptionClassCastException
-
-
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 theTemplateobjects, or just advancing to the next token if noTemplatewas 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.
-