|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--nl.justobjects.toolkit.xml.DefaultVisitor | +--nl.justobjects.toolkit.xml.Query
Implements queries on DOM trees.
This class is implemented using the Visitor and Strategy patterns. The Visitor pattern is used to traverse a DOM tree. The Strategy pattern is used to configure a series of "matchers" (interface ElementMatcher). As the DOM tree is visited each of the matchers is called. If all matchers match the visited element is added to the result vector. NB: currently there is no support for OR-ed matchers (to keep it simple). A query is done as follows (1) create a Query object using the target Document/Element, (2) add the matchers by calling query.addMatcherXYZ(args) (3) perform the query using query.query() $Id: Query.java,v 1.5 2003/01/06 00:23:49 just Exp $
Inner Class Summary | |
private static class |
Query.MatcherByAttributeName
|
private static class |
Query.MatcherByAttributeNameAndValue
|
private static class |
Query.MatcherByAttributeNameAndValueStartsWith
|
private static class |
Query.MatcherByExample
|
private static class |
Query.MatcherByNodeType
|
private static class |
Query.MatcherByTag
|
private static class |
Query.MatcherByText
|
private static class |
Query.MatcherByTextContains
|
Field Summary | |
(package private) java.util.Vector |
elementMatchers
|
(package private) java.util.Vector |
result
|
(package private) org.w3c.dom.Element |
targetElement
|
Constructor Summary | |
Query(org.w3c.dom.Document theDocument)
|
|
Query(org.w3c.dom.Element theTargetElement)
|
Method Summary | |
void |
addMatcher(ElementMatcher elementMatcher)
Add custom matcher. |
void |
addMatcherByAttributeName(java.lang.String name)
Add matcher for attribute name match. |
void |
addMatcherByAttributeNameAndValue(java.lang.String name,
java.lang.String value)
Add matcher for attribute N/V match. |
void |
addMatcherByAttributeNameAndValueStartsWith(java.lang.String name,
java.lang.String value)
Add matcher for attribute N/V match. |
void |
addMatcherByExample(org.w3c.dom.Element element)
Add matcher providing an example Element. |
void |
addMatcherById(java.lang.String id)
Add matcher for attribute id="xyz". |
void |
addMatcherByNodeType(short theNodeType)
Add matcher for Node type. |
void |
addMatcherByTag(java.lang.String tag)
Add matcher for tag name. |
void |
addMatcherByText(java.lang.String text)
Add matcher for text equal. |
void |
addMatcherByTextContains(java.lang.String text)
Add matcher for text containing the string. |
protected void |
addResult(org.w3c.dom.Element element)
Add element to final result. |
static void |
main(java.lang.String[] args)
|
java.util.Vector |
query()
Perform the actual query using the TreeWalker/Visitor. |
void |
reset()
|
void |
resetMatchers()
|
void |
resetResult()
|
void |
setTarget(org.w3c.dom.Document theDocument)
|
void |
setTarget(org.w3c.dom.Element theTargetElement)
|
void |
visitElementPost(org.w3c.dom.Element element)
Callback from TreeWalker. |
Methods inherited from class nl.justobjects.toolkit.xml.DefaultVisitor |
visitDocumentPost, visitDocumentPre, visitElementPre, visitText |
Methods inherited from class java.lang.Object |
|
Field Detail |
java.util.Vector elementMatchers
java.util.Vector result
org.w3c.dom.Element targetElement
Constructor Detail |
public Query(org.w3c.dom.Element theTargetElement)
public Query(org.w3c.dom.Document theDocument)
Method Detail |
public void setTarget(org.w3c.dom.Element theTargetElement)
public void setTarget(org.w3c.dom.Document theDocument)
public void resetMatchers()
public void resetResult()
public void reset()
public java.util.Vector query()
public void addMatcherById(java.lang.String id)
public void addMatcherByTag(java.lang.String tag)
public void addMatcherByAttributeName(java.lang.String name)
public void addMatcherByAttributeNameAndValue(java.lang.String name, java.lang.String value)
public void addMatcherByAttributeNameAndValueStartsWith(java.lang.String name, java.lang.String value)
public void addMatcherByExample(org.w3c.dom.Element element)
public void addMatcherByNodeType(short theNodeType)
public void addMatcherByText(java.lang.String text)
public void addMatcherByTextContains(java.lang.String text)
public void addMatcher(ElementMatcher elementMatcher)
public void visitElementPost(org.w3c.dom.Element element)
visitElementPost
in class DefaultVisitor
protected void addResult(org.w3c.dom.Element element)
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |