Interface MetadataNode
-
- All Known Subinterfaces:
MutableMetadataNode
public interface MetadataNodeThe MetadataNodes represents a node in an XML-based metadata-document. In contrast to the W3C DOM-API it allows for easy and convenient use by providing easy to use methods for access, navigation, evaluation and conversion.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description MetadataNodecreateNamespaceContext()Create a facade node which allows a new mapping of namespace prefixes to be used to navigate and query nodes without changing the base document.BooleanevalToBoolean(String relativeXpath, Object... arguments)Evaluate the given XPath expression against the current node and return the result as a Boolean.NodeevalToNode(String relativeXpath, Object... arguments)Evaluate the given XPath expression against the current node and return the result as a Node.NodeListevalToNodeSet(String relativeXpath, Object... arguments)Evaluate the given XPath expression against the current node and return the result as a NodeList.NumberevalToNumber(String relativeXpath, Object... arguments)Evaluate the given XPath expression against the current node and return the result as a Number.StringevalToString(String relativeXpath, Object... arguments)Evaluate the given XPath expression against the current node and return the result as a String.StringfindAttribute(String name)returns the attribute value of the current node or null if the attribute does not existStringfindAttribute(String name, String relativeXpath, Object... arguments)Returns the attribute value of the node pointed by given XPath expression or null if the attribute does not existStringgetAttribute(String name)returns the attribute value of the current nodeStringgetAttribute(String name, String relativeXpath, Object... arguments)Returns the attribute value of the node pointed by given XPath expressionString[]getAttributeNames()StringgetCDATA()intgetChildCount()List<? extends MetadataNode>getChildren()Return a list of all child nodes.List<? extends MetadataNode>getChildren(String relativeXpath, Object... arguments)Return a list of all nodes selected by the XPath expression.MetadatagetDocument()Return the meta-data document to which this node belongs.ElementgetElement()StringgetEncoding()MetadataNodegetInnerDocument()StringgetInnerText()StringgetLocation()StringgetName()StringgetPrefix(String namespaceURI)Get the prefix of a namespace identified by its URI.String[]getPrefixes(String namespaceURI)Get all bound prefixes of a namespace identified by its URI.StringgetText()StringgetText(String relativeXpath, Object... arguments)Get the text content of the node addressed by the XPath.StringgetTextOrCDATA()StringgetTextOrCDATA(String relativeXpath, Object... arguments)Get the text content of the node addressed by the XPath.MetadataNodegotoChild()Go to the only child element of the current node.MetadataNodegotoChild(int i)Go to the Nth child of the curent node.MetadataNodegotoChild(String nodeName)Go to the child found with given node nameMetadataNodegotoFirstChild()Go to the first child element of the current node.MetadataNodegotoFirstChild(String name)Go to the first child with the given nameMetadataNodegotoLastChild()Go to the last child element of the current node.MetadataNodegotoLastChild(String name)Go to the last child with the given nameMetadataNodegotoParent()Go to parent tag.MetadataNodegotoRoot()Go to document root tagMetadataNodegotoTag(String relativeXpath, Object... arguments)Go to a specific nodebooleanhasAttribute(String name)Check whether current tag contains the attribute with the given name.booleanhasAttribute(String name, String relativeXpath, Object... arguments)Check whether the node addressed by the XPath contains the attribute with the given name.booleanhasNode(String relativeXpath, Object... arguments)Check if the node addressed by the XPath exists in the document.
-
-
-
Method Detail
-
findAttribute
String findAttribute(String name)
returns the attribute value of the current node or null if the attribute does not exist- Parameters:
name- attribute name- Returns:
- attribute value or null if no attribute
-
findAttribute
String findAttribute(String name, String relativeXpath, Object... arguments) throws MetadataException
Returns the attribute value of the node pointed by given XPath expression or null if the attribute does not exist- Parameters:
name- attribute namerelativeXpath- XPath expressionarguments- optional XPath expression arguments. Uses String.format() to build XPath expression.- Returns:
- the attribute value or null if the attribute does not exist
- Throws:
MetadataException- targeted node does not exist or XPath expression is invalid
-
getAttribute
String getAttribute(String name) throws MetadataException
returns the attribute value of the current node- Parameters:
name- attribute name- Returns:
- attribute value
- Throws:
MetadataException- If the attribute does not exist
-
getAttribute
String getAttribute(String name, String relativeXpath, Object... arguments) throws MetadataException
Returns the attribute value of the node pointed by given XPath expression- Parameters:
name- attribute namerelativeXpath- XPath expressionarguments- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- attribute value
- Throws:
MetadataException- Attribute does not exist, targetted node or XPath expression is invalid
-
getAttributeNames
String[] getAttributeNames()
- Returns:
- all attribute names of current node
-
getCDATA
String getCDATA()
- Returns:
- The CDATA content of the current node, "" if none
-
getChildCount
int getChildCount()
- Returns:
- The number of child for the current tag
-
getChildren
List<? extends MetadataNode> getChildren()
Return a list of all child nodes.- Returns:
- The list
-
getChildren
List<? extends MetadataNode> getChildren(String relativeXpath, Object... arguments)
Return a list of all nodes selected by the XPath expression.- Parameters:
relativeXpath- XPath to select tagsarguments- XPath arguments- Returns:
- The list
-
getDocument
Metadata getDocument()
Return the meta-data document to which this node belongs.
-
getElement
Element getElement()
- Returns:
- the current tag
-
getLocation
String getLocation()
- Returns:
- An XPath expression representing the current tag location in the document. If you are in the root node and run gotoTag() giving this XPath expression, you will return to the current node.
-
getName
String getName()
- Returns:
- the current tag name
-
getInnerDocument
MetadataNode getInnerDocument()
- Returns:
- Another node instance in which the current node becomes the root element of the new document, and it contains all inner elements as in the previous document.
-
getInnerText
String getInnerText()
- Returns:
- The text representation of the inner nodes of the current node. The current node is used as as the root element of inner tags.
-
getPrefix
String getPrefix(String namespaceURI)
Get the prefix of a namespace identified by its URI.- Parameters:
namespaceURI- The URI of the namespace- Returns:
- the prefix or "" if not found ("" is the default prefix - see
javadoc)
-
getPrefixes
String[] getPrefixes(String namespaceURI)
Get all bound prefixes of a namespace identified by its URI.- Parameters:
namespaceURI- The URI of the namespace- Returns:
- a list of prefixes or an empty array.
-
getText
String getText()
- Returns:
- The text content of the current node, "" if none
-
getText
String getText(String relativeXpath, Object... arguments) throws MetadataException
Get the text content of the node addressed by the XPath.- Parameters:
relativeXpath- XPath expression that select the nodearguments- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- the text of "" if none
- Throws:
MetadataException- If the XPath expression is not valid or if the node does not exist
-
getTextOrCDATA
String getTextOrCDATA()
- Returns:
- The text content of the current node, if none tries to get the CDATA content, if none returns ""
-
getTextOrCDATA
String getTextOrCDATA(String relativeXpath, Object... arguments) throws MetadataException
Get the text content of the node addressed by the XPath.- Parameters:
relativeXpath- XPath expression that select the nodearguments- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- The text content of the current node, if none tries to get the CDATA content, if none returns ""
- Throws:
MetadataException- If the XPath expression is not valid or if the node does not exist
-
hasAttribute
boolean hasAttribute(String name)
Check whether current tag contains the attribute with the given name.- Parameters:
name- Attribute name- Returns:
- true if the attribute is in current tag
-
hasAttribute
boolean hasAttribute(String name, String relativeXpath, Object... arguments) throws MetadataException
Check whether the node addressed by the XPath contains the attribute with the given name.- Parameters:
name- the name of the attributerelativeXpath- XPath that target the tagarguments- optional arguments of xpath expression. Uses String.format() to build XPath expression.- Returns:
- true if the tag exist with this attribute name
- Throws:
MetadataException- If the targetted node does not exist or if xpath expression is not valid
-
hasNode
boolean hasNode(String relativeXpath, Object... arguments)
Check if the node addressed by the XPath exists in the document.- Parameters:
relativeXpath- XPath expression where the tag should be locatedarguments- XPath arguments. Uses String.format() to build XPath expression.- Returns:
- true if the tag is exist
-
evalToBoolean
Boolean evalToBoolean(String relativeXpath, Object... arguments)
Evaluate the given XPath expression against the current node and return the result as a Boolean.- Parameters:
relativeXpath- The XPath expressionarguments- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- The
XPathConstants.BOOLEANreturn type
-
evalToNode
Node evalToNode(String relativeXpath, Object... arguments)
Evaluate the given XPath expression against the current node and return the result as a Node.- Parameters:
relativeXpath- The XPath expressionarguments- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- The
XPathConstants.NODEreturn type
-
evalToNodeSet
NodeList evalToNodeSet(String relativeXpath, Object... arguments)
Evaluate the given XPath expression against the current node and return the result as a NodeList.- Parameters:
relativeXpath- The XPath expressionarguments- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- The
XPathConstants.NODESETreturn type
-
evalToNumber
Number evalToNumber(String relativeXpath, Object... arguments)
Evaluate the given XPath expression against the current node and return the result as a Number.- Parameters:
relativeXpath- The XPath expressionarguments- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- The
XPathConstants.NUMBERreturn type
-
evalToString
String evalToString(String relativeXpath, Object... arguments)
Evaluate the given XPath expression against the current node and return the result as a String.- Parameters:
relativeXpath- The XPath expressionarguments- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- The
XPathConstants.STRINGreturn type
-
getEncoding
String getEncoding()
-
gotoChild
MetadataNode gotoChild() throws MetadataException
Go to the only child element of the current node.- Returns:
- this
- Throws:
MetadataException- If the current node has several childs or no child at all
-
gotoChild
MetadataNode gotoChild(int i) throws MetadataException
Go to the Nth child of the curent node.- Parameters:
i- index of the child, from 1 to child element number- Returns:
- this
- Throws:
MetadataException- If the child node does not exist
-
gotoChild
MetadataNode gotoChild(String nodeName) throws MetadataException
Go to the child found with given node name- Parameters:
nodeName- name of the child to find.- Returns:
- this
- Throws:
MetadataException- If the element with this name has not been found or if there are too many elements
-
gotoFirstChild
MetadataNode gotoFirstChild() throws MetadataException
Go to the first child element of the current node.- Returns:
- this
- Throws:
MetadataException- If the current node has no child at all
-
gotoFirstChild
MetadataNode gotoFirstChild(String name) throws MetadataException
Go to the first child with the given name- Parameters:
name- Name of the child to go at- Returns:
- this
- Throws:
MetadataException- If the current node has no child at all
-
gotoLastChild
MetadataNode gotoLastChild() throws MetadataException
Go to the last child element of the current node.- Returns:
- this
- Throws:
MetadataException- If the current node has no child at all
-
gotoLastChild
MetadataNode gotoLastChild(String name) throws MetadataException
Go to the last child with the given name- Parameters:
name- Name of the child to go at- Returns:
- this
- Throws:
MetadataException- If the current node has no child at all
-
gotoParent
MetadataNode gotoParent()
Go to parent tag. Do nothing if we are already at root- Returns:
- this
-
gotoRoot
MetadataNode gotoRoot()
Go to document root tag- Returns:
- this
-
gotoTag
MetadataNode gotoTag(String relativeXpath, Object... arguments) throws MetadataException
Go to a specific node- Parameters:
relativeXpath- XPath expressionarguments- to be replaced in XPath expression before compiling. Uses String.format() to build XPath expression.- Returns:
- this
- Throws:
MetadataException- if the node does not exist or if the XPath expression is invalid
-
createNamespaceContext
MetadataNode createNamespaceContext()
Create a facade node which allows a new mapping of namespace prefixes to be used to navigate and query nodes without changing the base document.- Throws:
MetadataException- If the namespace handling has been disabled on the Metadata containing this node.
-
-