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.jboss.portal.common.xml
Class XMLTools

    java.lang.Object
      org.jboss.portal.common.xml.XMLTools

    public class XMLTools

extends java.lang.Object

Utilities for dealing with XML.

Version:
  $Revision: 7686 $
Author:
  Martin Holzner, Julien Viet

Nested Class Summary
`static interface` | `XMLTools.Filter<N extends org.w3c.dom.Node>`

Field Summary
`static java.lang.String` | `ATTRIB_CDATA_SECTION_ELEMENTS` .
`static java.lang.String` | `ATTRIB_HREF` .
`static java.lang.String` | `ATTRIB_INDENT` .
`static java.lang.String` | `ATTRIB_METHOD` .
`static java.lang.String` | `ATTRIB_OMIT_XML_DECLARATION` .
`static boolean` | `DEFAULT_NAMESPACE_AWARE` .
`static boolean` | `DEFAULT_VALIDATION` .
`static java.lang.String` | `DIRECTIVE_IMPORT` .
`static java.lang.String` | `DIRECTIVE_INCLUDE` .
`static java.lang.String` | `PARAM_NO` .
`static java.lang.String` | `PARAM_YES` .
`static java.lang.String` | `XML_LANG_NAMESPACE_URI` Namespace URI for XML lang.

Method Summary
`static java.lang.String` | `asString(org.w3c.dom.Element element)` Perform trimming by default
`static java.lang.String` | `asString(org.w3c.dom.Element element, boolean trim)` Get the element's content as a string.
`static XMLTools.Filter<org.w3c.dom.Element>` | `byName(java.lang.String uri, java.util.Set<java.lang.String> names)`
`static XMLTools.Filter<org.w3c.dom.Element>` | `byName(java.lang.String uri, java.lang.String name)`
`static java.util.List<org.w3c.dom.Element>` | `getChildren(org.w3c.dom.Element element)` Return all the children of the given element.
`static java.util.List<org.w3c.dom.Element>` | `getChildren(org.w3c.dom.Element element, java.lang.String name)` Return all the children of the given element having the specified name.
`static java.util.List<org.w3c.dom.Element>` | `getChildren(org.w3c.dom.Element element, java.lang.String uri, java.lang.String name)` Return all the children of the given element having the optionally specified name and the namespace URI.
`static
`<T extends org.w3c.dom.Node> java.util.List<T>`
` | `getChildren(org.w3c.dom.Node node, XMLTools.Filter<T> filter)` Return all the children of the given node that match the provided filter.
`static java.util.Iterator<org.w3c.dom.Element>` | `getChildrenIterator(org.w3c.dom.Element element)` Return an iterator for all the children of the given element.
`static java.util.Iterator<org.w3c.dom.Element>` | `getChildrenIterator(org.w3c.dom.Element element, java.lang.String name)` Return an iterator for all the children of the given element having the specified name.
`static java.util.Iterator<org.w3c.dom.Element>` | `getChildrenIterator(org.w3c.dom.Element element, java.lang.String uri, java.lang.String name)` Return an iterator for all the children of the given element having the specified name and the optionally specified namesspace uri.
`static javax.xml.parsers.DocumentBuilderFactory` | `getDocumentBuilderFactory()` Return the builder factory.
`static org.w3c.dom.Element` | `getUniqueChild(org.w3c.dom.Element element, boolean strict)` Return the optional unique child of an element.
`static org.w3c.dom.Element` | `getUniqueChild(org.w3c.dom.Element element, java.lang.String name, boolean strict)` Return an optional child of an element with the specified name.
`static org.w3c.dom.Element` | `getUniqueChild(org.w3c.dom.Element element, java.lang.String uri, java.lang.String name, boolean strict)` Return an optional child of an element with the specified name and the optionally specified namespace uri.
`static java.util.Properties` | `loadXMLProperties(org.w3c.dom.Document doc)`
`static java.util.Properties` | `loadXMLProperties(org.w3c.dom.Element propertiesElt)`
`static org.w3c.dom.Document` | `toDocument(org.w3c.dom.Element element)`
`static org.w3c.dom.Document` | `toDocument(java.lang.String text)` Parse a string into a document.
`static org.w3c.dom.Element` | `toElement(java.lang.String text)` Parse a string into an element.
`static java.lang.String` | `toString(org.w3c.dom.Document doc)` Serialize the document with the default format : - No XML declaration - Indented - Encoding is UTF-8
`static java.lang.String` | `toString(org.w3c.dom.Document doc, boolean omitXMLDeclaration, boolean standalone, boolean indented, java.lang.String encoding)`
`static java.lang.String` | `toString(org.w3c.dom.Element element)`

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

Field Detail

### XML_LANG_NAMESPACE_URI

    public static final java.lang.String XML_LANG_NAMESPACE_URI

  Namespace URI for XML lang.

  See Also:
    Constant Field Values

### PARAM_YES

    public static final java.lang.String PARAM_YES

  .

  See Also:
    Constant Field Values

### PARAM_NO

    public static final java.lang.String PARAM_NO

  .

  See Also:
    Constant Field Values

### ATTRIB_OMIT_XML_DECLARATION

    public static final java.lang.String ATTRIB_OMIT_XML_DECLARATION

  .

  See Also:
    Constant Field Values

### ATTRIB_CDATA_SECTION_ELEMENTS

    public static final java.lang.String ATTRIB_CDATA_SECTION_ELEMENTS

  .

  See Also:
    Constant Field Values

### ATTRIB_METHOD

    public static final java.lang.String ATTRIB_METHOD

  .

  See Also:
    Constant Field Values

### ATTRIB_INDENT

    public static final java.lang.String ATTRIB_INDENT

  .

  See Also:
    Constant Field Values

### ATTRIB_HREF

    public static final java.lang.String ATTRIB_HREF

  .

  See Also:
    Constant Field Values

### DIRECTIVE_IMPORT

    public static final java.lang.String DIRECTIVE_IMPORT

  .

  See Also:
    Constant Field Values

### DIRECTIVE_INCLUDE

    public static final java.lang.String DIRECTIVE_INCLUDE

  .

  See Also:
    Constant Field Values

### DEFAULT_NAMESPACE_AWARE

    public static final boolean DEFAULT_NAMESPACE_AWARE

  .

  See Also:
    Constant Field Values

### DEFAULT_VALIDATION

    public static final boolean DEFAULT_VALIDATION

  .

  See Also:
    Constant Field Values

Method Detail

### getDocumentBuilderFactory

    public static javax.xml.parsers.DocumentBuilderFactory getDocumentBuilderFactory()

  Return the builder factory.

### toString

    public static java.lang.String toString(org.w3c.dom.Document doc,
                                            boolean omitXMLDeclaration,
                                            boolean standalone,
                                            boolean indented,
                                            java.lang.String encoding)
                                     throws javax.xml.transform.TransformerException

  Throws:
    `javax.xml.transform.TransformerException`

### toString

    public static java.lang.String toString(org.w3c.dom.Document doc)
                                     throws javax.xml.transform.TransformerException

  Serialize the document with the default format : - No XML declaration - Indented - Encoding is UTF-8

  Throws:
    `javax.xml.transform.TransformerException`
  See Also:
    `toString(Document,Properties)`

### toString

    public static java.lang.String toString(org.w3c.dom.Element element)
                                     throws javax.xml.parsers.ParserConfigurationException,
                                            javax.xml.transform.TransformerException

  Throws:
    `javax.xml.parsers.ParserConfigurationException`
    `javax.xml.transform.TransformerException`
  See Also:
    `toString(Document)`

### toDocument

    public static org.w3c.dom.Document toDocument(java.lang.String text)
                                           throws javax.xml.parsers.ParserConfigurationException,
                                                  org.xml.sax.SAXException,
                                                  java.io.IOException

  Parse a string into a document.

  Throws:
    `javax.xml.parsers.ParserConfigurationException`
    `org.xml.sax.SAXException`
    `java.io.IOException`

### toElement

    public static org.w3c.dom.Element toElement(java.lang.String text)
                                         throws javax.xml.parsers.ParserConfigurationException,
                                                org.xml.sax.SAXException,
                                                java.io.IOException

  Parse a string into an element.

  Throws:
    `javax.xml.parsers.ParserConfigurationException`
    `org.xml.sax.SAXException`
    `java.io.IOException`

### toDocument

    public static org.w3c.dom.Document toDocument(org.w3c.dom.Element element)
                                           throws javax.xml.parsers.ParserConfigurationException,
                                                  org.xml.sax.SAXException,
                                                  java.io.IOException

  Throws:
    `javax.xml.parsers.ParserConfigurationException`
    `org.xml.sax.SAXException`
    `java.io.IOException`

### asString

    public static java.lang.String asString(org.w3c.dom.Element element)
                                     throws java.lang.IllegalArgumentException

  Perform trimming by default

  Parameters:
    `element` -
  Returns:
  Throws:
    `java.lang.IllegalArgumentException`
  See Also:
    `asString(org.w3c.dom.Element,boolean)`

### asString

    public static java.lang.String asString(org.w3c.dom.Element element,
                                            boolean trim)
                                     throws java.lang.IllegalArgumentException

  Get the element's content as a string.

  Parameters:
    `element` - the container
    `trim` - true if text should be trimmed before returning result
  Throws:
    `java.lang.IllegalArgumentException` - if the element content is mixed or null

### getUniqueChild

    public static org.w3c.dom.Element getUniqueChild(org.w3c.dom.Element element,
                                                     boolean strict)
                                              throws java.lang.IllegalArgumentException,
                                                     NoSuchElementException,
                                                     TooManyElementException

  Return the optional unique child of an element.

  Parameters:
    `element` - the parent element
    `strict` - true if the element must be present
  Returns:
    the child element or null if it does not exist and strict is false
  Throws:
    `java.lang.IllegalArgumentException` - if an argument is null
    `NoSuchElementException` - if strict is true and the element is not present
    `TooManyElementException` - if more than one element is found

### getUniqueChild

    public static org.w3c.dom.Element getUniqueChild(org.w3c.dom.Element element,
                                                     java.lang.String name,
                                                     boolean strict)
                                              throws java.lang.IllegalArgumentException,
                                                     NoSuchElementException,
                                                     TooManyElementException

  Return an optional child of an element with the specified name.

  Parameters:
    `element` - the parent element
    `name` - the child name
    `strict` - if the child must be present
  Returns:
    the child element or null if it does not exist and strict is set to false
  Throws:
    `java.lang.IllegalArgumentException` - if an argument is null
    `NoSuchElementException` - if strict is true and the element is not present
    `TooManyElementException` - if more than one element is found

### getUniqueChild

    public static org.w3c.dom.Element getUniqueChild(org.w3c.dom.Element element,
                                                     java.lang.String uri,
                                                     java.lang.String name,
                                                     boolean strict)
                                              throws java.lang.IllegalArgumentException,
                                                     NoSuchElementException,
                                                     TooManyElementException

  Return an optional child of an element with the specified name and the optionally specified namespace uri.

  Parameters:
    `element` - the parent element
    `name` - the child name
    `uri` - the child uri
    `strict` - if the child must be present
  Returns:
    the child element or null if it does not exist and strict is set to false
  Throws:
    `java.lang.IllegalArgumentException` - if an argument is null
    `NoSuchElementException` - if strict is true and the element is not present
    `TooManyElementException` - if more than one element is found

### getChildrenIterator

    public static java.util.Iterator<org.w3c.dom.Element> getChildrenIterator(org.w3c.dom.Element element)
                                                                       throws java.lang.IllegalArgumentException

  Return an iterator for all the children of the given element.

  Parameters:
    `element` - the parent element
  Returns:
    an iterator for the designated elements
  Throws:
    `java.lang.IllegalArgumentException` - if the element is null or the name is null

### getChildrenIterator

    public static java.util.Iterator<org.w3c.dom.Element> getChildrenIterator(org.w3c.dom.Element element,
                                                                              java.lang.String name)
                                                                       throws java.lang.IllegalArgumentException

  Return an iterator for all the children of the given element having the specified name.

  Parameters:
    `element` - the parent element
    `name` - the child names
  Returns:
    an iterator for the designated elements
  Throws:
    `java.lang.IllegalArgumentException` - if the element is null or the name is null

### getChildrenIterator

    public static java.util.Iterator<org.w3c.dom.Element> getChildrenIterator(org.w3c.dom.Element element,
                                                                              java.lang.String uri,
                                                                              java.lang.String name)
                                                                       throws java.lang.IllegalArgumentException

  Return an iterator for all the children of the given element having the specified name and the optionally specified namesspace uri.

  Parameters:
    `element` - the parent element
    `uri` - the children uri
    `name` - the children name
  Returns:
    an iterator for the designated elements
  Throws:
    `java.lang.IllegalArgumentException` - if the element is null or the name is null

### getChildren

    public static java.util.List<org.w3c.dom.Element> getChildren(org.w3c.dom.Element element)
                                                           throws java.lang.IllegalArgumentException

  Return all the children of the given element. The collection object can be modified.

  Parameters:
    `element` - the parent element
  Returns:
    a list of elements
  Throws:
    `java.lang.IllegalArgumentException` - if the element is null or the name is null

### getChildren

    public static java.util.List<org.w3c.dom.Element> getChildren(org.w3c.dom.Element element,
                                                                  java.lang.String name)
                                                           throws java.lang.IllegalArgumentException

  Return all the children of the given element having the specified name. The collection object can be modified.

  Parameters:
    `element` - the parent element
    `name` - the child names
  Returns:
    a list of elements
  Throws:
    `java.lang.IllegalArgumentException` - if the element is null or the name is null

### getChildren

    public static java.util.List<org.w3c.dom.Element> getChildren(org.w3c.dom.Element element,
                                                                  java.lang.String uri,
                                                                  java.lang.String name)
                                                           throws java.lang.IllegalArgumentException

  Return all the children of the given element having the optionally specified name and the namespace URI.

  If the URI is specified then the element must have the same URI namespace in order to be included otherwise it will be included. If the URI is specified the name matching will be done against the element local name otherwise it will be done against the element tag name.

  If the name is specified then the element must have the same tag name or the same local name to be retained otherwise it will be included.

  The resulting element collection can be safely modified.

  Parameters:
    `element` - the parent element
    `uri` - the children uri
    `name` - the children name
  Returns:
    a list of elements
  Throws:
    `java.lang.IllegalArgumentException` - if the element is null

### getChildren

    public static <T extends org.w3c.dom.Node> java.util.List<T> getChildren(org.w3c.dom.Node node,
                                                                             XMLTools.Filter<T> filter)
                                                                  throws java.lang.IllegalArgumentException

  Return all the children of the given node that match the provided filter.

  The resulting element collection can be safely modified.

  Parameters:
    `node` - the parent element
    `filter` - the filter
  Returns:
    a list of elements
  Throws:
    `java.lang.IllegalArgumentException` - if the element is null

### byName

    public static XMLTools.Filter<org.w3c.dom.Element> byName(java.lang.String uri,
                                                              java.util.Set<java.lang.String> names)

### byName

    public static XMLTools.Filter<org.w3c.dom.Element> byName(java.lang.String uri,
                                                              java.lang.String name)

### loadXMLProperties

    public static java.util.Properties loadXMLProperties(org.w3c.dom.Element propertiesElt)

### loadXMLProperties

    public static java.util.Properties loadXMLProperties(org.w3c.dom.Document doc)

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 © 2008. All Rights Reserved.