org.jaxen.dom
Class DocumentNavigator

java.lang.Object
  |
  +--org.jaxen.DefaultNavigator
        |
        +--org.jaxen.dom.DocumentNavigator
All Implemented Interfaces:
Navigator, Serializable

public class DocumentNavigator
extends DefaultNavigator

Interface for navigating around the W3C DOM Level 2 object model.

This class is not intended for direct usage, but is used by the Jaxen engine during evaluation.

This class implements the org.jaxen.DefaultNavigator interface for the Jaxen XPath library, version 1.0beta3 (it is not guaranteed to work with subsequent releases). This adapter allows the Jaxen library to be used to execute XPath queries against any object tree that implements the DOM level 2 interfaces.

Note: DOM level 2 does not include a node representing an XML Namespace declaration. This navigator will return Namespace decls as instantiations of the custom NamespaceNode class, and users will have to check result sets to locate and isolate these.

Author:
David Megginson, James Strachan
See Also:
XPath, NamespaceNode, Serialized Form

Constructor Summary
DocumentNavigator()
          Default Constructor.
 
Method Summary
 Iterator getAttributeAxisIterator(Object contextNode)
          Get an iterator over all attributes.
 String getAttributeName(Object object)
          Get the local name of an attribute.
 String getAttributeNamespaceUri(Object object)
          Get the Namespace URI of an attribute.
 String getAttributeQName(Object object)
          Get the qualified name of an attribute.
 String getAttributeStringValue(Object object)
          Get the string value of an attribute node.
 Iterator getChildAxisIterator(Object contextNode)
          Get an iterator over all of this node's children.
 String getCommentStringValue(Object object)
          Get the string value of a comment node.
 Object getDocument(String uri)
          Use JAXP to load a namespace aware document from a given URI
 Object getDocumentNode(Object contextNode)
          Get the top-level document node.
 Object getElementById(Object object, String elementId)
          Returns the element whose ID is given by elementId.
 String getElementName(Object object)
          Get the local name of an element.
 String getElementNamespaceUri(Object object)
          Get the Namespace URI of an element.
 String getElementQName(Object object)
          Get the qualified name of an element.
 String getElementStringValue(Object object)
          Get the string value of an element node.
 Iterator getFollowingAxisIterator(Object contextNode)
          Get an iterator over all following nodes, depth-first.
 Iterator getFollowingSiblingAxisIterator(Object contextNode)
          Get an iterator over all following siblings.
static DocumentNavigator getInstance()
          Get a singleton DocumentNavigator for efficiency.
 Iterator getNamespaceAxisIterator(Object contextNode)
          Get an iterator over all declared Namespaces.
 String getNamespacePrefix(Object object)
          Get the prefix value of a Namespace node.
 String getNamespaceStringValue(Object object)
          Get the string value of a Namespace node.
 Iterator getParentAxisIterator(Object contextNode)
          Get a (single-member) iterator over this node's parent.
 Iterator getPrecedingAxisIterator(Object contextNode)
          Get an iterator over all preceding nodes, depth-first.
 Iterator getPrecedingSiblingAxisIterator(Object contextNode)
          Get an iterator over all preceding siblings.
 String getProcessingInstructionData(Object obj)
          Retrieve the data of a processing-instruction.
 String getProcessingInstructionTarget(Object obj)
          Retrieve the target of a processing-instruction.
 String getTextStringValue(Object object)
          Get the string value of text.
 boolean isAttribute(Object object)
          Test if a node is an attribute.
 boolean isComment(Object object)
          Test if a node is a comment.
 boolean isDocument(Object object)
          Test if a node is a top-level document.
 boolean isElement(Object object)
          Test if a node is an element.
 boolean isNamespace(Object object)
          Test if a node is a Namespace.
 boolean isProcessingInstruction(Object object)
          Test if a node is a processing instruction.
 boolean isText(Object object)
          Test if a node is plain text.
 XPath parseXPath(String xpath)
          Returns a parsed form of the given xpath string, which will be suitable for queries on DOM documents.
 String translateNamespacePrefixToUri(String prefix, Object element)
          Translate a Namespace prefix to a URI.
 
Methods inherited from class org.jaxen.DefaultNavigator
getAncestorAxisIterator, getAncestorOrSelfAxisIterator, getDescendantAxisIterator, getDescendantOrSelfAxisIterator, getNodeType, getParentNode, getSelfAxisIterator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DocumentNavigator

public DocumentNavigator()
Default Constructor.
Method Detail

getInstance

public static DocumentNavigator getInstance()
Get a singleton DocumentNavigator for efficiency.
Returns:
A singleton instance of a DocumentNavigator.

getChildAxisIterator

public Iterator getChildAxisIterator(Object contextNode)
Get an iterator over all of this node's children.
Overrides:
getChildAxisIterator in class DefaultNavigator
Parameters:
contextNode - The context node for the child axis.
Returns:
A possibly-empty iterator (not null).

getParentAxisIterator

public Iterator getParentAxisIterator(Object contextNode)
Get a (single-member) iterator over this node's parent.
Overrides:
getParentAxisIterator in class DefaultNavigator
Parameters:
contextNode - the context node for the parent axis.
Returns:
A possibly-empty iterator (not null).

getFollowingSiblingAxisIterator

public Iterator getFollowingSiblingAxisIterator(Object contextNode)
Get an iterator over all following siblings.
Overrides:
getFollowingSiblingAxisIterator in class DefaultNavigator
Parameters:
contextNode - the context node for the sibling iterator.
Returns:
A possibly-empty iterator (not null).

getPrecedingSiblingAxisIterator

public Iterator getPrecedingSiblingAxisIterator(Object contextNode)
Get an iterator over all preceding siblings.
Overrides:
getPrecedingSiblingAxisIterator in class DefaultNavigator
Parameters:
contextNode - The context node for the preceding sibling axis.
Returns:
A possibly-empty iterator (not null).

getFollowingAxisIterator

public Iterator getFollowingAxisIterator(Object contextNode)
Get an iterator over all following nodes, depth-first.
Overrides:
getFollowingAxisIterator in class DefaultNavigator
Parameters:
contextNode - The context node for the following axis.
Returns:
A possibly-empty iterator (not null).

getPrecedingAxisIterator

public Iterator getPrecedingAxisIterator(Object contextNode)
Get an iterator over all preceding nodes, depth-first.
Overrides:
getPrecedingAxisIterator in class DefaultNavigator
Parameters:
contextNode - The context node for the preceding axis.
Returns:
A possibly-empty iterator (not null).

getAttributeAxisIterator

public Iterator getAttributeAxisIterator(Object contextNode)
Get an iterator over all attributes.
Overrides:
getAttributeAxisIterator in class DefaultNavigator
Parameters:
contextNode - The context node for the attribute axis.
Returns:
A possibly-empty iterator (not null).

getNamespaceAxisIterator

public Iterator getNamespaceAxisIterator(Object contextNode)
Get an iterator over all declared Namespaces.

Note: this iterator is not live: it takes a snapshot and that snapshot remains static during the life of the iterator (i.e. it won't reflect subsequent changes to the DOM).

Overrides:
getNamespaceAxisIterator in class DefaultNavigator
Parameters:
contextNode - The context node for the Namespace axis.
Returns:
A possibly-empty iterator (not null).

parseXPath

public XPath parseXPath(String xpath)
                 throws org.saxpath.SAXPathException
Returns a parsed form of the given xpath string, which will be suitable for queries on DOM documents.
Following copied from interface: org.jaxen.Navigator
Parameters:
xpath - The xpath expression.
Returns:
A new XPath expression object.
See Also:
XPath

getDocumentNode

public Object getDocumentNode(Object contextNode)
Get the top-level document node.
Overrides:
getDocumentNode in class DefaultNavigator
Parameters:
contextNode - Any node in the document.
Returns:
The root node.

getElementNamespaceUri

public String getElementNamespaceUri(Object object)
Get the Namespace URI of an element.
Parameters:
object - The target node.
Returns:
A string (possibly empty) if the node is an element, and null otherwise.

getElementName

public String getElementName(Object object)
Get the local name of an element.
Parameters:
object - The target node.
Returns:
A string representing the unqualified local name if the node is an element, or null otherwise.

getElementQName

public String getElementQName(Object object)
Get the qualified name of an element.
Parameters:
object - The target node.
Returns:
A string representing the qualified (i.e. possibly prefixed) name if the node is an element, or null otherwise.

getAttributeNamespaceUri

public String getAttributeNamespaceUri(Object object)
Get the Namespace URI of an attribute.
Parameters:
object - The target node.
A - possibly-empty string representing the Namespace URI if the node is an attribute, or null otherwise.

getAttributeName

public String getAttributeName(Object object)
Get the local name of an attribute.
Parameters:
object - The target node.
Returns:
A string representing the unqualified local name if the node is an attribute, or null otherwise.

getAttributeQName

public String getAttributeQName(Object object)
Get the qualified name of an attribute.
Parameters:
object - The target node.
Returns:
A string representing the qualified (i.e. possibly prefixed) name if the node is an attribute, or null otherwise.

isDocument

public boolean isDocument(Object object)
Test if a node is a top-level document.
Parameters:
object - The target node.
Returns:
true if the node is the document root, false otherwise.

isNamespace

public boolean isNamespace(Object object)
Test if a node is a Namespace.
Parameters:
object - The target node.
Returns:
true if the node is a Namespace, false otherwise.

isElement

public boolean isElement(Object object)
Test if a node is an element.
Parameters:
object - The target node.
Returns:
true if the node is an element, false otherwise.

isAttribute

public boolean isAttribute(Object object)
Test if a node is an attribute.
Parameters:
object - The target node.
Returns:
true if the node is an attribute, false otherwise.

isComment

public boolean isComment(Object object)
Test if a node is a comment.
Parameters:
object - The target node.
Returns:
true if the node is a comment, false otherwise.

isText

public boolean isText(Object object)
Test if a node is plain text.
Parameters:
object - The target node.
Returns:
true if the node is a text node, false otherwise.

isProcessingInstruction

public boolean isProcessingInstruction(Object object)
Test if a node is a processing instruction.
Parameters:
object - The target node.
Returns:
true if the node is a processing instruction, false otherwise.

getElementStringValue

public String getElementStringValue(Object object)
Get the string value of an element node.
Parameters:
object - The target node.
Returns:
The text inside the node and its descendants if the node is an element, null otherwise.

getAttributeStringValue

public String getAttributeStringValue(Object object)
Get the string value of an attribute node.
Parameters:
object - The target node.
Returns:
The text of the attribute value if the node is an attribute, null otherwise.

getTextStringValue

public String getTextStringValue(Object object)
Get the string value of text.
Parameters:
object - The target node.
Returns:
The string of text if the node is text, null otherwise.

getCommentStringValue

public String getCommentStringValue(Object object)
Get the string value of a comment node.
Parameters:
object - The target node.
Returns:
The text of the comment if the node is a comment, null otherwise.

getNamespaceStringValue

public String getNamespaceStringValue(Object object)
Get the string value of a Namespace node.
Parameters:
object - The target node.
Returns:
The Namespace URI as a (possibly empty) string if the node is a namespace node, null otherwise.

getNamespacePrefix

public String getNamespacePrefix(Object object)
Get the prefix value of a Namespace node.
Parameters:
object - The target node.
Returns:
The Namespace prefix a (possibly empty) string if the node is a namespace node, null otherwise.

translateNamespacePrefixToUri

public String translateNamespacePrefixToUri(String prefix,
                                            Object element)
Translate a Namespace prefix to a URI.
Overrides:
translateNamespacePrefixToUri in class DefaultNavigator
Following copied from interface: org.jaxen.Navigator
Parameters:
prefix - The prefix to translate.
element - The element to consider during translation.
Returns:
The namespace URI associated with the prefix.
See Also:
NamespaceContext

getDocument

public Object getDocument(String uri)
                   throws FunctionCallException
Use JAXP to load a namespace aware document from a given URI
Overrides:
getDocument in class DefaultNavigator
Parameters:
uri - is the URI of the document to load
Returns:
the new W3C DOM Level 2 Document instance
Throws:
FunctionCallException - containing a nested exception if a problem occurs trying to parse the given document

getProcessingInstructionTarget

public String getProcessingInstructionTarget(Object obj)
Description copied from interface: Navigator
Retrieve the target of a processing-instruction.
Overrides:
getProcessingInstructionTarget in class DefaultNavigator
Following copied from interface: org.jaxen.Navigator
Parameters:
pi - The context processing-instruction node.
Returns:
The target of the processing-instruction node.

getProcessingInstructionData

public String getProcessingInstructionData(Object obj)
Description copied from interface: Navigator
Retrieve the data of a processing-instruction.
Overrides:
getProcessingInstructionData in class DefaultNavigator
Following copied from interface: org.jaxen.Navigator
Parameters:
pi - The context processing-instruction node.
Returns:
The data of the processing-instruction node.

getElementById

public Object getElementById(Object object,
                             String elementId)
Returns the element whose ID is given by elementId. If no such element exists, returns null. Attributes with the name "ID" are not of type ID unless so defined. Atribute types are only known if when the parser understands DTD's or schemas that declare attributes of type ID. When JAXP is used, you must call setValidating(true) on the DocumentBuilderFactory.
Overrides:
getElementById in class DefaultNavigator
Parameters:
contextNode - a node from the document in which to look for the id
elementId - id to look for
Returns:
element whose ID is given by elementId, or null if no such element exists in the document or if the implementation does not know about attribute types
See Also:
DocumentBuilderFactory


Copyright © 2002 bob mcwhirter & James Strachan. All Rights Reserved. Hosted by

SourceForge Logo