Class DocumentNavigator
- All Implemented Interfaces:
Serializable, Navigator
This class is not intended for direct usage, but is used by the Jaxen engine during evaluation.
This class implements the DefaultNavigator interface
for the Jaxen XPath library. 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 XPath
namespace node. This navigator will return namespace nodes
as instances of the custom NamespaceNode class, and
users will have to check result sets to locate and isolate
these.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classAn iterator over an attribute list.(package private) classA generic iterator over DOM nodes. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final longprivate static final DocumentNavigator -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetAttributeAxisIterator(Object contextNode) Get an iterator over all attributes.getAttributeName(Object attribute) Get the local name of an attribute.getAttributeNamespaceUri(Object attribute) Get the namespace URI of an attribute.getAttributeQName(Object attribute) Get the qualified name of an attribute.getAttributeStringValue(Object object) Get the string value of an attribute node.getChildAxisIterator(Object contextNode) Get an iterator over all of this node's children.getCommentStringValue(Object object) Get the string value of a comment node.getDocument(String uri) Use JAXP to load a namespace aware document from a given URI.getDocumentNode(Object contextNode) Get the top-level document node.getElementById(Object object, String elementId) Returns the element whose ID is given by elementId.getElementName(Object element) Get the local name of an element.getElementNamespaceUri(Object element) Get the namespace URI of an element.getElementQName(Object element) Get the qualified name of an element.getElementStringValue(Object object) Get the string value of an element node.getFollowingAxisIterator(Object contextNode) Get an iterator over all following nodes, depth-first.getFollowingSiblingAxisIterator(Object contextNode) Get an iterator over all following siblings.static NavigatorGet a constant DocumentNavigator for efficiency.getNamespaceAxisIterator(Object contextNode) Get an iterator over all declared namespaces.getNamespacePrefix(Object object) Get the prefix value of a namespace node.getNamespaceStringValue(Object object) Get the string value of a namespace node.getParentAxisIterator(Object contextNode) Get a (single-member) iterator over this node's parent.getParentNode(Object child) Return the XPath parent of the supplied DOM node.getPrecedingSiblingAxisIterator(Object contextNode) Get an iterator over all preceding siblings.Get the data of a processing instruction node.Get the target of a processing instruction node.private StringBuffergetStringValue(Node node, StringBuffer buffer) Construct a node's string value recursively.getTextStringValue(Object object) Get the string value of text.booleanisAttribute(Object object) Test if a node is an attribute.booleanTest if a node is a comment.booleanisDocument(Object object) Test if a node is a top-level document.booleanTest if a node is an element.booleanisNamespace(Object object) Test if a node is a namespace.booleanisProcessingInstruction(Object object) Test if a node is a processing instruction.booleanTest if a node is plain text.parseXPath(String xpath) Returns a parsed form of the given XPath string, which will be suitable for queries on DOM documents.translateNamespacePrefixToUri(String prefix, Object element) Translate a namespace prefix to a URI.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
SINGLETON
-
-
Constructor Details
-
DocumentNavigator
public DocumentNavigator()Default constructor.
-
-
Method Details
-
getInstance
Get a constant DocumentNavigator for efficiency.- Returns:
- a constant instance of a DocumentNavigator.
-
getChildAxisIterator
Get an iterator over all of this node's children.- Specified by:
getChildAxisIteratorin interfaceNavigator- Overrides:
getChildAxisIteratorin classDefaultNavigator- Parameters:
contextNode- the context node for the child axis.- Returns:
- a possibly-empty iterator (not null)
-
getParentAxisIterator
Get a (single-member) iterator over this node's parent.- Specified by:
getParentAxisIteratorin interfaceNavigator- Overrides:
getParentAxisIteratorin classDefaultNavigator- Parameters:
contextNode- the context node for the parent axis- Returns:
- a possibly-empty iterator (not null)
-
getParentNode
Return the XPath parent of the supplied DOM node. XPath has slightly different definition of parent than DOM does. In particular, the parent of an attribute is not null.- Specified by:
getParentNodein interfaceNavigator- Overrides:
getParentNodein classDefaultNavigator- Parameters:
child- the child node- Returns:
- the parent of the specified node; or null if the node does not have a parent
- See Also:
-
getFollowingSiblingAxisIterator
Get an iterator over all following siblings.- Specified by:
getFollowingSiblingAxisIteratorin interfaceNavigator- Overrides:
getFollowingSiblingAxisIteratorin classDefaultNavigator- Parameters:
contextNode- the context node for the sibling iterator- Returns:
- a possibly-empty iterator (not null)
-
getPrecedingSiblingAxisIterator
Get an iterator over all preceding siblings.- Specified by:
getPrecedingSiblingAxisIteratorin interfaceNavigator- Overrides:
getPrecedingSiblingAxisIteratorin classDefaultNavigator- Parameters:
contextNode- the context node for the preceding sibling axis- Returns:
- a possibly-empty iterator (not null)
-
getFollowingAxisIterator
Get an iterator over all following nodes, depth-first.- Specified by:
getFollowingAxisIteratorin interfaceNavigator- Overrides:
getFollowingAxisIteratorin classDefaultNavigator- Parameters:
contextNode- the context node for the following axis- Returns:
- a possibly-empty iterator (not null)
-
getAttributeAxisIterator
Get an iterator over all attributes.- Specified by:
getAttributeAxisIteratorin interfaceNavigator- Overrides:
getAttributeAxisIteratorin classDefaultNavigator- Parameters:
contextNode- the context node for the attribute axis- Returns:
- a possibly-empty iterator (not null)
-
getNamespaceAxisIterator
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).
In the event that the DOM is inconsistent; for instance a
pre:fooelement is declared by DOM to be in the http://www.a.com/ namespace but also has anxmlns:pre="http://www.b.com"attribute; then only one of the namespaces will be counted. This will be the intrinsic namespace of theElementorAttrobject rather than the one provide by the contradictory namespace declaration attribute. In the event of a contradiction between two attributes on the same element--e.g.pre:fooin the http://www.a.com/ namespace andpre:barin the http://www.b.com/ namespace--it is undefined which namespace will be returned.- Specified by:
getNamespaceAxisIteratorin interfaceNavigator- Overrides:
getNamespaceAxisIteratorin classDefaultNavigator- Parameters:
contextNode- the context node for the namespace axis- Returns:
- a possibly-empty iterator (not null)
-
parseXPath
Returns a parsed form of the given XPath string, which will be suitable for queries on DOM documents.- Parameters:
xpath- the XPath expression- Returns:
- a parsed form of the given XPath string
- Throws:
SAXPathException- if the string is syntactically incorrect- See Also:
-
getDocumentNode
Get the top-level document node.- Specified by:
getDocumentNodein interfaceNavigator- Overrides:
getDocumentNodein classDefaultNavigator- Parameters:
contextNode- any node in the document- Returns:
- the root node
- See Also:
-
getElementNamespaceUri
-
getElementName
-
getElementQName
-
getAttributeNamespaceUri
-
getAttributeName
-
getAttributeQName
-
isDocument
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
Test if a node is a namespace.- Parameters:
object- the target node- Returns:
- true if the node is a namespace, false otherwise
-
isElement
Test if a node is an element.- Parameters:
object- the target node- Returns:
- true if the node is an element, false otherwise
-
isAttribute
Test if a node is an attribute.xmlnsandxmlns:preattributes do not count as attributes for the purposes of XPath.- Parameters:
object- the target node- Returns:
- true if the node is an attribute, false otherwise
-
isComment
Test if a node is a comment.- Parameters:
object- the target node- Returns:
- true if the node is a comment, false otherwise
-
isText
Test if a node is plain text.- Parameters:
object- the target node- Returns:
- true if the node is a text node, false otherwise
-
isProcessingInstruction
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
-
getStringValue
Construct a node's string value recursively.- Parameters:
node- the current nodebuffer- the buffer for building the text- Returns:
- the buffer passed as a parameter (for convenience)
-
getAttributeStringValue
-
getTextStringValue
-
getCommentStringValue
-
getNamespaceStringValue
-
getNamespacePrefix
-
translateNamespacePrefixToUri
Translate a namespace prefix to a URI.- Specified by:
translateNamespacePrefixToUriin interfaceNavigator- Overrides:
translateNamespacePrefixToUriin classDefaultNavigator- Parameters:
prefix- the namespace prefixelement- the namespace context- Returns:
- the namespace URI bound to the prefix in the scope of
element; null if the prefix is not bound - See Also:
-
getDocument
Use JAXP to load a namespace aware document from a given URI.- Specified by:
getDocumentin interfaceNavigator- Overrides:
getDocumentin classDefaultNavigator- Parameters:
uri- 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
Get the target of a processing instruction node.- Specified by:
getProcessingInstructionTargetin interfaceNavigator- Overrides:
getProcessingInstructionTargetin classDefaultNavigator- Parameters:
obj- the processing instruction- Returns:
- the target of the processing instruction
- Throws:
ClassCastException- if obj is not a processing instruction
-
getProcessingInstructionData
Get the data of a processing instruction node.- Specified by:
getProcessingInstructionDatain interfaceNavigator- Overrides:
getProcessingInstructionDatain classDefaultNavigator- Parameters:
obj- the processing instruction- Returns:
- the target of the processing instruction
- Throws:
ClassCastException- if obj is not a processing instruction
-
getElementById
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. Attribute 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 callsetValidating(true)on the DocumentBuilderFactory.- Specified by:
getElementByIdin interfaceNavigator- Overrides:
getElementByIdin classDefaultNavigator- Parameters:
object- a node from the document in which to look for the idelementId- 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
- Throws:
ClassCastException- if object is not anorg.w3c.dom.Nodeobject- See Also:
-