Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.cocoon.forms.util
Class DomHelper

    java.lang.Object
      org.apache.cocoon.forms.util.DomHelper

public class DomHelper
extends Object

Helper class to create and retrieve information from DOM-trees. It provides some functionality comparable to what's found in Avalon's Configuration objects. These lasts one could however not be used by Cocoon Forms because they don't provide an accurate model of an XML file (no mixed content, no namespaced attributes, no namespace declarations, ...).

This class depends specifically on the Xerces DOM implementation to be able to provide information about the location of elements in their source XML file. See the `getLocation(Element)` method.

Version:
  $Id: DomHelper.java 587759 2007-10-24 03:00:37Z vgritsenko $

Field Summary
`static String` | `XMLNS_URI`

Constructor Summary
`DomHelper()`

Method Summary
`static XMLizable` | `compileElementContent(Element element)` Returns the content of the given Element as an object implementing the XMLizable interface.
`static String` | `getAttribute(Element element, String attributeName)` Returns the value of an element's attribute, but throws an exception if the element has no such attribute.
`static String` | `getAttribute(Element element, String attributeName, String defaultValue)` Returns the value of an element's attribute, or a default value if the element has no such attribute.
`static boolean` | `getAttributeAsBoolean(Element element, String attributeName, boolean defaultValue)`
`static int` | `getAttributeAsInteger(Element element, String attributeName)`
`static int` | `getAttributeAsInteger(Element element, String attributeName, int defaultValue)`
`static Element` | `getChildElement(Element element, String namespace, String localName)` Returns the first child element with the given namespace and localName, or null if there is no such element.
`static Element` | `getChildElement(Element element, String namespace, String localName, boolean required)` Returns the first child element with the given namespace and localName, or null if there is no such element and required flag is unset or throws an Exception if the "required" flag is set.
`static Element[]` | `getChildElements(Element element, String namespace)` Returns all Element children of an Element that belong to the given namespace.
`static Element[]` | `getChildElements(Element element, String namespace, String localName)` Returns all Element children of an Element that belong to the given namespace and have the given local name.
`static int` | `getColumnLocation(Element element)`
`static String` | `getElementText(Element element)`
`static Map` | `getInheritedNSDeclarations(Element elm)`
`static int` | `getLineLocation(Element element)`
`static Map` | `getLocalNSDeclarations(Element elm)`
`static String` | `getLocation(Element element)` Retrieves the location of an element node in the source file from which the Document was created.
`static org.apache.cocoon.util.location.Location` | `getLocationObject(Element element)`
`static String` | `getSystemIdLocation(Element element)`
`static Document` | `parse(InputSource inputSource, org.apache.cocoon.core.xml.SAXParser parser)` Creates a W3C Document that remembers the location of each element in the source file.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### XMLNS_URI

    public static final String XMLNS_URI

See Also:
  Constant Field Values

Constructor Detail

### DomHelper

    public DomHelper()

Method Detail

### getLocationObject

    public static org.apache.cocoon.util.location.Location getLocationObject(Element element)

### getLocation

    public static String getLocation(Element element)

  Retrieves the location of an element node in the source file from which the Document was created. This will only work for Document's created with the method `#parse(InputSource, ServiceManager)` of this class.

### getSystemIdLocation

    public static String getSystemIdLocation(Element element)

### getLineLocation

    public static int getLineLocation(Element element)

### getColumnLocation

    public static int getColumnLocation(Element element)

### getChildElements

    public static Element[] getChildElements(Element element,
                                             String namespace)

  Returns all Element children of an Element that belong to the given namespace.

### getChildElements

    public static Element[] getChildElements(Element element,
                                             String namespace,
                                             String localName)

  Returns all Element children of an Element that belong to the given namespace and have the given local name.

### getChildElement

    public static Element getChildElement(Element element,
                                          String namespace,
                                          String localName)

  Returns the first child element with the given namespace and localName, or null if there is no such element.

### getChildElement

    public static Element getChildElement(Element element,
                                          String namespace,
                                          String localName,
                                          boolean required)
                                   throws FormsException

  Returns the first child element with the given namespace and localName, or null if there is no such element and required flag is unset or throws an Exception if the "required" flag is set.

  Throws:
    `FormsException`

### getAttribute

    public static String getAttribute(Element element,
                                      String attributeName)
                               throws FormsException

  Returns the value of an element's attribute, but throws an exception if the element has no such attribute.

  Throws:
    `FormsException`

### getAttribute

    public static String getAttribute(Element element,
                                      String attributeName,
                                      String defaultValue)

  Returns the value of an element's attribute, or a default value if the element has no such attribute.

### getAttributeAsInteger

    public static int getAttributeAsInteger(Element element,
                                            String attributeName)
                                     throws FormsException

  Throws:
    `FormsException`

### getAttributeAsInteger

    public static int getAttributeAsInteger(Element element,
                                            String attributeName,
                                            int defaultValue)
                                     throws FormsException

  Throws:
    `FormsException`

### getAttributeAsBoolean

    public static boolean getAttributeAsBoolean(Element element,
                                                String attributeName,
                                                boolean defaultValue)

### getElementText

    public static String getElementText(Element element)

### compileElementContent

    public static XMLizable compileElementContent(Element element)

  Returns the content of the given Element as an object implementing the XMLizable interface. Practically speaking, the implementation uses the `SaxBuffer` class. The XMLizable object will be a standalone blurb of SAX events, not producing start/endDocument calls and containing all necessary namespace declarations.

### parse

    public static Document parse(InputSource inputSource,
                                 org.apache.cocoon.core.xml.SAXParser parser)
                          throws SAXException,
                                 IOException

  Creates a W3C Document that remembers the location of each element in the source file. The location of element nodes can then be retrieved using the `getLocation(Element)` method.

  Parameters:
    `inputSource` - the inputSource to read the document from
  Throws:
    `SAXException`
    `IOException`

### getLocalNSDeclarations

    public static Map getLocalNSDeclarations(Element elm)

### getInheritedNSDeclarations

    public static Map getInheritedNSDeclarations(Element elm)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 1999-2008 The Apache Software Foundation. All Rights Reserved.