public class DocumentNavigator extends DefaultNavigator
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.
XPath
,
NamespaceNode
,
Serialized FormModifier and Type | Class and Description |
---|---|
private static class |
DocumentNavigator.AttributeIterator
An iterator over an attribute list.
|
(package private) class |
DocumentNavigator.NodeIterator
A generic iterator over DOM nodes.
|
Modifier and Type | Field and Description |
---|---|
private static long |
serialVersionUID |
private static DocumentNavigator |
SINGLETON |
Constructor and Description |
---|
DocumentNavigator()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
java.util.Iterator |
getAttributeAxisIterator(java.lang.Object contextNode)
Get an iterator over all attributes.
|
java.lang.String |
getAttributeName(java.lang.Object attribute)
Get the local name of an attribute.
|
java.lang.String |
getAttributeNamespaceUri(java.lang.Object attribute)
Get the namespace URI of an attribute.
|
java.lang.String |
getAttributeQName(java.lang.Object attribute)
Get the qualified name of an attribute.
|
java.lang.String |
getAttributeStringValue(java.lang.Object object)
Get the string value of an attribute node.
|
java.util.Iterator |
getChildAxisIterator(java.lang.Object contextNode)
Get an iterator over all of this node's children.
|
java.lang.String |
getCommentStringValue(java.lang.Object object)
Get the string value of a comment node.
|
java.lang.Object |
getDocument(java.lang.String uri)
Use JAXP to load a namespace aware document from a given URI.
|
java.lang.Object |
getDocumentNode(java.lang.Object contextNode)
Get the top-level document node.
|
java.lang.Object |
getElementById(java.lang.Object object,
java.lang.String elementId)
Returns the element whose ID is given by elementId.
|
java.lang.String |
getElementName(java.lang.Object element)
Get the local name of an element.
|
java.lang.String |
getElementNamespaceUri(java.lang.Object element)
Get the namespace URI of an element.
|
java.lang.String |
getElementQName(java.lang.Object element)
Get the qualified name of an element.
|
java.lang.String |
getElementStringValue(java.lang.Object object)
Get the string value of an element node.
|
java.util.Iterator |
getFollowingAxisIterator(java.lang.Object contextNode)
Get an iterator over all following nodes, depth-first.
|
java.util.Iterator |
getFollowingSiblingAxisIterator(java.lang.Object contextNode)
Get an iterator over all following siblings.
|
static Navigator |
getInstance()
Get a constant DocumentNavigator for efficiency.
|
java.util.Iterator |
getNamespaceAxisIterator(java.lang.Object contextNode)
Get an iterator over all declared namespaces.
|
java.lang.String |
getNamespacePrefix(java.lang.Object object)
Get the prefix value of a namespace node.
|
java.lang.String |
getNamespaceStringValue(java.lang.Object object)
Get the string value of a namespace node.
|
java.util.Iterator |
getParentAxisIterator(java.lang.Object contextNode)
Get a (single-member) iterator over this node's parent.
|
java.lang.Object |
getParentNode(java.lang.Object child)
Return the XPath parent of the supplied DOM node.
|
java.util.Iterator |
getPrecedingSiblingAxisIterator(java.lang.Object contextNode)
Get an iterator over all preceding siblings.
|
java.lang.String |
getProcessingInstructionData(java.lang.Object obj)
Get the data of a processing instruction node.
|
java.lang.String |
getProcessingInstructionTarget(java.lang.Object obj)
Get the target of a processing instruction node.
|
private java.lang.StringBuffer |
getStringValue(org.w3c.dom.Node node,
java.lang.StringBuffer buffer)
Construct a node's string value recursively.
|
java.lang.String |
getTextStringValue(java.lang.Object object)
Get the string value of text.
|
boolean |
isAttribute(java.lang.Object object)
Test if a node is an attribute.
|
boolean |
isComment(java.lang.Object object)
Test if a node is a comment.
|
boolean |
isDocument(java.lang.Object object)
Test if a node is a top-level document.
|
boolean |
isElement(java.lang.Object object)
Test if a node is an element.
|
boolean |
isNamespace(java.lang.Object object)
Test if a node is a namespace.
|
boolean |
isProcessingInstruction(java.lang.Object object)
Test if a node is a processing instruction.
|
boolean |
isText(java.lang.Object object)
Test if a node is plain text.
|
XPath |
parseXPath(java.lang.String xpath)
Returns a parsed form of the given XPath string, which will be suitable
for queries on DOM documents.
|
java.lang.String |
translateNamespacePrefixToUri(java.lang.String prefix,
java.lang.Object element)
Translate a namespace prefix to a URI.
|
getAncestorAxisIterator, getAncestorOrSelfAxisIterator, getDescendantAxisIterator, getDescendantOrSelfAxisIterator, getNodeType, getPrecedingAxisIterator, getSelfAxisIterator
private static final long serialVersionUID
private static final DocumentNavigator SINGLETON
public static Navigator getInstance()
public java.util.Iterator getChildAxisIterator(java.lang.Object contextNode)
getChildAxisIterator
in interface Navigator
getChildAxisIterator
in class DefaultNavigator
contextNode
- the context node for the child axis.public java.util.Iterator getParentAxisIterator(java.lang.Object contextNode)
getParentAxisIterator
in interface Navigator
getParentAxisIterator
in class DefaultNavigator
contextNode
- the context node for the parent axispublic java.lang.Object getParentNode(java.lang.Object child)
getParentNode
in interface Navigator
getParentNode
in class DefaultNavigator
child
- the child nodeNavigator.isDocument(java.lang.Object)
,
Navigator.isElement(java.lang.Object)
public java.util.Iterator getFollowingSiblingAxisIterator(java.lang.Object contextNode)
getFollowingSiblingAxisIterator
in interface Navigator
getFollowingSiblingAxisIterator
in class DefaultNavigator
contextNode
- the context node for the sibling iteratorpublic java.util.Iterator getPrecedingSiblingAxisIterator(java.lang.Object contextNode)
getPrecedingSiblingAxisIterator
in interface Navigator
getPrecedingSiblingAxisIterator
in class DefaultNavigator
contextNode
- the context node for the preceding sibling axispublic java.util.Iterator getFollowingAxisIterator(java.lang.Object contextNode)
getFollowingAxisIterator
in interface Navigator
getFollowingAxisIterator
in class DefaultNavigator
contextNode
- the context node for the following axispublic java.util.Iterator getAttributeAxisIterator(java.lang.Object contextNode)
getAttributeAxisIterator
in interface Navigator
getAttributeAxisIterator
in class DefaultNavigator
contextNode
- the context node for the attribute axispublic java.util.Iterator getNamespaceAxisIterator(java.lang.Object contextNode)
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:foo
element is declared by DOM to be in the
http://www.a.com/ namespace but also has an
xmlns:pre="http://www.b.com"
attribute; then only
one of the namespaces will be counted. This will be the intrinsic
namespace of the Element
or Attr
object
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:foo
in the
http://www.a.com/ namespace and pre:bar
in the
http://www.b.com/ namespace--it is undefined which namespace
will be returned.
getNamespaceAxisIterator
in interface Navigator
getNamespaceAxisIterator
in class DefaultNavigator
contextNode
- the context node for the namespace axispublic XPath parseXPath(java.lang.String xpath) throws SAXPathException
xpath
- the XPath expressionSAXPathException
- if the string is syntactically incorrectXPath
public java.lang.Object getDocumentNode(java.lang.Object contextNode)
getDocumentNode
in interface Navigator
getDocumentNode
in class DefaultNavigator
contextNode
- any node in the documentNavigator.isDocument(Object)
public java.lang.String getElementNamespaceUri(java.lang.Object element)
element
- the target nodepublic java.lang.String getElementName(java.lang.Object element)
element
- the target nodepublic java.lang.String getElementQName(java.lang.Object element)
element
- the target nodepublic java.lang.String getAttributeNamespaceUri(java.lang.Object attribute)
attribute
- the target nodepublic java.lang.String getAttributeName(java.lang.Object attribute)
attribute
- the target nodepublic java.lang.String getAttributeQName(java.lang.Object attribute)
attribute
- the target nodepublic boolean isDocument(java.lang.Object object)
object
- the target nodepublic boolean isNamespace(java.lang.Object object)
object
- the target nodepublic boolean isElement(java.lang.Object object)
object
- the target nodepublic boolean isAttribute(java.lang.Object object)
xmlns
and
xmlns:pre
attributes do not count as attributes
for the purposes of XPath.object
- the target nodepublic boolean isComment(java.lang.Object object)
object
- the target nodepublic boolean isText(java.lang.Object object)
object
- the target nodepublic boolean isProcessingInstruction(java.lang.Object object)
object
- the target nodepublic java.lang.String getElementStringValue(java.lang.Object object)
object
- the target nodeprivate java.lang.StringBuffer getStringValue(org.w3c.dom.Node node, java.lang.StringBuffer buffer)
node
- the current nodebuffer
- the buffer for building the textpublic java.lang.String getAttributeStringValue(java.lang.Object object)
object
- the target nodepublic java.lang.String getTextStringValue(java.lang.Object object)
object
- the target nodepublic java.lang.String getCommentStringValue(java.lang.Object object)
object
- the target nodepublic java.lang.String getNamespaceStringValue(java.lang.Object object)
object
- the target nodepublic java.lang.String getNamespacePrefix(java.lang.Object object)
object
- the target nodepublic java.lang.String translateNamespacePrefixToUri(java.lang.String prefix, java.lang.Object element)
translateNamespacePrefixToUri
in interface Navigator
translateNamespacePrefixToUri
in class DefaultNavigator
prefix
- the namespace prefixelement
- the namespace contextelement
;
null if the prefix is not boundNamespaceContext
public java.lang.Object getDocument(java.lang.String uri) throws FunctionCallException
getDocument
in interface Navigator
getDocument
in class DefaultNavigator
uri
- the URI of the document to loadFunctionCallException
- containing a nested exception
if a problem occurs trying to parse the given documentpublic java.lang.String getProcessingInstructionTarget(java.lang.Object obj)
getProcessingInstructionTarget
in interface Navigator
getProcessingInstructionTarget
in class DefaultNavigator
obj
- the processing instructionjava.lang.ClassCastException
- if obj is not a processing instructionpublic java.lang.String getProcessingInstructionData(java.lang.Object obj)
getProcessingInstructionData
in interface Navigator
getProcessingInstructionData
in class DefaultNavigator
obj
- the processing instructionjava.lang.ClassCastException
- if obj is not a processing instructionpublic java.lang.Object getElementById(java.lang.Object object, java.lang.String elementId)
setValidating(true)
on the
DocumentBuilderFactory.getElementById
in interface Navigator
getElementById
in class DefaultNavigator
object
- a node from the document in which to look for the idelementId
- id to look forjava.lang.ClassCastException
- if object is not an org.w3c.dom.Node
objectDocumentBuilderFactory