| java.lang.Object sunlabs.brazil.template.TemplateRunner
TemplateRunner | public class TemplateRunner (Code) | | Class for processing html templates.
An html template is an ordinary html string, with additional
application specific tags added (sort of like XML). Each
tag is mapped to a java method of a template class, that rewrites its
tag into normal html.
The mechanism used to map templates into sessions is inadaquate, and
should be fixed in a future version.
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.
|
Constructor Summary | |
public | TemplateRunner(String names) 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. |
Method Summary | |
public String | getError() Return the last error message generated, or null of no
errors have occurred since the last call to "process". | public String | process(Server server, String prefix, Request request, String content, String sessionId) 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. Parameters: sessionId - An arbitrary identifier used to locate the correct instanceof the template class for processing this template. | public void | process(RewriteContext hr) Processes the next token in the HTML document represented by the
given RewriteContext . | public int | tagsProcessed() Return the # of tags replaced in the previous call to "process". |
tagsProcessed | int tagsProcessed(Code) | | |
TemplateRunner | public TemplateRunner(String names) throws ClassNotFoundException, ClassCastException(Code) | | 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 form tag_xxx or
tag_slash_xxx is invoked when the corrosponding
<xxx> or </xxx> tag is found.
The methods init and done 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 taht may be defined that don't follow the naming
convension 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.
Parameters: names - The names of the Template classes. This TemplateRunner willdispatch to the methods described by the union of all thetag methods in the given Template classes. The init and done methods for eachtemplate specified will be called in order. If any ofthe calls returns false , this handler terminatesand no output is generated. The names "comment", "string", and "defaultTag" arehandled specially. |
getError | public String getError()(Code) | | 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().
|
process | public String process(Server server, String prefix, Request request, String content, String sessionId)(Code) | | 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. Parameters: sessionId - An arbitrary identifier used to locate the correct instanceof the template class for processing this template. Thefirst time an identifier is used, a new instance is created. Parameters: args - The arguments passed to the templates init method. content or null |
process | public void process(RewriteContext hr)(Code) | | Processes the next token in the HTML document represented by the
given RewriteContext . Processing a token involves either
dispatching to a tag-handling method in one of the
Template objects, or just advancing to the next token
if no Template was interested.
Parameters: hr - The RewriteContext holding the state of the HTML document. |
tagsProcessed | public int tagsProcessed()(Code) | | Return the # of tags replaced in the previous call to "process".
|
|
|