nl.justobjects.toolkit.xml
Class Query

java.lang.Object
  |
  +--nl.justobjects.toolkit.xml.DefaultVisitor
        |
        +--nl.justobjects.toolkit.xml.Query
All Implemented Interfaces:
Visitor

public class Query
extends DefaultVisitor

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 $

Author:
$Author: just $ - Just van den Broecke - Just Objects B.V. ©

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
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

elementMatchers

java.util.Vector elementMatchers

result

java.util.Vector result

targetElement

org.w3c.dom.Element targetElement
Constructor Detail

Query

public Query(org.w3c.dom.Element theTargetElement)

Query

public Query(org.w3c.dom.Document theDocument)
Method Detail

setTarget

public void setTarget(org.w3c.dom.Element theTargetElement)

setTarget

public void setTarget(org.w3c.dom.Document theDocument)

resetMatchers

public void resetMatchers()

resetResult

public void resetResult()

reset

public void reset()

query

public java.util.Vector query()
Perform the actual query using the TreeWalker/Visitor.

addMatcherById

public void addMatcherById(java.lang.String id)
Add matcher for attribute id="xyz".

addMatcherByTag

public void addMatcherByTag(java.lang.String tag)
Add matcher for tag name.

addMatcherByAttributeName

public void addMatcherByAttributeName(java.lang.String name)
Add matcher for attribute name match.

addMatcherByAttributeNameAndValue

public void addMatcherByAttributeNameAndValue(java.lang.String name,
                                              java.lang.String value)
Add matcher for attribute N/V match.

addMatcherByAttributeNameAndValueStartsWith

public void addMatcherByAttributeNameAndValueStartsWith(java.lang.String name,
                                                        java.lang.String value)
Add matcher for attribute N/V match.

addMatcherByExample

public void addMatcherByExample(org.w3c.dom.Element element)
Add matcher providing an example Element.

addMatcherByNodeType

public void addMatcherByNodeType(short theNodeType)
Add matcher for Node type.

addMatcherByText

public void addMatcherByText(java.lang.String text)
Add matcher for text equal.

addMatcherByTextContains

public void addMatcherByTextContains(java.lang.String text)
Add matcher for text containing the string.

addMatcher

public void addMatcher(ElementMatcher elementMatcher)
Add custom matcher.

visitElementPost

public void visitElementPost(org.w3c.dom.Element element)
Callback from TreeWalker.
Overrides:
visitElementPost in class DefaultVisitor

addResult

protected void addResult(org.w3c.dom.Element element)
Add element to final result.

main

public static void main(java.lang.String[] args)


Copyright © 2000-2001 - Just Objects B.V.