Package sunlabs.brazil.template
Class RewriteContext
- java.lang.Object
-
- sunlabs.brazil.handler.HtmlRewriter
-
- sunlabs.brazil.template.RewriteContext
-
public class RewriteContext extends HtmlRewriter
A variant containing instance variables that may be referenced by rewriting filters. Every implementation of the template class may define methods of the form:tag_xxx
ortag_slash_xxx
which will get called when the corrosponding HTML entity<xxx ...>
or</xxx ...>
is found in the content being filtered.An instance of this class is passed to each
tag
method, permitting introspection of the current filtering context.- Version:
- %V% RewriteContext.java
-
-
Field Summary
Fields Modifier and Type Field Description java.lang.String
prefix
The prefix to use for locating keys in the server or request properties objects.Request
request
The Request object, as passed to a handler's respond method.Server
server
The server object, as passed to a handler's init method.java.lang.String
sessionId
A unique session id, if available.java.lang.String
templatePrefix
This is the prefix defined by the invoker of a set of templates.-
Fields inherited from class sunlabs.brazil.handler.HtmlRewriter
lex, sb
-
-
Constructor Summary
Constructors Constructor Description RewriteContext(Server server, java.lang.String prefix, Request request, java.lang.String content, java.lang.String sessionId, TemplateRunner runner, java.util.Vector templates)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abort()
Cause this RewriteContext to abort its processing.void
addClosingTag(java.lang.String tag)
Add a closing tag to the list of tags that mark un-interpreted text Deal with the tag prefix, if anyboolean
checkRewriteState(int state)
Check whether this RewriteContext is in the specified state.void
decrNestingLevel()
Decrement the nesting level counter.java.lang.String
get(java.lang.String name)
overwrite "get" to automatically do ${...} substitutions The default is "true".java.lang.String
get(java.lang.String name, boolean subst)
Get an attribute value, and optionally perform ${...} substitutions.java.lang.String
get(java.lang.String name, java.lang.String dflt)
Get a tag attribute, with a default value.java.util.Properties
getNamespaceProperties()
Get the proper properties table based on the "namespace" attribute.int
getNestingLevel()
Return the current nesting level counter.void
incrNestingLevel()
Increment the nesting level counter.boolean
isClosingFor(java.lang.String tag)
See if the current token is the closing tag for the given string.boolean
isClosingFor(java.lang.String tag, boolean close)
See if the current token is the closing tag for the given string.boolean
isTrue(java.lang.String name)
Determine the value of a boolean attribute in the current tag.void
process()
Invoke a template on this token, if any template is interested in this token.boolean
setRewriteState(int state)
Set the given state of this RewriteContext.java.lang.String
snarfTillClose()
Grab all the markup between the current tag, and the corrosponding closing tag.void
substAttributeValues()
Substitute all attribute values.int
tagsSeen()
Return the number of HTML tags seen to this point.Template
templateFromTag(java.lang.String tag)
Get the template that will process the supplied tag (if any).void
unsetRewriteState(int state)
Unset the given state of this RewriteContext.-
Methods inherited from class sunlabs.brazil.handler.HtmlRewriter
accumulate, append, appendToken, getArgs, getBody, getMap, getTag, getToken, getType, isSingleton, keys, killToken, nextTag, nextToken, pushback, put, quote, remove, reset, setSingleton, setTag, setType, tagCount, tokenCount, toString
-
-
-
-
Field Detail
-
server
public Server server
The server object, as passed to a handler's init method.
-
prefix
public java.lang.String prefix
The prefix to use for locating keys in the server or request properties objects. This is a dynamic value that changes during template processing. Before each template is processed, it is set to the prefix associated with the template class that the current tag belongs to.
-
templatePrefix
public java.lang.String templatePrefix
This is the prefix defined by the invoker of a set of templates. Its value corrosponds to the class that invokes a set of templates.
-
request
public Request request
The Request object, as passed to a handler's respond method.
-
sessionId
public java.lang.String sessionId
A unique session id, if available.
-
-
Constructor Detail
-
RewriteContext
public RewriteContext(Server server, java.lang.String prefix, Request request, java.lang.String content, java.lang.String sessionId, TemplateRunner runner, java.util.Vector templates)
-
-
Method Detail
-
abort
public void abort()
Cause this RewriteContext to abort its processing.
-
setRewriteState
public boolean setRewriteState(int state)
Set the given state of this RewriteContext.
-
unsetRewriteState
public void unsetRewriteState(int state)
Unset the given state of this RewriteContext.
-
checkRewriteState
public boolean checkRewriteState(int state)
Check whether this RewriteContext is in the specified state.
-
incrNestingLevel
public void incrNestingLevel()
Increment the nesting level counter.
-
decrNestingLevel
public void decrNestingLevel()
Decrement the nesting level counter.
-
getNestingLevel
public int getNestingLevel()
Return the current nesting level counter.
-
process
public void process()
Invoke a template on this token, if any template is interested in this token. The template may consume more than just this token, if it wants.
-
tagsSeen
public int tagsSeen()
Return the number of HTML tags seen to this point.
-
get
public java.lang.String get(java.lang.String name)
overwrite "get" to automatically do ${...} substitutions The default is "true". Setting the default to "false" and recompiling is more backward compatible (but less useful).- Overrides:
get
in classHtmlRewriter
- Returns:
- The value to which the specified key is mapped, or
null
if the key was not in the attributes. - See Also:
LexML.getAttributes()
-
get
public java.lang.String get(java.lang.String name, boolean subst)
Get an attribute value, and optionally perform ${...} substitutions.
-
get
public java.lang.String get(java.lang.String name, java.lang.String dflt)
Get a tag attribute, with a default value. The name is looked-up as an attribute in the current tag. If it is not found, the configuration property by the same name is used. If that is not found,dflt
is used instead.- Parameters:
name
- The name of the attribute to look updflt
- The default attribute value (may be null)- Returns:
- The value of "name"
-
isTrue
public boolean isTrue(java.lang.String name)
Determine the value of a boolean attribute in the current tag. ${...} substitution is performed on the value.- Parameters:
name
- The name of the boolean attribute- Returns:
- false if the value is: null, "", "0", "no", "off", or "false" true otherwise. "attribute=" is false, but "attribute" with no value is true;
-
isClosingFor
public boolean isClosingFor(java.lang.String tag)
See if the current token is the closing tag for the given string. Account for tag prefix, if any.- Parameters:
tag
- tag whose match ( e.g. /[prefix]tag is to be found- Returns:
- true if the current tag closes "tag"
-
isClosingFor
public boolean isClosingFor(java.lang.String tag, boolean close)
See if the current token is the closing tag for the given string. Account for tag prefix, if any.- Parameters:
tag
- tag whose match ( e.g. /[prefix]tag is to be foundclose
- if set, "tag" matches "/[prefix]tag", otherwise tag matches "[prefix]tag".- Returns:
- true if the current tag closes "tag"
-
snarfTillClose
public java.lang.String snarfTillClose()
Grab all the markup between the current tag, and the corrosponding closing tag. Nesting is supported. If there is no markup, or the current tag is a singleton, the empty string is returned. The starting and ending tags are not included in the markup.
-
addClosingTag
public void addClosingTag(java.lang.String tag)
Add a closing tag to the list of tags that mark un-interpreted text Deal with the tag prefix, if any
-
getNamespaceProperties
public java.util.Properties getNamespaceProperties()
Get the proper properties table based on the "namespace" attribute. The namespaces "local" (the default) and "server" are special. The "sessionTable" cinfiguration property can be used to override the default session-table, which defaults to the template handler/filter prefix.
-
templateFromTag
public Template templateFromTag(java.lang.String tag)
Get the template that will process the supplied tag (if any). This allows template classes to get a handle on the template instances of other classes running in the same template processing step. If you need this (and sometimes you do), then there is an architectual flaw, either in the template system or your classes or both.- Parameters:
tag
- the name of the html tag that will get processed- Returns:
- The template instance, if one exists.
-
substAttributeValues
public void substAttributeValues()
Substitute all attribute values.
-
-