public final class TagDispatcher extends Object implements TCDLParserEventListener
Tags are associated with a (chain of) TagHandlers OR tags can be parameters to methods of parent TagHandlers. So for example if you have nested tags in a tag:
Suppose the tag "parent" is handled by a class:
class ParentTagHandler implements TagHandler {
public void setNested(MyNestedObject object) { ::
public void setAttribute1(String value) { :: attribute1="value1" ... } ... }
The tag "nested" is mapped onto the method "setNested" (by name). The single parameter of this method indicates which object will be created (MyNestedObject) (using the default constructor or via a factory method defined on the class if it exists by the name createMyNestedObject).
class MyNestedObject { implements nothing specific to TCDL
public void addNested(MyNestedObject obj) { :: taglib:nested/taglib:nested/... list.add(obj); }
public void setRequiredAttr2(String value) { :: attr2="val2" ... }
public void setElementData(String tagBody) { :: >myNestedValue< ... } ... }
The element data of the "nested" tag, is set onto the MyNestedObject via a setElementData(string) method if it is present in the object. This process is recursive, e.g. another level of tags can be nested in the "nested" tags processed in the same way. To support multiple elements of the same name a method addNested can be used instead of setNested. This mechanism allows you to easily represent complex arguments for tags as POJOs.
A similar process occurs for attributes of tags: The attribute "attribute1" of the parent tag will be set via a method setAttribute1(String x) if the class ParentTagHandler has such a method. Similarly, the "attr2" attribute will be set on MyNestedObject if it defines a method called setAttr2(String val) or setRequiredAttr2(String val). Attributes are set immediately before doStartTag is called
Note that if a class defines methods in the form "setRequiredXXXX(..)", the engine checks that the attribute XXXX exists otherwise an error is thrown.
Note that when using nested tags as parameters the rules apply: - A parent must define a method either named set$TAGNAME(..) or add$TAGNAME(..) - The $TAGNAME may not have a registered TagHandler too. This will result in an error - Nested tags must be in the same namespace as their parents - The set$TAGNAME(..) or add$TAGNAME(..) is only called at the time the parent tag ends, just before doEndTag is called, so when these methods are called, the objects are fully initialized
Constructor and Description |
---|
TagDispatcher(TransformContext context,
OutputDocument target,
TagHandlerRegistry registry)
Constructs this TagDispatcher so it is ready for use as a TCDLParserEventListener with the TCDLParser
It is not re-usable, e.g.
|
Modifier and Type | Method and Description |
---|---|
boolean |
afterBody(Tag tag)
Called by the TCDLParser if body of a Tag require reevaluation.
|
protected void |
appendRenderedContentOf(TagDispatcher aDispatcher)
Appends data to the current body.
|
int |
calculateNameSpaces(Pattern pattern) |
void |
elementData(String data,
boolean directlyAfterTag)
Entry point called by TCDL parser for character data present between or before/after tcdl tags.
|
void |
endDocument()
Entry point called by TCDL parser right after finishing parsing the TCDL enabled content.
|
boolean |
endTag(Tag tag)
Entry point called by the TCDL Parser.
|
protected TagHandlerBase |
getEnclosingTagHandler()
Returns the TagHandler for the enclosing Tag of the currently active Tag in the processing Stack.
|
protected TagHandlerRegistry |
getRegistry()
Gets the cached TagHandlerRegistry.
|
protected boolean |
isSkippingMode()
Exposes if the parsing mechanism is currently skipping tags.
|
void |
startDocument()
Entry point called by the TCDL Parser just before it starts parsing
|
boolean |
startTag(Tag tag)
Entry point called by the TCDL Parser.
|
public TagDispatcher(TransformContext context, OutputDocument target, TagHandlerRegistry registry)
context
- An initialized TransformContext that will be used throughout the entire process.target
- The output document that will used throughout the entire process.registry
- Registry that will be used to look up TagHandlerspublic void startDocument() throws TCDLTransformerException
Prepare for processing by clearing the tagStack and pushing a default TagHandler onto it, that acts as the Root TagHandler surrounding the entire TCDL content.
startDocument
in interface TCDLParserEventListener
TCDLTransformerException
- if the processing cannot continue for some reason.TCDLTransformerException
public boolean startTag(Tag tag) throws TCDLTransformerException
startTag
in interface TCDLParserEventListener
tag
- Fully initialized tag as it is encountered by the parserTCDLTransformerException
- whenever an error occurs in processing the tagTCDLTransformerException
public boolean endTag(Tag tag) throws TCDLTransformerException
endTag
in interface TCDLParserEventListener
tag
- Fully initialized tag as it is encountered by the parser.
Note that it will not have the attributes of the start tag.TCDLTransformerException
- whenever an error occurs in processing the tagTCDLTransformerException
public void elementData(String data, boolean directlyAfterTag)
elementData
in interface TCDLParserEventListener
data
- the element data between tcdl tagsdirectlyAfterTag
- when true the parser found this data right after a valid tcdl tag. This helps deciding
if whitespace should be strippedpublic void endDocument() throws TCDLTransformerException
endDocument
in interface TCDLParserEventListener
TCDLTransformerException
- if the processing should not continue for some reason.TCDLTransformerException
protected TagHandlerBase getEnclosingTagHandler() throws TCDLTransformerException
In case of tag that does not contain any tag, it returns default tag handler. For iteration tag, it returns enclosing Tag's handler.
TCDLTransformerException
- If enclosing Tag does not support TagHandlerTCDLTransformerException
public int calculateNameSpaces(Pattern pattern)
public boolean afterBody(Tag tag) throws TCDLTransformerException
TCDLParserEventListener
afterBody
in interface TCDLParserEventListener
TCDLTransformerException
- if the processing should not continue for some reason.TCDLTransformerException
protected void appendRenderedContentOf(TagDispatcher aDispatcher) throws TCDLTransformerException
TCDLTransformerException
- Thrown if no current body is available.TCDLTransformerException
protected TagHandlerRegistry getRegistry()
protected boolean isSkippingMode() throws TCDLTransformerException
TCDLTransformerException
- Thrown if the there are no tags left on the stack.TCDLTransformerException
Copyright (c) 2014-2021 All Rights Reserved by the RWS Group for and on behalf of its affiliates and subsidiaries