| java.lang.Object org.apache.cocoon.xml.dom.DOMUtil
DOMUtil | final public class DOMUtil (Code) | | This class is a utility class for miscellaneous DOM functions, like getting
and setting values of nodes.
author: Carsten Ziegeler version: $Id: DOMUtil.java 433543 2006-08-22 06:22:54Z crossley $ |
Method Summary | |
public static String[] | buildPathArray(String xpath) Build the input for the get...FromPath methods. | public static boolean | compareAttributes(Element first, Element second) Compare all attributes of two elements. | public static Document | createDocument() Create a new empty DOM document. | public static SourceParameters | createParameters(Node fragment, SourceParameters source) Create a parameter object from xml. | public static String | createText(DocumentFragment fragment) Create a string from a DOM document fragment. | public static DocumentFragment | getDocumentFragment(SAXParser parser, Reader stream) Get a document fragment from a Reader . | public static Node | getFirstNodeFromPath(Node contextNode, String[] path, boolean create) Use a path to select the first occurence of a node. | public static NodeList | getNodeListFromPath(Node contextNode, String[] path) Use a path to select all occurences of a node. | public static Document | getOwnerDocument(Node node) Get the owner of the DOM document belonging to the node. | public static Node | getSingleNode(Node contextNode, String str, XPathProcessor processor) Use an XPath string to select a single node. | public static Node | getSingleNode(Node contextNode, String str) Use an XPath string to select a single node. | public static boolean | getValueAsBooleanOf(Node root, String path) Get the boolean value of the node specified by the XPath. | public static boolean | getValueAsBooleanOf(Node root, String path, XPathProcessor processor) Get the boolean value of the node specified by the XPath. | public static boolean | getValueAsBooleanOf(Node root, String path, boolean defaultValue) Get the boolean value of the node specified by the XPath. | public static boolean | getValueAsBooleanOf(Node root, String path, boolean defaultValue, XPathProcessor processor) Get the boolean value of the node specified by the XPath. | public static String | getValueOf(Node root, String path) Get the value of the node specified by the XPath. | public static String | getValueOf(Node root, String path, XPathProcessor processor) Get the value of the node specified by the XPath. | public static String | getValueOf(Node root, String path, String defaultValue) Get the value of the node specified by the XPath. | public static String | getValueOf(Node root, String path, String defaultValue, XPathProcessor processor) Get the value of the node specified by the XPath. | public static String | getValueOfNode(XPathProcessor processor, Node root, String path) Get the value of the node specified by the XPath. | public static String | getValueOfNode(XPathProcessor processor, Node root, String path, String defaultValue) Get the value of the node specified by the XPath. | public static String | getValueOfNode(Node node) Get the value of the DOM node. | public static String | getValueOfNode(Node node, String defaultValue) Get the value of the node. | public static boolean | getValueOfNodeAsBoolean(XPathProcessor processor, Node root, String path) Get the boolean value of the node specified by the XPath. | public static boolean | getValueOfNodeAsBoolean(XPathProcessor processor, Node root, String path, boolean defaultValue) Get the boolean value of the node specified by the XPath. | public static String | node2String(Node node) Converts a org.w3c.dom.Node to a String. | public static String | node2String(Node node, boolean pretty) Create a string representation of a org.w3c.dom.Node and any (most)
subtypes. | public static StringBuffer | node2StringBuffer(Node node) Create a string representation of a org.w3c.dom.Node and any (most)
subtypes. | public static StringBuffer | node2StringBuffer(Node node, boolean pretty, String indent) Create a string representation of a org.w3c.dom.Node and any (most)
subtypes.
Parameters: node - a org.w3c.dom.Node value Parameters: pretty - a boolean value whether to format the XML Parameters: indent - a String value containing spaces as initialindent, if null defaults to empty string. | public static NodeList | selectNodeList(Node contextNode, String str) Use an XPath string to select a nodelist. | public static NodeList | selectNodeList(Node contextNode, String str, XPathProcessor processor) Use an XPath string to select a nodelist. | public static Node | selectSingleNode(Node rootNode, String path) Return the Node from the DOM Node rootNode
using the XPath expression path . | public static Node | selectSingleNode(Node rootNode, String path, XPathProcessor processor) Return the Node from the DOM Node rootNode
using the XPath expression path . | public static void | setValueOfNode(Node node, String value) Set the value of the DOM node. | public static void | valueOf(Node parent, String text) Implementation for String : outputs characters
representing the value. | public static void | valueOf(Node parent, XMLizable v) Implementation for XMLizable : outputs the value by
calling v.toSax(contentHandler) . | public static void | valueOf(Node parent, Node v) Implementation for org.w3c.dom.Node : converts the Node to
a SAX event stream. | public static void | valueOf(Node parent, Collection v) Implementation for java.util.Collection : outputs the
value by calling
DOMUtil.valueOf(Node,Object) on each element of the
collection. | public static void | valueOf(Node parent, Map v) Implementation for java.util.Map : For each entry an
element is created with the childs key and value Outputs the value and
the key by calling
DOMUtil.valueOf(Node,Object) on each value and key
of the Map. | public static void | valueOf(Node parent, Object v) |
buildPathArray | public static String[] buildPathArray(String xpath)(Code) | | Build the input for the get...FromPath methods. If the XPath expression
cannot be handled by the methods, null is returned.
|
compareAttributes | public static boolean compareAttributes(Element first, Element second)(Code) | | Compare all attributes of two elements. This method returns true only if
both nodes have the same number of attributes and the same attributes
with equal values. Namespace definition nodes are ignored
|
createParameters | public static SourceParameters createParameters(Node fragment, SourceParameters source)(Code) | | Create a parameter object from xml. The xml is flat and consists of
elements which all have exactly one text node: value_one
value_two A parameter can occur more than once with
different values. If source is not specified a new
parameter object is created otherwise the parameters are added to source.
|
createText | public static String createText(DocumentFragment fragment)(Code) | | Create a string from a DOM document fragment. Only the top level text
nodes are chained together to build the text.
|
getDocumentFragment | public static DocumentFragment getDocumentFragment(SAXParser parser, Reader stream) throws ProcessingException(Code) | | Get a document fragment from a Reader . The reader must
provide valid XML, but it is allowed that the XML has more than one root
node. This xml is parsed by the specified parser instance and a DOM
DocumentFragment is created.
|
getFirstNodeFromPath | public static Node getFirstNodeFromPath(Node contextNode, String[] path, boolean create)(Code) | | Use a path to select the first occurence of a node. The namespace of a
node is ignored!
Parameters: contextNode - The node starting the search. Parameters: path - The path to search the node. The contextNode is searched for achild named path[0], this node is searched for a child namedpath[1]... Parameters: create - If a child with the corresponding name is not found and createis set, this node will be created. |
getNodeListFromPath | public static NodeList getNodeListFromPath(Node contextNode, String[] path)(Code) | | Use a path to select all occurences of a node. The namespace of a node is
ignored!
Parameters: contextNode - The node starting the search. Parameters: path - The path to search the node. The contextNode is searched for achild named path[0], this node is searched for a child namedpath[1]... |
getOwnerDocument | public static Document getOwnerDocument(Node node)(Code) | | Get the owner of the DOM document belonging to the node. This works even
if the node is the document itself.
Parameters: node - The node. The corresponding document. |
getSingleNode | public static Node getSingleNode(Node contextNode, String str, XPathProcessor processor) throws TransformerException(Code) | | Use an XPath string to select a single node. XPath namespace prefixes are
resolved from the context node, which may not be what you want (see the
next method).
Parameters: contextNode - The node to start searching from. Parameters: str - A valid XPath string. Parameters: processor - The XPath processor to use The first node found that matches the XPath, or null. throws: TransformerException - |
getSingleNode | public static Node getSingleNode(Node contextNode, String str) throws TransformerException(Code) | | Use an XPath string to select a single node. XPath namespace prefixes are
resolved from the context node, which may not be what you want (see the
next method).
Parameters: contextNode - The node to start searching from. Parameters: str - A valid XPath string. The first node found that matches the XPath, or null. throws: TransformerException - To be removed in 2.2. |
getValueAsBooleanOf | public static boolean getValueAsBooleanOf(Node root, String path) throws ProcessingException(Code) | | Get the boolean value of the node specified by the XPath. This works
similar to <xsl:value-of>. If the node exists and has a value this
value is converted to a boolean, e.g. "true" or "false" as value will
result into the corresponding boolean values.
Parameters: root - The node to start the search. Parameters: path - XPath search expression. The boolean value of the node. throws: ProcessingException - If the node is not found. |
getValueAsBooleanOf | public static boolean getValueAsBooleanOf(Node root, String path, XPathProcessor processor) throws ProcessingException(Code) | | Get the boolean value of the node specified by the XPath. This works
similar to <xsl:value-of>. If the node exists and has a value this
value is converted to a boolean, e.g. "true" or "false" as value will
result into the corresponding boolean values.
Parameters: root - The node to start the search. Parameters: path - XPath search expression. Parameters: processor - The XPath Processor The boolean value of the node. throws: ProcessingException - If the node is not found. |
getValueAsBooleanOf | public static boolean getValueAsBooleanOf(Node root, String path, boolean defaultValue) throws ProcessingException(Code) | | Get the boolean value of the node specified by the XPath. This works
similar to <xsl:value-of>. If the node exists and has a value this
value is converted to a boolean, e.g. "true" or "false" as value will
result into the corresponding boolean values. If the node does not exist,
the defaultValue is returned.
Parameters: root - The node to start the search. Parameters: path - XPath search expression. Parameters: defaultValue - Default boolean value. The value of the node or defaultValue |
getValueAsBooleanOf | public static boolean getValueAsBooleanOf(Node root, String path, boolean defaultValue, XPathProcessor processor) throws ProcessingException(Code) | | Get the boolean value of the node specified by the XPath. This works
similar to <xsl:value-of>. If the node exists and has a value this
value is converted to a boolean, e.g. "true" or "false" as value will
result into the corresponding boolean values. If the node does not exist,
the defaultValue is returned.
Parameters: root - The node to start the search. Parameters: path - XPath search expression. Parameters: defaultValue - Default boolean value. Parameters: processor - The XPath Processor The value of the node or defaultValue |
getValueOf | public static String getValueOf(Node root, String path) throws ProcessingException(Code) | | Get the value of the node specified by the XPath. This works similar to
<xsl:value-of>. If the node does not exist null is
returned.
Parameters: root - The node to start the search. Parameters: path - XPath search expression. The value of the node or null |
getValueOf | public static String getValueOf(Node root, String path, XPathProcessor processor) throws ProcessingException(Code) | | Get the value of the node specified by the XPath. This works similar to
<xsl:value-of>. If the node does not exist null is
returned.
Parameters: root - The node to start the search. Parameters: path - XPath search expression. Parameters: processor - The XPath processor to use The value of the node or null |
getValueOf | public static String getValueOf(Node root, String path, String defaultValue) throws ProcessingException(Code) | | Get the value of the node specified by the XPath. This works similar to
<xsl:value-of>. If the node is not found the defaultValue
is returned.
Parameters: root - The node to start the search. Parameters: path - XPath search expression. Parameters: defaultValue - The default value if the node does not exist. The value of the node or defaultValue |
getValueOf | public static String getValueOf(Node root, String path, String defaultValue, XPathProcessor processor) throws ProcessingException(Code) | | Get the value of the node specified by the XPath. This works similar to
<xsl:value-of>. If the node is not found the defaultValue
is returned.
Parameters: root - The node to start the search. Parameters: path - XPath search expression. Parameters: defaultValue - The default value if the node does not exist. Parameters: processor - The XPath Processor The value of the node or defaultValue |
getValueOfNode | public static String getValueOfNode(XPathProcessor processor, Node root, String path) throws ProcessingException(Code) | | Get the value of the node specified by the XPath. This works similar to
<xsl:value-of>. If the node does not exist null is
returned.
Parameters: root - The node to start the search. Parameters: path - XPath search expression. The value of the node or null |
getValueOfNode | public static String getValueOfNode(XPathProcessor processor, Node root, String path, String defaultValue) throws ProcessingException(Code) | | Get the value of the node specified by the XPath. This works similar to
<xsl:value-of>. If the node is not found the defaultValue
is returned.
Parameters: root - The node to start the search. Parameters: path - XPath search expression. Parameters: defaultValue - The default value if the node does not exist. The value of the node or defaultValue |
getValueOfNode | public static String getValueOfNode(Node node)(Code) | | Get the value of the DOM node. The value of a node is the content of the
first text node. If the node has no text nodes, null is
returned.
|
getValueOfNode | public static String getValueOfNode(Node node, String defaultValue)(Code) | | Get the value of the node. The value of the node is the content of the
first text node. If the node has no text nodes the defaultValue
is returned.
|
getValueOfNodeAsBoolean | public static boolean getValueOfNodeAsBoolean(XPathProcessor processor, Node root, String path) throws ProcessingException(Code) | | Get the boolean value of the node specified by the XPath. This works
similar to <xsl:value-of>. If the node exists and has a value this
value is converted to a boolean, e.g. "true" or "false" as value will
result into the corresponding boolean values.
Parameters: root - The node to start the search. Parameters: path - XPath search expression. The boolean value of the node. throws: ProcessingException - If the node is not found. |
getValueOfNodeAsBoolean | public static boolean getValueOfNodeAsBoolean(XPathProcessor processor, Node root, String path, boolean defaultValue) throws ProcessingException(Code) | | Get the boolean value of the node specified by the XPath. This works
similar to <xsl:value-of>. If the node exists and has a value this
value is converted to a boolean, e.g. "true" or "false" as value will
result into the corresponding boolean values. If the node does not exist,
the defaultValue is returned.
Parameters: root - The node to start the search. Parameters: path - XPath search expression. Parameters: defaultValue - Default boolean value. The value of the node or defaultValue |
node2String | public static String node2String(Node node, boolean pretty)(Code) | | Create a string representation of a org.w3c.dom.Node and any (most)
subtypes.
Parameters: node - a org.w3c.dom.Node value Parameters: pretty - a boolean value whether to format the XML a String valueXMLUtils.serializeNode(NodeProperties) |
node2StringBuffer | public static StringBuffer node2StringBuffer(Node node, boolean pretty, String indent)(Code) | | Create a string representation of a org.w3c.dom.Node and any (most)
subtypes.
Parameters: node - a org.w3c.dom.Node value Parameters: pretty - a boolean value whether to format the XML Parameters: indent - a String value containing spaces as initialindent, if null defaults to empty string. a StringBuffer valueXMLUtils.serializeNode(NodeProperties) |
selectNodeList | public static NodeList selectNodeList(Node contextNode, String str) throws TransformerException(Code) | | Use an XPath string to select a nodelist. XPath namespace prefixes are
resolved from the contextNode.
Parameters: contextNode - The node to start searching from. Parameters: str - A valid XPath string. A NodeIterator, should never be null. throws: TransformerException - |
selectNodeList | public static NodeList selectNodeList(Node contextNode, String str, XPathProcessor processor) throws TransformerException(Code) | | Use an XPath string to select a nodelist. XPath namespace prefixes are
resolved from the contextNode.
Parameters: contextNode - The node to start searching from. Parameters: str - A valid XPath string. Parameters: processor - The XPath Processor A NodeIterator, should never be null. throws: TransformerException - |
selectSingleNode | public static Node selectSingleNode(Node rootNode, String path) throws ProcessingException(Code) | | Return the Node from the DOM Node rootNode
using the XPath expression path . If the node does not
exist, it is created and then returned. This is a very simple method for
creating new nodes. If the XPath contains selectors ([,,,]) or "*" it is
of course not possible to create the new node. So if you use such XPaths
the node must exist beforehand. An simple exception is if the expression
contains attribute test to values (e.g. [@id = 'du' and
Parameters: rootNode - The node to start the search. Parameters: path - XPath expression for searching the node. The node specified by the path. throws: ProcessingException - If no path is specified or the XPath engine fails. |
selectSingleNode | public static Node selectSingleNode(Node rootNode, String path, XPathProcessor processor) throws ProcessingException(Code) | | Return the Node from the DOM Node rootNode
using the XPath expression path . If the node does not
exist, it is created and then returned. This is a very simple method for
creating new nodes. If the XPath contains selectors ([,,,]) or "*" it is
of course not possible to create the new node. So if you use such XPaths
the node must exist beforehand. An simple exception is if the expression
contains attribute test to values (e.g. [@id = 'du' and
Parameters: rootNode - The node to start the search. Parameters: path - XPath expression for searching the node. Parameters: processor - The XPath processor to use The node specified by the path. throws: ProcessingException - If no path is specified or the XPath engine fails. |
setValueOfNode | public static void setValueOfNode(Node node, String value)(Code) | | Set the value of the DOM node. All current children of the node are
removed and a new text node with the value is appended.
|
valueOf | public static void valueOf(Node parent, String text) throws ProcessingException(Code) | | Implementation for String : outputs characters
representing the value.
Parameters: parent - The node getting the value Parameters: text - the value |
valueOf | public static void valueOf(Node parent, XMLizable v) throws ProcessingException(Code) | | Implementation for XMLizable : outputs the value by
calling v.toSax(contentHandler) .
Parameters: parent - The node getting the value Parameters: v - the XML fragment |
valueOf | public static void valueOf(Node parent, Node v) throws ProcessingException(Code) | | Implementation for org.w3c.dom.Node : converts the Node to
a SAX event stream.
Parameters: parent - The node getting the value Parameters: v - the value |
valueOf | public static void valueOf(Node parent, Map v) throws ProcessingException(Code) | | Implementation for java.util.Map : For each entry an
element is created with the childs key and value Outputs the value and
the key by calling
DOMUtil.valueOf(Node,Object) on each value and key
of the Map.
Parameters: parent - The node getting the value Parameters: v - the Map |
valueOf | public static void valueOf(Node parent, Object v) throws ProcessingException(Code) | | Implementation for Object depending on its class :
Parameters: parent - The node getting the value Parameters: v - the value |
|
|