org.jaxen.dom4j
Class DocumentNavigator

java.lang.Object
  extended by org.jaxen.DefaultNavigator
      extended by org.jaxen.dom4j.DocumentNavigator
All Implemented Interfaces:
Serializable, NamedAccessNavigator, Navigator

public class DocumentNavigator
extends DefaultNavigator
implements NamedAccessNavigator

Interface for navigating around the DOM4J object model.

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

Author:
bob mcwhirter, Stephen Colebourne
See Also:
XPath, Serialized Form

Constructor Summary
DocumentNavigator()
           
 
Method Summary
 Iterator getAttributeAxisIterator(Object contextNode)
          Throws UnsupportedAxisException.
 Iterator getAttributeAxisIterator(Object contextNode, String localName, String namespacePrefix, String namespaceURI)
          Retrieves an Iterator over the attribute elements that match the supplied name.
 String getAttributeName(Object obj)
          Retrieve the local name of the given attribute node.
 String getAttributeNamespaceUri(Object obj)
          Retrieve the namespace URI of the given attribute node.
 String getAttributeQName(Object obj)
          Retrieve the qualified name of the given attribute node.
 String getAttributeStringValue(Object obj)
          Retrieve the string-value of an attribute node.
 Iterator getChildAxisIterator(Object contextNode)
          Throws UnsupportedAxisException
 Iterator getChildAxisIterator(Object contextNode, String localName, String namespacePrefix, String namespaceURI)
          Retrieves an Iterator over the child elements that match the supplied name.
 String getCommentStringValue(Object obj)
          Retrieve the string-value of a comment node.
 Object getDocument(String uri)
          Default implementation that always returns null.
 Object getDocumentNode(Object contextNode)
          Returns the document node that contains the given context node.
 String getElementName(Object obj)
          Retrieve the local name of the given element node.
 String getElementNamespaceUri(Object obj)
          Retrieve the namespace URI of the given element node.
 String getElementQName(Object obj)
          Retrieve the qualified name of the given element node.
 String getElementStringValue(Object obj)
          Retrieve the string-value of an element node.
static Navigator getInstance()
          Retrieve the singleton instance of this DocumentNavigator.
 Iterator getNamespaceAxisIterator(Object contextNode)
          Throws UnsupportedAxisException.
 String getNamespacePrefix(Object obj)
          Retrieve the namespace prefix of a namespace node.
 String getNamespaceStringValue(Object obj)
          Retrieve the string-value of a namespace node.
 short getNodeType(Object node)
          Returns a number that identifies the type of node that the given object represents in this navigator.
 Iterator getParentAxisIterator(Object contextNode)
          Throws UnsupportedAxisException
 Object getParentNode(Object contextNode)
          Default inefficient implementation.
 String getProcessingInstructionData(Object obj)
          Retrieve the data of a processing-instruction.
 String getProcessingInstructionTarget(Object obj)
          Retrieve the target of a processing-instruction.
 org.dom4j.io.SAXReader getSAXReader()
           
 String getTextStringValue(Object obj)
          Retrieve the string-value of a text node.
 boolean isAttribute(Object obj)
          Returns whether the given object is an attribute node.
 boolean isComment(Object obj)
          Returns whether the given object is a comment node.
 boolean isDocument(Object obj)
          Returns whether the given object is a document node.
 boolean isElement(Object obj)
          Returns whether the given object is an element node.
 boolean isNamespace(Object obj)
          Returns whether the given object is a namespace node.
 boolean isProcessingInstruction(Object obj)
          Returns whether the given object is a processing-instruction node.
 boolean isText(Object obj)
          Returns whether the given object is a text node.
 XPath parseXPath(String xpath)
          Returns a parsed form of the given XPath string, which will be suitable for queries on DOM4J documents.
 void setSAXReader(org.dom4j.io.SAXReader reader)
           
 String translateNamespacePrefixToUri(String prefix, Object context)
          Translate a namespace prefix to a namespace URI, possibly considering a particular element node.
 
Methods inherited from class org.jaxen.DefaultNavigator
getAncestorAxisIterator, getAncestorOrSelfAxisIterator, getDescendantAxisIterator, getDescendantOrSelfAxisIterator, getElementById, getFollowingAxisIterator, getFollowingSiblingAxisIterator, getPrecedingAxisIterator, getPrecedingSiblingAxisIterator, getSelfAxisIterator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jaxen.Navigator
getAncestorAxisIterator, getAncestorOrSelfAxisIterator, getDescendantAxisIterator, getDescendantOrSelfAxisIterator, getElementById, getFollowingAxisIterator, getFollowingSiblingAxisIterator, getPrecedingAxisIterator, getPrecedingSiblingAxisIterator, getSelfAxisIterator
 

Constructor Detail

DocumentNavigator

public DocumentNavigator()
Method Detail

getInstance

public static Navigator getInstance()
Retrieve the singleton instance of this DocumentNavigator.


isElement

public boolean isElement(Object obj)
Description copied from interface: Navigator
Returns whether the given object is an element node.

Specified by:
isElement in interface Navigator
Parameters:
obj - the object to test
Returns:
true if the object is an element node, else false

isComment

public boolean isComment(Object obj)
Description copied from interface: Navigator
Returns whether the given object is a comment node.

Specified by:
isComment in interface Navigator
Parameters:
obj - the object to test
Returns:
true if the object is a comment node, else false

isText

public boolean isText(Object obj)
Description copied from interface: Navigator
Returns whether the given object is a text node.

Specified by:
isText in interface Navigator
Parameters:
obj - the object to test
Returns:
true if the object is a text node, else false

isAttribute

public boolean isAttribute(Object obj)
Description copied from interface: Navigator
Returns whether the given object is an attribute node.

Specified by:
isAttribute in interface Navigator
Parameters:
obj - the object to test
Returns:
true if the object is an attribute node, else false

isProcessingInstruction

public boolean isProcessingInstruction(Object obj)
Description copied from interface: Navigator
Returns whether the given object is a processing-instruction node.

Specified by:
isProcessingInstruction in interface Navigator
Parameters:
obj - the object to test
Returns:
true if the object is a processing-instruction node, else false

isDocument

public boolean isDocument(Object obj)
Description copied from interface: Navigator
Returns whether the given object is a document node. A document node is the node that is selected by the XPath expression /.

Specified by:
isDocument in interface Navigator
Parameters:
obj - the object to test
Returns:
true if the object is a document node, else false

isNamespace

public boolean isNamespace(Object obj)
Description copied from interface: Navigator
Returns whether the given object is a namespace node.

Specified by:
isNamespace in interface Navigator
Parameters:
obj - the object to test
Returns:
true if the object is a namespace node, else false

getElementName

public String getElementName(Object obj)
Description copied from interface: Navigator
Retrieve the local name of the given element node.

Specified by:
getElementName in interface Navigator
Parameters:
obj - the context element node
Returns:
the local name of the element node

getElementNamespaceUri

public String getElementNamespaceUri(Object obj)
Description copied from interface: Navigator
Retrieve the namespace URI of the given element node.

Specified by:
getElementNamespaceUri in interface Navigator
Parameters:
obj - the context element node
Returns:
the namespace URI of the element node

getElementQName

public String getElementQName(Object obj)
Description copied from interface: Navigator
Retrieve the qualified name of the given element node.

Specified by:
getElementQName in interface Navigator
Parameters:
obj - the context element node
Returns:
the qualified name of the element node

getAttributeName

public String getAttributeName(Object obj)
Description copied from interface: Navigator
Retrieve the local name of the given attribute node.

Specified by:
getAttributeName in interface Navigator
Parameters:
obj - the context attribute node
Returns:
the local name of the attribute node

getAttributeNamespaceUri

public String getAttributeNamespaceUri(Object obj)
Description copied from interface: Navigator
Retrieve the namespace URI of the given attribute node.

Specified by:
getAttributeNamespaceUri in interface Navigator
Parameters:
obj - the context attribute node
Returns:
the namespace URI of the attribute node

getAttributeQName

public String getAttributeQName(Object obj)
Description copied from interface: Navigator
Retrieve the qualified name of the given attribute node.

Specified by:
getAttributeQName in interface Navigator
Parameters:
obj - the context attribute node
Returns:
the qualified name of the attribute node

getChildAxisIterator

public Iterator getChildAxisIterator(Object contextNode)
Description copied from class: DefaultNavigator
Throws UnsupportedAxisException

Specified by:
getChildAxisIterator in interface Navigator
Overrides:
getChildAxisIterator in class DefaultNavigator
Parameters:
contextNode - the original context node
Returns:
never returns

getChildAxisIterator

public Iterator getChildAxisIterator(Object contextNode,
                                     String localName,
                                     String namespacePrefix,
                                     String namespaceURI)
Retrieves an Iterator over the child elements that match the supplied name.

Specified by:
getChildAxisIterator in interface NamedAccessNavigator
Parameters:
contextNode - the origin context node
localName - the local name of the children to return, always present
namespacePrefix - the prefix of the namespace of the children to return
namespaceURI - the uri of the namespace of the children to return
Returns:
an Iterator that traverses the named children, or null if none

getParentAxisIterator

public Iterator getParentAxisIterator(Object contextNode)
Description copied from class: DefaultNavigator
Throws UnsupportedAxisException

Specified by:
getParentAxisIterator in interface Navigator
Overrides:
getParentAxisIterator in class DefaultNavigator
Parameters:
contextNode - the original context node
Returns:
never returns

getAttributeAxisIterator

public Iterator getAttributeAxisIterator(Object contextNode)
Description copied from class: DefaultNavigator
Throws UnsupportedAxisException. Subclasses that support the attribute axis must override this method.

Specified by:
getAttributeAxisIterator in interface Navigator
Overrides:
getAttributeAxisIterator in class DefaultNavigator
Parameters:
contextNode - the original context node
Returns:
never returns

getAttributeAxisIterator

public Iterator getAttributeAxisIterator(Object contextNode,
                                         String localName,
                                         String namespacePrefix,
                                         String namespaceURI)
Retrieves an Iterator over the attribute elements that match the supplied name.

Specified by:
getAttributeAxisIterator in interface NamedAccessNavigator
Parameters:
contextNode - the origin context node
localName - the local name of the attributes to return, always present
namespacePrefix - the prefix of the namespace of the attributes to return
namespaceURI - the URI of the namespace of the attributes to return
Returns:
an Iterator that traverses the named attributes, not null

getNamespaceAxisIterator

public Iterator getNamespaceAxisIterator(Object contextNode)
Description copied from class: DefaultNavigator
Throws UnsupportedAxisException. Subclasses that support the namespace axis must override this method.

Specified by:
getNamespaceAxisIterator in interface Navigator
Overrides:
getNamespaceAxisIterator in class DefaultNavigator
Parameters:
contextNode - the original context node
Returns:
never returns

getDocumentNode

public Object getDocumentNode(Object contextNode)
Description copied from interface: Navigator
Returns the document node that contains the given context node.

Specified by:
getDocumentNode in interface Navigator
Overrides:
getDocumentNode in class DefaultNavigator
Parameters:
contextNode - the context node
Returns:
the document of the context node
See Also:
Navigator.isDocument(Object)

parseXPath

public XPath parseXPath(String xpath)
                 throws SAXPathException
Returns a parsed form of the given XPath string, which will be suitable for queries on DOM4J documents.

Specified by:
parseXPath in interface Navigator
Parameters:
xpath - the XPath expression
Returns:
a new XPath expression object
Throws:
SAXPathException - if the string is not a syntactically correct XPath expression
See Also:
XPath

getParentNode

public Object getParentNode(Object contextNode)
Description copied from class: DefaultNavigator
Default inefficient implementation. Subclasses should override this method.

Specified by:
getParentNode in interface Navigator
Overrides:
getParentNode in class DefaultNavigator
Parameters:
contextNode - the node whose parent to return
Returns:
the parent node
See Also:
Navigator.isDocument(java.lang.Object), Navigator.isElement(java.lang.Object)

getTextStringValue

public String getTextStringValue(Object obj)
Description copied from interface: Navigator
Retrieve the string-value of a text node. This must not be null and should not be the empty string. The XPath data model does not allow empty text nodes.

Specified by:
getTextStringValue in interface Navigator
Parameters:
obj - the text node
Returns:
the string-value of the node

getElementStringValue

public String getElementStringValue(Object obj)
Description copied from interface: Navigator
Retrieve the string-value of an element node. This may be the empty string if the element is empty, but must not be null.

Specified by:
getElementStringValue in interface Navigator
Parameters:
obj - the comment node.
Returns:
the string-value of the node.

getAttributeStringValue

public String getAttributeStringValue(Object obj)
Description copied from interface: Navigator
Retrieve the string-value of an attribute node. This should be the XML 1.0 normalized attribute value. This may be the empty string but must not be null.

Specified by:
getAttributeStringValue in interface Navigator
Parameters:
obj - the attribute node
Returns:
the string-value of the node

getNamespaceStringValue

public String getNamespaceStringValue(Object obj)
Description copied from interface: Navigator
Retrieve the string-value of a namespace node. This is generally the namespace URI. This may be the empty string but must not be null.

Specified by:
getNamespaceStringValue in interface Navigator
Parameters:
obj - the namespace node
Returns:
the string-value of the node

getNamespacePrefix

public String getNamespacePrefix(Object obj)
Description copied from interface: Navigator
Retrieve the namespace prefix of a namespace node.

Specified by:
getNamespacePrefix in interface Navigator
Parameters:
obj - the namespace node
Returns:
the prefix associated with the node

getCommentStringValue

public String getCommentStringValue(Object obj)
Description copied from interface: Navigator
Retrieve the string-value of a comment node. This may be the empty string if the comment is empty, but must not be null.

Specified by:
getCommentStringValue in interface Navigator
Parameters:
obj - the comment node
Returns:
the string-value of the node

translateNamespacePrefixToUri

public String translateNamespacePrefixToUri(String prefix,
                                            Object context)
Description copied from interface: Navigator
Translate a namespace prefix to a namespace URI, possibly considering a particular element node.

Strictly speaking, prefix-to-URI translation should occur irrespective of any element in the document. This method is provided to allow a non-conforming ease-of-use enhancement.

Specified by:
translateNamespacePrefixToUri in interface Navigator
Overrides:
translateNamespacePrefixToUri in class DefaultNavigator
Parameters:
prefix - the prefix to translate
context - the element to consider during translation
Returns:
the namespace URI associated with the prefix
See Also:
NamespaceContext

getNodeType

public short getNodeType(Object node)
Description copied from interface: Navigator
Returns a number that identifies the type of node that the given object represents in this navigator.

Specified by:
getNodeType in interface Navigator
Overrides:
getNodeType in class DefaultNavigator
Parameters:
node - ????
Returns:
????
See Also:
Pattern

getDocument

public Object getDocument(String uri)
                   throws FunctionCallException
Description copied from class: DefaultNavigator
Default implementation that always returns null. Override in subclass if the subclass can load documents.

Specified by:
getDocument in interface Navigator
Overrides:
getDocument in class DefaultNavigator
Parameters:
uri - the URL of the document to load
Returns:
null
Throws:
FunctionCallException - if an error occurs while loading the URL; e.g. an I/O error or the document is malformed

getProcessingInstructionTarget

public String getProcessingInstructionTarget(Object obj)
Description copied from interface: Navigator
Retrieve the target of a processing-instruction.

Specified by:
getProcessingInstructionTarget in interface Navigator
Overrides:
getProcessingInstructionTarget in class DefaultNavigator
Parameters:
obj - 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.

Specified by:
getProcessingInstructionData in interface Navigator
Overrides:
getProcessingInstructionData in class DefaultNavigator
Parameters:
obj - the context processing-instruction node
Returns:
the data of the processing-instruction node

getSAXReader

public org.dom4j.io.SAXReader getSAXReader()

setSAXReader

public void setSAXReader(org.dom4j.io.SAXReader reader)


Copyright © 2001-2008 Codehaus. All Rights Reserved.