org.apache.lenya.xml
Class DOMUtil

java.lang.Object
  extended by org.apache.lenya.xml.DOMUtil

public class DOMUtil
extends java.lang.Object

This class is a utility class for miscellaneous DOM functions, similar to org.apache.cocoon.xml.dom.DOMUtil FIXME: Merge classes or extend functionality


Constructor Summary
DOMUtil()
          Ctor.
 
Method Summary
 void addElement(org.w3c.dom.Document document, java.lang.String xpath, java.lang.String value)
          Deprecated. See replacement code.
 org.w3c.dom.Document create(java.lang.String xml)
          Deprecated. Use DocumentHelper.readDocument(java.lang.String) instead.
 org.w3c.dom.Node createNode(org.w3c.dom.Document document, XPath xpath)
          Deprecated. See replacement code.
 boolean elementExists(org.w3c.dom.Element element, XPath xpath)
          Deprecated. See replacement code.
 org.w3c.dom.Element[] getAllElements(org.w3c.dom.Document document, XPath xpath)
          Deprecated. Use XPathAPI.selectNodeList(org.w3c.dom.Node, java.lang.String) instead.
 java.lang.String[] getAllElementValues(org.w3c.dom.Document document, XPath xpath)
          get all elements values from |xpath|, xpath has to start with the root node
 java.lang.String getAttributeValue(org.w3c.dom.Element element, XPath xpath)
          Deprecated. See replacement code.
 org.w3c.dom.Element getElement(org.w3c.dom.Element element, XPath xpath)
          Deprecated. Use XPathAPI.selectSingleNode(org.w3c.dom.Node, java.lang.String) instead.
 java.lang.String getElementValue(org.w3c.dom.Document document, XPath xpath)
          Deprecated. Use instead.
 java.lang.String getElementValue(org.w3c.dom.Element element)
          Deprecated. See replacement code.
 java.lang.String getElementValue(org.w3c.dom.Element element, XPath xpath)
          Deprecated. Use instead.
static void main(java.lang.String[] args)
          Main method, used to test the class.
 void replaceText(org.w3c.dom.Element element, java.lang.String text)
           This method removes all child nodes from an element and inserts a text node instead.
 org.w3c.dom.Element[] select(org.w3c.dom.Document document, java.lang.String xpath)
          Deprecated. Use XPathAPI.selectNodeList(org.w3c.dom.Node, java.lang.String) instead.
 void setAttributeValue(org.w3c.dom.Document document, java.lang.String xpath, java.lang.String value)
          Deprecated. See replacement code.
 void setElementValue(org.w3c.dom.Document document, java.lang.String xpath, java.lang.String value)
          Deprecated. See replacement code.
 void setValue(org.w3c.dom.Document document, XPath xpath, java.lang.String value)
           If the XPath expression denotes an element, the child nodes of this element are replaced by a single text node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMUtil

public DOMUtil()
Ctor.

Method Detail

main

public static void main(java.lang.String[] args)
Main method, used to test the class.

Parameters:
args - The command line arguments.

create

public org.w3c.dom.Document create(java.lang.String xml)
                            throws java.lang.Exception
Deprecated. Use DocumentHelper.readDocument(java.lang.String) instead.

Creates a DOM document from a string.

Parameters:
xml - The string.
Returns:
A DOM document.
Throws:
java.lang.Exception - if an error occurs.

select

public org.w3c.dom.Element[] select(org.w3c.dom.Document document,
                                    java.lang.String xpath)
                             throws java.lang.Exception
Deprecated. Use XPathAPI.selectNodeList(org.w3c.dom.Node, java.lang.String) instead.

Selects an array of elements using an XPath.

Parameters:
document - The document.
xpath - The XPath.
Returns:
An array of elements.
Throws:
java.lang.Exception - if the XPath does not return a NodeList consisting of elements.

replaceText

public void replaceText(org.w3c.dom.Element element,
                        java.lang.String text)

This method removes all child nodes from an element and inserts a text node instead.

Caution: Child elements are removed as well!

Parameters:
element - The element.
text - The string to insert as a text node.

getElementValue

public java.lang.String getElementValue(org.w3c.dom.Document document,
                                        XPath xpath)
                                 throws java.lang.Exception
Deprecated. Use instead.

Returns the concatenation string of all text nodes which are children of an element. The XPath is resolved against the document element.

Parameters:
document - The document.
xpath - The XPath of the element to resolve.
Returns:
A string.
Throws:
java.lang.Exception - if an error occurs.

getElementValue

public java.lang.String getElementValue(org.w3c.dom.Element element,
                                        XPath xpath)
                                 throws java.lang.Exception
Deprecated. Use instead.

Returns the concatenation string of all text nodes which are children of an element. The XPath is resolved against a certain element.

Parameters:
element - The element to resolve the XPath against.
xpath - The XPath of the element to resolve.
Returns:
A string.
Throws:
java.lang.Exception - if an error occurs.

elementExists

public boolean elementExists(org.w3c.dom.Element element,
                             XPath xpath)
                      throws java.lang.Exception
Deprecated. See replacement code.

Check if elements exists This method just checks the root element! TODO: Implementation is not really finished, or is it! Replacement code: Node node = XPathAPI.selectSingleNode(element, xPath); if (node != null && node instanceof Element) { exists = true; }

Throws:
java.lang.Exception

getElement

public org.w3c.dom.Element getElement(org.w3c.dom.Element element,
                                      XPath xpath)
                               throws java.lang.Exception
Deprecated. Use XPathAPI.selectSingleNode(org.w3c.dom.Node, java.lang.String) instead.

Get element via XPath.

Throws:
java.lang.Exception

getAllElements

public org.w3c.dom.Element[] getAllElements(org.w3c.dom.Document document,
                                            XPath xpath)
                                     throws java.lang.Exception
Deprecated. Use XPathAPI.selectNodeList(org.w3c.dom.Node, java.lang.String) instead.

get all elements with |xpath|, xpath has to start with the root node

Parameters:
document - a value of type 'Document'
xpath - a value of type 'XPath'
Returns:
a value of type 'Element[]'
Throws:
java.lang.Exception - if an error occurs

getAllElementValues

public java.lang.String[] getAllElementValues(org.w3c.dom.Document document,
                                              XPath xpath)
                                       throws java.lang.Exception
get all elements values from |xpath|, xpath has to start with the root node

Parameters:
document - a value of type 'Document'
xpath - a value of type 'XPath'
Returns:
a value of type 'String[]'
Throws:
java.lang.Exception - if an error occurs

getElementValue

public java.lang.String getElementValue(org.w3c.dom.Element element)
                                 throws java.lang.Exception
Deprecated. See replacement code.

Returns the concatenation string of all text nodes which are children of an element.

Parameters:
element - The element.
Returns:
A string.
Throws:
java.lang.Exception - if an error occurs. Replacement code: Element element = (Element) XPathAPI.selectSingleNode(document, xPath); String value = DocumentHelper.getSimpleElementText(element, "...");

getAttributeValue

public java.lang.String getAttributeValue(org.w3c.dom.Element element,
                                          XPath xpath)
                                   throws java.lang.Exception
Deprecated. See replacement code.

Return the value of an attribte named e.g. "this/myelement/(at)myattribute"

Parameters:
element - a value of type 'Element'
xpath - a value of type 'XPath'
Returns:
a value of type 'String' Replacement code: Element element = (Element) XPathAPI.selectSingleNode(document, xPath); String value = element.getAttribute("...");
Throws:
java.lang.Exception

setElementValue

public void setElementValue(org.w3c.dom.Document document,
                            java.lang.String xpath,
                            java.lang.String value)
                     throws java.lang.Exception
Deprecated. See replacement code.

Describe 'setElementValue' method here.

Parameters:
document - a value of type 'Document'
xpath - a value of type 'String'
value - a value of type 'String'
Throws:
java.lang.Exception - if an error occurs Replacement code: Element element = (Element) XPathAPI.selectSingleNode(document, xPath); DocumentHelper.setSimpleElementText(element, "...");

addElement

public void addElement(org.w3c.dom.Document document,
                       java.lang.String xpath,
                       java.lang.String value)
                throws java.lang.Exception
Deprecated. See replacement code.

Replacement code: Element parent = (Element) XPathAPI.selectSingleNode(document, xPath); Element child = NamespaceHelper.createElement("...", "..."); parent.appendChild(child);

Throws:
java.lang.Exception

setAttributeValue

public void setAttributeValue(org.w3c.dom.Document document,
                              java.lang.String xpath,
                              java.lang.String value)
                       throws java.lang.Exception
Deprecated. See replacement code.

Replacement code: Element element = (Element) XPathAPI.selectSingleNode(document, xPath); element.setAttribute("...", "...");

Throws:
java.lang.Exception

setValue

public void setValue(org.w3c.dom.Document document,
                     XPath xpath,
                     java.lang.String value)
              throws java.lang.Exception

Parameters:
document - The document to resolve the XPath against.
xpath - The XPath.
value - A string.
Throws:
java.lang.Exception - if an error occurs.

createNode

public org.w3c.dom.Node createNode(org.w3c.dom.Document document,
                                   XPath xpath)
                            throws java.lang.Exception
Deprecated. See replacement code.

Replacement code: Element parent = XPathAPI.selectSingleNode(...); Element child = document.createElementNS("http://...", "..."); parent.appendChild(child);

Throws:
java.lang.Exception


Copyright © 1999-2005 Apache Software Foundation. All Rights Reserved.