public abstract class AbstractProxyTagNodeVisitor extends Object implements TagNodeVisitor
TagNodeVisitor
class
which can be extended simply by implementing the link rewriting method only
(rewriteURI(String, String, String)
).
This abstract class is provided to help developers implement TagNodeVisitor
s
more easily with a simple link rewriting capability which is very common in
reverse proxy modules.
This class is constructed with a map constructor argument, Map<String,String[]> tagNameAndLinkAttrs
,
which should contain entries of tag name and link attribute names array of the tag.
For example, an HTML <a /> tag typically may contain an href
attribute for
the link information. e.g, <a href="http://portals.apache.org">Apache Portals</a>.
If you want to rewrite the link string contained in the href
attribute of the
<a /> tag, then the map constructor argument should contain a key-value pair entry (the tag name
: link attribute names array): { "a" : [ "href" ] }.
Then this class will invoke rewriteURI(String, String, String)
for each link attribute
whenever it visits a <a /> tag.
Constructor and Description |
---|
AbstractProxyTagNodeVisitor(Map<String,String[]> tagNameAndLinkAttrs)
Construct a AbstractProxyTagNodeVisitor from the map of
the link element tag name (e.g, "a" or "img") and its link attributes (e.g, [ "href" ] or [ "src" ]).
|
Modifier and Type | Method and Description |
---|---|
protected abstract String |
rewriteURI(String tagName,
String attrName,
String uri)
The method which should rewrite the original link URI string to a new link URI to return if necessary.
|
boolean |
visit(TagNode parentNode,
HtmlNode htmlNode) |
protected boolean |
visitCommentNode(TagNode parentNode,
CommentNode comment)
Default implementation of handling visited
CommentNode s. |
protected boolean |
visitTagNode(TagNode parentNode,
TagNode tag)
Default implementation of handling visited
TagNode s. |
public boolean visit(TagNode parentNode, HtmlNode htmlNode)
This method checks the type of the current htmlNode
and it invokes visitTagNode(TagNode, TagNode)
if the current htmlNode
is instance of TagNode
, or invokes visitCommentNode(TagNode, CommentNode)
if the current htmlNode
is instance of CommentNode
.
visit
in interface TagNodeVisitor
protected boolean visitTagNode(TagNode parentNode, TagNode tag)
TagNode
s.
This method checks if the tag name was registered to be handled to rewrite the link attributes.
If it is registered through the constructor, then it retrieves the attribute names array by the
tag name. For each attribute, it invokes rewriteURI(String, String, String)
method
to translate the link URI.
If rewriteURI(String, String, String)
returns a different string than the original
link URI string, then it updates the link attributes by the newly rewritten link URI string.
parentNode
- tag
- protected boolean visitCommentNode(TagNode parentNode, CommentNode comment)
CommentNode
s.
This does nothing but simply returns true by default.
parentNode
- comment
- protected abstract String rewriteURI(String tagName, String attrName, String uri)
tagName
- the tag name holding the linkattrName
- the attribute name of the tag node holding the linkuri
- the original link URI stringCopyright © 2008–2015 The Apache Software Foundation. All rights reserved.