站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JBOSS Portal 2.6 API 英文版文档

XML - JBOSS Portal 2.6 API 英文版文档


org.jboss.portal.common.util
Class XML

java.lang.Object
  extended byorg.jboss.portal.common.util.XML

public class XML
extends java.lang.Object

Utilities for dealing with XML.

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

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
          .
private static javax.xml.parsers.DocumentBuilderFactory buildFactory
          Document builder factory.
private static java.util.Properties DEFAULT_FORMAT
          Default output format which is : no xml declaration, no document type, indent.
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
          .
private static javax.xml.transform.TransformerFactory transformerFactory
          Transformer factory.
static java.lang.String XML_LANG_NAMESPACE_URI
          Namespace URI for XML lang.
 
Constructor Summary
private XML()
          prevent instantiation
 
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.
private static java.util.Properties createFormat(boolean omitXMLDeclaration, boolean standalone, boolean indented, java.lang.String encoding)
           
static java.util.List 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.Iterator 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 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.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)
           
private static java.lang.String toString(org.w3c.dom.Document doc, java.util.Properties format)
          Converts an document to a String representation.
static java.lang.String toString(org.w3c.dom.Element element)
           
private static java.lang.String toString(org.w3c.dom.Element element, java.util.Properties properties)
          Converts an element to a String representation.
 
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

buildFactory

private static final javax.xml.parsers.DocumentBuilderFactory buildFactory
Document builder factory.


transformerFactory

private static final javax.xml.transform.TransformerFactory transformerFactory
Transformer factory.


DEFAULT_FORMAT

private static java.util.Properties DEFAULT_FORMAT
Default output format which is : no xml declaration, no document type, indent.


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
Constructor Detail

XML

private XML()
prevent instantiation

Method Detail

getDocumentBuilderFactory

public static javax.xml.parsers.DocumentBuilderFactory getDocumentBuilderFactory()
Return the builder factory.


createFormat

private static java.util.Properties createFormat(boolean omitXMLDeclaration,
                                                 boolean standalone,
                                                 boolean indented,
                                                 java.lang.String encoding)

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)

toString

private static java.lang.String toString(org.w3c.dom.Element element,
                                         java.util.Properties properties)
                                  throws javax.xml.parsers.ParserConfigurationException,
                                         javax.xml.transform.TransformerException
Converts an element to a String representation.

Throws:
javax.xml.parsers.ParserConfigurationException
javax.xml.transform.TransformerException

toString

private static java.lang.String toString(org.w3c.dom.Document doc,
                                         java.util.Properties format)
                                  throws javax.xml.transform.TransformerException
Converts an document to a String representation.

Throws:
javax.xml.transform.TransformerException

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

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

getChildrenIterator

public static java.util.Iterator 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

getChildren

public static java.util.List 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