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

XML - JBOSS Portal 2.2 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.


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 org.w3c.dom.Node addDirectiveToXSL(org.w3c.dom.Document xslDom, java.lang.String directiveName, java.lang.String attributeName, java.lang.String attributeValue)
          Add an xsl:import or xsl:include etc.
static org.w3c.dom.Node addDirectiveToXSLBeforeSibling(org.w3c.dom.Node sibling, java.lang.String directiveName, java.lang.String attributeName, java.lang.String attributeValue)
          Add an xsl:import or xsl:include node to an existing xsl style sheet (represented as DOM) before the passed sibling node.
static org.w3c.dom.Node addNodeAfterSibling(org.w3c.dom.Node siblingNode, java.lang.String nodeName, org.w3c.dom.Node content)
          create a new Element with nodeName and insert it after the siblingNode (same level); if the node name is null, insert the content node after the sibling node; both Nodes need to be part of the same document
static org.w3c.dom.Node addNodeAfterSibling(org.w3c.dom.Node siblingNode, java.lang.String nodeName, org.w3c.dom.Node content, boolean contentIsLocal)
          create a new Element with nodeName and insert it after the siblingNode (same level); if the node name is null, insert the content node after the sibling node
static org.w3c.dom.Node addNodeBeforeSibling(org.w3c.dom.Node siblingNode, java.lang.String nodeName, org.w3c.dom.Node content)
          create a new Element with nodeName and insert it before the siblingNode (same level)
static org.w3c.dom.Node addNodeBeforeSibling(org.w3c.dom.Node siblingNode, java.lang.String nodeName, org.w3c.dom.Node content, boolean contentIsLocal)
          Create a new Element with nodeName and insert it before the siblingNode (same level).
static org.w3c.dom.Element appendChildElement(org.w3c.dom.Document document, org.w3c.dom.Element parent, java.lang.String key)
          Create and adds a new element to parent with a tag of key.
static org.w3c.dom.Node appendChildNode(org.w3c.dom.Node parentNode, org.w3c.dom.Node contentNode)
          import a node into the current document directly under the passed parent Node
static org.w3c.dom.Node appendChildNode(org.w3c.dom.Node parentNode, org.w3c.dom.Node contentNode, boolean contentIsLocal)
          import a node into the current document directly under the passed parent Node
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 void copyAttributes(org.w3c.dom.Element src, org.w3c.dom.Element dest)
          Copies all of the attributes from the src Element to the dest Element.
static org.w3c.dom.Attr createAttribute(org.w3c.dom.Document doc, java.lang.String attributeName, java.lang.String attributeValue)
          create an attribute standalone (not added to any node)
static org.w3c.dom.Attr createAttribute(org.w3c.dom.Element el, java.lang.String attributeName, java.lang.String attributeValue)
          create an attribute and add it to the Node provided
static org.w3c.dom.Node createCDATANode(org.w3c.dom.Node parentNode, java.lang.String nodeName, java.lang.String content)
          create a CDATA section as a child to the provided parentNode In case the content is null, a child node without content will be created, using createChildNode()
static org.w3c.dom.Node createChildNode(org.w3c.dom.Node parentNode, java.lang.String nodeName)
          Create a child node and append it to the provided parent node
static org.w3c.dom.Node createChildNode(org.w3c.dom.Node parentNode, java.lang.String nodeName, org.w3c.dom.Node contentNode)
          create a child node (to parentNode) and populate it with the delivered content (if != null)
static org.w3c.dom.Node createChildNode(org.w3c.dom.Node parentNode, java.lang.String nodeName, org.w3c.dom.Node contentNode, boolean contentIsLocal)
          create a child node (to parentNode) and populate it with the delivered content (if != null)
static org.w3c.dom.Document createDocument()
          create a new org.w3c.dom.Document with validation turned off and name space awareness turned on
static org.w3c.dom.Document createDocument(byte[] bytes)
          create a Document from a byte[]
static org.w3c.dom.Document createDocument(org.xml.sax.InputSource inputSrc, boolean isValidating, boolean isNamespaceAware, org.xml.sax.ErrorHandler errorHandler, org.xml.sax.EntityResolver entityResolver)
          Creates a new Document from an InputSource allowing the validation, namespace, error handler and entity resolver to be set.
static org.w3c.dom.Document createDocument(java.io.InputStream stream)
          create a Document from a String representation (with name space awareness on and validation off)
static org.w3c.dom.Document createDocument(java.io.InputStream stream, java.lang.String encoding, boolean validation, boolean namespace)
          create a Document from a stream representation of the XML content use the requested char-set encoding, validation and name space awareness
static org.w3c.dom.Document createDocument(java.io.Reader reader, boolean validation, boolean namespace)
          create a Document from a reader representation of the XML content use the requested validation and name space awareness
static org.w3c.dom.Document createDocument(java.lang.String strDoc)
          Creates a Document from a String representing a valid XML document (no validation, but name space aware)
static org.w3c.dom.Document createDocument(java.net.URL documentURL)
          create a Document from a URL (get the content from the URL); name space aware, but no validation
static org.w3c.dom.Node createDocumentRootNode(org.w3c.dom.Document parentDocument, java.lang.String nodeName, org.w3c.dom.Node contentNode)
          create a child node (to parentDocument) and populate it with the delivered content (if != null)
static org.w3c.dom.Node createDocumentRootNode(org.w3c.dom.Document parentDocument, java.lang.String nodeName, org.w3c.dom.Node contentNode, boolean contentIsLocal)
          create a child node (to parentDocument) and populate it with the delivered content (if != null).
static org.w3c.dom.Node createNode(org.w3c.dom.Document document, java.lang.String nodeName, org.w3c.dom.Node contentNode)
          create a Node standalone (not added to any parent)
static org.w3c.dom.Node createNode(org.w3c.dom.Document document, java.lang.String nodeName, org.w3c.dom.Node contentNode, boolean contentIsLocal)
          create a Node standalone (not added to any parent)
static java.util.Properties createOutputProperties(boolean omitXMLDeclaration, boolean enableIndenting, java.lang.String[] elements)
          create the output properties for an xsl style sheet (like
static org.w3c.dom.Node createTextNode(org.w3c.dom.Document doc, org.w3c.dom.Node parentNode, java.lang.String nodeName, java.lang.String content)
          create a text node

To create a stand-alone node, pass null for parentNode.

static org.w3c.dom.Node createTextNode(org.w3c.dom.Node parentNode, java.lang.String nodeName, java.lang.String content)
          Create a text node as a child of another node.
static org.w3c.dom.Attr getAttribute(java.lang.String attributeName, org.w3c.dom.Node node)
          get an attribute of a node (if present)
static java.lang.String getAttributeValue(java.lang.String attributeName, org.w3c.dom.Node node)
          get the value of an attribute of a node (if present)
static javax.xml.parsers.DocumentBuilder getBuilder()
          get a javax.xml.parsers.DocumentBuilder from the javax.xml.parsers.DocumentBuilderFactory validation turned off and name space awareness turned on if you need a DocumentBuilder with different features, use the getBuilder(boolean validation, boolean nameSpaceAware) method
static javax.xml.parsers.DocumentBuilder getBuilder(boolean validation, boolean nameSpaceAware)
          get a javax.xml.parsers.DocumentBuilder from the javax.xml.parsers.DocumentBuilderFactory Using this method will cache the DocumentBuilder in thread local storage after the fist hit
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 javax.xml.parsers.DocumentBuilderFactory getDocumentBuilderFactory()
          Return the builder factory.
static java.lang.String getElementBodyText(org.w3c.dom.Node parentNode)
          get the text from an elements body example get 'hello world' from hello world
static java.lang.String getElementValue(org.w3c.dom.Node node)
          entities are often considered serperate text nodes.
static java.lang.String getFirstElementValue(org.w3c.dom.Node node, java.lang.String element)
          Returns the value of the first occurence of the child element specified for the node specified
static javax.xml.parsers.SAXParserFactory getSAXParserFactory(boolean validation, boolean nameSpaceAware)
          get a SAXParserFactory (from cache) for the validation and name space aware properties
static org.w3c.dom.Node getSelectedNode(org.apache.xpath.CachedXPathAPI xpath, org.w3c.dom.Node contextNode, java.lang.String str)
          Use an XPath string to select a single node.
static org.w3c.dom.Node getSelectedNode(org.w3c.dom.Node contextNode, java.lang.String str)
          Use an XPath string to select a single node.
static org.w3c.dom.NodeList getSelectedNodes(org.w3c.dom.Node contextNode, java.lang.String str)
          Use an XPath string to select a nodelist.
static javax.xml.transform.Templates getTemplates(javax.xml.transform.Source source)
          compile the provided style sheet into templates
static javax.xml.transform.Transformer getTransformer()
          get a new Transformer from the TransformerFactory with indent turned on
static javax.xml.transform.Transformer getTransformer(org.w3c.dom.Document doc)
          get a new Transformer for the passed Document (the xsl) from the TransformerFactory with indent turned on
static javax.xml.transform.Transformer getTransformer(java.util.Properties transProps)
          get a new Transformer from the TransformerFactory with the passed output properties
static javax.xml.transform.Transformer getTransformer(javax.xml.transform.Source strSource)
          get a new Transformer for the passed Source (the xsl) from the TransformerFactory with indent turned on
static javax.xml.transform.Transformer getTransformer(javax.xml.transform.Templates templates)
          get a new Transformer for the passed compiled xsl template (with indent turned on)
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 void importChildNodes(org.w3c.dom.Node src, org.w3c.dom.Node dest)
          Deep copies the src Node's children to the dest Node.
static void moveChildNodes(org.w3c.dom.Node src, org.w3c.dom.Node dest)
          Move all child nodes or src to the dest node.
static void saxParse(org.xml.sax.InputSource source, org.xml.sax.helpers.DefaultHandler handler, boolean validation, boolean nameSpaceAware)
          parse the document from an InputStream with the provided handler
static void saxParse(java.io.InputStream in, org.xml.sax.helpers.DefaultHandler handler, boolean validation, boolean nameSpaceAware)
          parse the document from an InputStream with the provided handler
static java.lang.String serialize(org.w3c.dom.Node doc)
          serialize a Document to String (using a Transformer) This call uses a javax.xml.transform.Transformer, and it's output encoding to convert the content to a String (default is UTF-8).
static void serialize(org.w3c.dom.Node doc, java.io.OutputStream output)
          serialize a Document to the provided OutputStream (using a Transformer)
static void serialize(org.w3c.dom.Node doc, java.io.OutputStream output, javax.xml.transform.Transformer transformer)
          serialize a Document to the provided OutputStream (using the passed Transformer)
static java.lang.String serialize(org.w3c.dom.Node doc, javax.xml.transform.Transformer transformer)
          serialize a Document to String (using the passed Transformer) This call uses the transformer's output encoding to convert the content to a String
static void serialize(org.w3c.dom.Node doc, java.io.Writer writer)
          serialize a Document to the provided Writer (using a Transformer)
static void serialize(org.w3c.dom.Node doc, java.io.Writer writer, javax.xml.transform.Transformer transformer)
          serialize a Document to the provided Writer (using a Transformer) This call uses the transformer's output encoding to convert the content to a String (default is UTF-8)
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, java.util.Properties format)
          Converts an document to a String representation.
static java.lang.String toString(org.w3c.dom.Element element)
           
static java.lang.String toString(org.w3c.dom.Element element, java.util.Properties properties)
          Converts an element to a String representation.
static void xslTransform(org.w3c.dom.Document contentDom, org.w3c.dom.Document styleDom, java.io.Writer out)
          Transforms an xml with the provided xsl document and writes it to the writer.
static java.lang.String xslTransform(org.w3c.dom.Document contentDom, javax.xml.transform.Transformer transformer, java.io.OutputStream out)
          Transforms an xml document with the provided xsl style (compiled version) and write it to the provided writer
static void xslTransform(org.w3c.dom.Document contentDom, javax.xml.transform.Transformer transformer, java.io.Writer writer)
          Transforms an xml document with the provided xsl style (compiled version) and write it to the provided writer
 
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 final 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

public static final 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

public static final 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.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

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

getBuilder

public static javax.xml.parsers.DocumentBuilder getBuilder()
                                                    throws javax.xml.parsers.ParserConfigurationException
get a javax.xml.parsers.DocumentBuilder from the javax.xml.parsers.DocumentBuilderFactory validation turned off and name space awareness turned on if you need a DocumentBuilder with different features, use the getBuilder(boolean validation, boolean nameSpaceAware) method

Returns:
DocumentBuilder
Throws:
javax.xml.parsers.ParserConfigurationException - if the parser is not configured
See Also:
getBuilder(boolean, boolean)

getBuilder

public static javax.xml.parsers.DocumentBuilder getBuilder(boolean validation,
                                                           boolean nameSpaceAware)
                                                    throws javax.xml.parsers.ParserConfigurationException
get a javax.xml.parsers.DocumentBuilder from the javax.xml.parsers.DocumentBuilderFactory Using this method will cache the DocumentBuilder in thread local storage after the fist hit

Parameters:
validation - true if validation should be turned on, otherwise use false
nameSpaceAware - true if name space awareness should be turned on, otherwise use false
Returns:
a DocumentBuilder to create Documents
Throws:
javax.xml.parsers.ParserConfigurationException - if the underlying parser does

createDocument

public static org.w3c.dom.Document createDocument()
                                           throws javax.xml.parsers.ParserConfigurationException
create a new org.w3c.dom.Document with validation turned off and name space awareness turned on

Returns:
the created org.w3c.dom.Document
Throws:
javax.xml.parsers.ParserConfigurationException - if the underlying parser does

createDocument

public static org.w3c.dom.Document createDocument(java.lang.String strDoc)
                                           throws org.w3c.dom.DOMException,
                                                  java.io.IOException,
                                                  org.xml.sax.SAXException,
                                                  javax.xml.parsers.ParserConfigurationException
Creates a Document from a String representing a valid XML document (no validation, but name space aware)

Parameters:
strDoc - the string representing the xml
Returns:
the created Document
Throws:
org.w3c.dom.DOMException - if the provided string does not represent a valid xml document
java.io.IOException - on read problems
org.xml.sax.SAXException - on parse problems
javax.xml.parsers.ParserConfigurationException - if the underlying parser does
java.lang.IllegalArgumentException - if the passed string is null

createDocument

public static org.w3c.dom.Document createDocument(java.io.InputStream stream)
                                           throws org.w3c.dom.DOMException,
                                                  java.io.IOException,
                                                  org.xml.sax.SAXException,
                                                  javax.xml.parsers.ParserConfigurationException
create a Document from a String representation (with name space awareness on and validation off)

Parameters:
stream - the InputStream that represents the XML Content
Returns:
a Document representing the same content
Throws:
org.w3c.dom.DOMException - if the InputSource does not represent a valid XML document
java.io.IOException - on read problems
org.xml.sax.SAXException - on parse problems
javax.xml.parsers.ParserConfigurationException - if the underlying parser does
java.lang.IllegalArgumentException - if the provided InputSource is null

createDocument

public static org.w3c.dom.Document createDocument(byte[] bytes)
                                           throws org.w3c.dom.DOMException,
                                                  java.io.IOException,
                                                  org.xml.sax.SAXException,
                                                  javax.xml.parsers.ParserConfigurationException
create a Document from a byte[]

Parameters:
bytes - the bytes that represents the XML Content
Returns:
a Document representing the same content
Throws:
org.w3c.dom.DOMException - if the InputSource does not represent a valid XML document
java.io.IOException - on read problems
org.xml.sax.SAXException - on parse problems
javax.xml.parsers.ParserConfigurationException - if the underlying parser does
java.lang.IllegalArgumentException - if the provided InputSource is null

createDocument

public static org.w3c.dom.Document createDocument(java.io.InputStream stream,
                                                  java.lang.String encoding,
                                                  boolean validation,
                                                  boolean namespace)
                                           throws org.w3c.dom.DOMException,
                                                  java.io.IOException,
                                                  org.xml.sax.SAXException,
                                                  javax.xml.parsers.ParserConfigurationException
create a Document from a stream representation of the XML content use the requested char-set encoding, validation and name space awareness

Parameters:
stream - the stream (InputStream,...) to represent the XML
encoding - the Char encoding that should be used to read from the stream
validation - use validation (true), or not (false)
namespace - use namespace awareness (true) , or not (false)
Returns:
a Document representing the same XML content in form of a DOM
Throws:
org.w3c.dom.DOMException - on Document problems
java.io.IOException - on read problems
org.xml.sax.SAXException - on parse problems
javax.xml.parsers.ParserConfigurationException - if the underlying parser does
java.lang.IllegalArgumentException - if the provided InputSource or encoding is null

createDocument

public static org.w3c.dom.Document createDocument(java.io.Reader reader,
                                                  boolean validation,
                                                  boolean namespace)
                                           throws org.w3c.dom.DOMException,
                                                  java.io.IOException,
                                                  org.xml.sax.SAXException,
                                                  javax.xml.parsers.ParserConfigurationException
create a Document from a reader representation of the XML content use the requested validation and name space awareness

Parameters:
reader - the reader pointing to the 'raw' xml
namespace - use namespace awareness (true) , or not (false)
validation - use validation (true), or not (false)
Returns:
a Document representing the same XML content in form of a DOM
Throws:
org.w3c.dom.DOMException - on Document problems
java.io.IOException - if the reader doesn't allow successfull access
org.xml.sax.SAXException - on parsing problems
javax.xml.parsers.ParserConfigurationException - if the underlying parser does

createDocument

public static org.w3c.dom.Document createDocument(java.net.URL documentURL)
                                           throws java.io.IOException,
                                                  org.xml.sax.SAXException,
                                                  javax.xml.parsers.ParserConfigurationException
create a Document from a URL (get the content from the URL); name space aware, but no validation

Parameters:
documentURL - the URL pointing to the Document
Returns:
a Document representing the document content
Throws:
java.io.IOException - on read problems
org.xml.sax.SAXException - on parse problems
javax.xml.parsers.ParserConfigurationException - if the underlying parser does
java.lang.IllegalArgumentException - if the provided URL is null

createDocument

public static org.w3c.dom.Document createDocument(org.xml.sax.InputSource inputSrc,
                                                  boolean isValidating,
                                                  boolean isNamespaceAware,
                                                  org.xml.sax.ErrorHandler errorHandler,
                                                  org.xml.sax.EntityResolver entityResolver)
                                           throws org.w3c.dom.DOMException,
                                                  java.io.IOException,
                                                  org.xml.sax.SAXException,
                                                  javax.xml.parsers.ParserConfigurationException
Creates a new Document from an InputSource allowing the validation, namespace, error handler and entity resolver to be set.

Parameters:
inputSrc - the InputSource representing the xml
isValidating - the boolean determining if validating is used against the xml
isNamespaceAware - the boolean determining if the NameSpaceAware feature is set
errorHandler - the ErrorHandler to be used if supplied
entityResolver - the entityResolver to be used if supplied
Returns:
a Document
Throws:
org.w3c.dom.DOMException - on Document problems
java.io.IOException - on read problems
org.xml.sax.SAXException - on parse problems
javax.xml.parsers.ParserConfigurationException - if the underlying parser does
java.lang.IllegalArgumentException - if the provided InputSource is null

createDocumentRootNode

public static org.w3c.dom.Node createDocumentRootNode(org.w3c.dom.Document parentDocument,
                                                      java.lang.String nodeName,
                                                      org.w3c.dom.Node contentNode)
create a child node (to parentDocument) and populate it with the delivered content (if != null)

Parameters:
parentDocument - the Document that will receive the new Element and the content
nodeName - the name of the Element to create
contentNode - the Node that will be appended as a child to the created Element
Returns:
the created Node
Throws:
java.lang.IllegalArgumentException - if the document or the node name is null

createDocumentRootNode

public static org.w3c.dom.Node createDocumentRootNode(org.w3c.dom.Document parentDocument,
                                                      java.lang.String nodeName,
                                                      org.w3c.dom.Node contentNode,
                                                      boolean contentIsLocal)
create a child node (to parentDocument) and populate it with the delivered content (if != null).

Parameters:
parentDocument - the Document that will receive the new Element and the content
nodeName - the name of the Element to create
contentNode - the Node that will be imported (if external) or appended (if local) as a child to the created Element (incl. subtree)
contentIsLocal - a boolean indicating wether the contentNode is external to the document and has to be imported (false), or if it can be appended (true)
Returns:
the created Element
Throws:
java.lang.IllegalArgumentException - if the document or the node name is null

createNode

public static org.w3c.dom.Node createNode(org.w3c.dom.Document document,
                                          java.lang.String nodeName,
                                          org.w3c.dom.Node contentNode)
create a Node standalone (not added to any parent)

Parameters:
document - Document used to create the Element (not null!)
nodeName - name of the node to be created (not null!)
contentNode - content in form of a Node to be appended as child (if not null) ; including the subtree
Returns:
the newly created Node
Throws:
java.lang.IllegalArgumentException - if the document or the node name is null

createNode

public static org.w3c.dom.Node createNode(org.w3c.dom.Document document,
                                          java.lang.String nodeName,
                                          org.w3c.dom.Node contentNode,
                                          boolean contentIsLocal)
create a Node standalone (not added to any parent)

Parameters:
document - Document used to create the Element (not null!)
nodeName - name of the node to be created (not null!)
contentNode - content in form of a Node to be imported or appended as child (if not null)
contentIsLocal - a boolean indicating wether the contentNode is external to the document and has to be imported (false), or if it can be appended (true)
Returns:
the newly created Node
Throws:
java.lang.IllegalArgumentException - if the document or the node name is null

createChildNode

public static org.w3c.dom.Node createChildNode(org.w3c.dom.Node parentNode,
                                               java.lang.String nodeName,
                                               org.w3c.dom.Node contentNode)
create a child node (to parentNode) and populate it with the delivered content (if != null)

Parameters:
parentNode - the parent Node (not null!)
nodeName - the name for the new Element (not null!)
contentNode - org.w3c.dom.Node that contains the content to be appended (incl. subtree) to the parent Document (or null)
Returns:
the newly created Node
Throws:
java.lang.IllegalArgumentException - if the parent node or the node name is null

createChildNode

public static org.w3c.dom.Node createChildNode(org.w3c.dom.Node parentNode,
                                               java.lang.String nodeName,
                                               org.w3c.dom.Node contentNode,
                                               boolean contentIsLocal)
create a child node (to parentNode) and populate it with the delivered content (if != null)

Parameters:
parentNode - the parent Node (not null!)
nodeName - the name for the new Element (not null!)
contentNode - org.w3c.dom.Node that contains the content to be imported (incl. subtree) or appended (if local) to the parent Document (or null)
contentIsLocal - a boolean indicating wether the contentNode is external to the document and has to be imported (false), or if it can be appended (true)
Returns:
the newly created Node
Throws:
java.lang.IllegalArgumentException - if the parent node or the node name is null

createChildNode

public static org.w3c.dom.Node createChildNode(org.w3c.dom.Node parentNode,
                                               java.lang.String nodeName)
Create a child node and append it to the provided parent node

Parameters:
nodeName - the name for the new node
parentNode - the parent org.w3c.dom.Node that will receive the child
Returns:
the newly created Node
Throws:
java.lang.IllegalArgumentException - if the parent node or the node name is null

createTextNode

public static org.w3c.dom.Node createTextNode(org.w3c.dom.Document doc,
                                              org.w3c.dom.Node parentNode,
                                              java.lang.String nodeName,
                                              java.lang.String content)
create a text node

To create a stand-alone node, pass null for parentNode. Otherwise the node will be created as a child of parentNode.

Parameters:
doc - the Document to contain the new text node (not null!)
parentNode - the Node under which the new text node should be placed (or null)
nodeName - the name of the new text node (not null!)
content - the text itself
Returns:
the newly created Node
Throws:
java.lang.IllegalArgumentException - if either the document, or the node name and the parent node are null

createTextNode

public static org.w3c.dom.Node createTextNode(org.w3c.dom.Node parentNode,
                                              java.lang.String nodeName,
                                              java.lang.String content)
Create a text node as a child of another node.

Parameters:
parentNode - the Node under which the new text node should be placed (not null!)
nodeName - the name of the new text node (not null!)
content - the text itself
Returns:
the newly created Node
Throws:
java.lang.IllegalArgumentException - if the parent node is null

createAttribute

public static org.w3c.dom.Attr createAttribute(org.w3c.dom.Element el,
                                               java.lang.String attributeName,
                                               java.lang.String attributeValue)
create an attribute and add it to the Node provided

Parameters:
el - the element that will receive the attribute (not null!)
attributeName - name of the attribute to be created (not null!)
attributeValue - value of the attribute to be created
Returns:
the created attribute as Attr
Throws:
java.lang.IllegalArgumentException - if the element or the attribute name is null

createAttribute

public static org.w3c.dom.Attr createAttribute(org.w3c.dom.Document doc,
                                               java.lang.String attributeName,
                                               java.lang.String attributeValue)
create an attribute standalone (not added to any node)

Parameters:
doc - the Document used to create the attribute
attributeName - name of the attribute to be created
attributeValue - value of the attribute to be created
Returns:
the Attribute as org.w3c.dom.Attr
Throws:
java.lang.IllegalArgumentException - if the document or the attribute name is null

getAttributeValue

public static java.lang.String getAttributeValue(java.lang.String attributeName,
                                                 org.w3c.dom.Node node)
get the value of an attribute of a node (if present)

Parameters:
attributeName - the name of the attribute you want to get
node - the Node where the attribute lives
Returns:
the value of the attribute, or null if not present
Throws:
java.lang.IllegalArgumentException - if the attribute name or the node is null

getAttribute

public static org.w3c.dom.Attr getAttribute(java.lang.String attributeName,
                                            org.w3c.dom.Node node)
get an attribute of a node (if present)

Parameters:
attributeName - the name of the attribute you want to get
node - the Node where the attribute lives
Returns:
the attribute, or null if not present on the node
Throws:
java.lang.IllegalArgumentException - if the attribute name or the node is null

getElementBodyText

public static java.lang.String getElementBodyText(org.w3c.dom.Node parentNode)
get the text from an elements body example get 'hello world' from hello world

Parameters:
parentNode - the node that contains text
Returns:
the text inside the element and end element tags if the node is a text node, otherwise an empty string
Throws:
org.w3c.dom.DOMException - if the undelying DOM api does

createCDATANode

public static org.w3c.dom.Node createCDATANode(org.w3c.dom.Node parentNode,
                                               java.lang.String nodeName,
                                               java.lang.String content)
create a CDATA section as a child to the provided parentNode In case the content is null, a child node without content will be created, using createChildNode()

Parameters:
parentNode - Node (parent) of the element to be created (not null!)
nodeName - the name you want to give your Node (or null if the textnode should be appended to the parent node directly)
content - the content of the node (the text that will be wrapped in a CDATA section)
Returns:
the org.w3c.dom.Node that was created
Throws:
java.lang.IllegalArgumentException - if the parent node is null
See Also:
createChildNode(org.w3c.dom.Node,String)

addNodeBeforeSibling

public static org.w3c.dom.Node addNodeBeforeSibling(org.w3c.dom.Node siblingNode,
                                                    java.lang.String nodeName,
                                                    org.w3c.dom.Node content)
create a new Element with nodeName and insert it before the siblingNode (same level)

Parameters:
siblingNode - the node that will be used as reference; the new element will be inserted before this node
nodeName - the name of the element to create
content - any subtree that will be appended as child of the new element (if != null)
Returns:
the newly created element as a Node
Throws:
java.lang.IllegalArgumentException - if the sibling node or the node name is null

addNodeBeforeSibling

public static org.w3c.dom.Node addNodeBeforeSibling(org.w3c.dom.Node siblingNode,
                                                    java.lang.String nodeName,
                                                    org.w3c.dom.Node content,
                                                    boolean contentIsLocal)
Create a new Element with nodeName and insert it before the siblingNode (same level). If the node name is null, insert the content node before the sibling node. Best way to use this method is with either a nodeName or content, but not both.

Parameters:
siblingNode - the node that will be used as reference; the new element will be inserted before this node
nodeName - the name of the element to create (or null; if null, content needs to be not null!)
content - any subtree that will be imported or appended (if local) as child of the new element (if != null)
contentIsLocal - a boolean indicating wether the contentNode is external to the document and has to be imported (false), or if it can be appended (true)
Returns:
the newly created element as a Node
Throws:
java.lang.IllegalArgumentException - if the sibling node is null or the node name and the content is null

addNodeAfterSibling

public static org.w3c.dom.Node addNodeAfterSibling(org.w3c.dom.Node siblingNode,
                                                   java.lang.String nodeName,
                                                   org.w3c.dom.Node content)
create a new Element with nodeName and insert it after the siblingNode (same level); if the node name is null, insert the content node after the sibling node; both Nodes need to be part of the same document

Parameters:
siblingNode - the node that will be used as reference; the new element will be inserted after this node
nodeName - the name of the element to create (or null; if null, content needs to be not null!)
content - any subtree that will be imported or appended (if local) as child of the new element (if != null)
Returns:
the newly created element as a Node
Throws:
java.lang.IllegalArgumentException - if the sibling node is null or the node name and the content is null

addNodeAfterSibling

public static org.w3c.dom.Node addNodeAfterSibling(org.w3c.dom.Node siblingNode,
                                                   java.lang.String nodeName,
                                                   org.w3c.dom.Node content,
                                                   boolean contentIsLocal)
create a new Element with nodeName and insert it after the siblingNode (same level); if the node name is null, insert the content node after the sibling node

Parameters:
siblingNode - the node that will be used as reference; the new element will be inserted after this node
nodeName - the name of the element to create (or null; if null, content needs to be not null!)
content - any subtree that will be imported or appended (if local) as child of the new element (if != null)
contentIsLocal - a boolean indicating wether the contentNode is external to the document and has to be imported (false), or if it can be appended (true)
Returns:
the newly created element as a Node
Throws:
java.lang.IllegalArgumentException - if the sibling node is null or the node name and the content is null

appendChildElement

public static org.w3c.dom.Element appendChildElement(org.w3c.dom.Document document,
                                                     org.w3c.dom.Element parent,
                                                     java.lang.String key)
Create and adds a new element to parent with a tag of key.

Parameters:
document - xml document to which element will be added
parent - Element inside of which element of tag "key" will go.
key - String that becomes the appended element.
Returns:
new element appended to parent.

appendChildNode

public static org.w3c.dom.Node appendChildNode(org.w3c.dom.Node parentNode,
                                               org.w3c.dom.Node contentNode)
import a node into the current document directly under the passed parent Node

Parameters:
parentNode - the Node under which the content should be placed (not null!)
contentNode - the Node (not null!) that will be imported as a child to the created Node (incl. subtree)
Returns:
the Node representing the imported content in the current dom
Throws:
java.lang.IllegalArgumentException - if the parent node or the content node is null

appendChildNode

public static org.w3c.dom.Node appendChildNode(org.w3c.dom.Node parentNode,
                                               org.w3c.dom.Node contentNode,
                                               boolean contentIsLocal)
import a node into the current document directly under the passed parent Node

Parameters:
parentNode - the Node under which the content should be placed (not null!)
contentNode - the Node (not null!) that will be imported as a child to the created Node (incl. subtree)
contentIsLocal - a boolean indicating wether the contentNode is external to the document and has to be imported (false), or if it can be appended (true)
Returns:
the Node representing the imported content in the current dom (or the passed in contentNode if it's local)
Throws:
java.lang.IllegalArgumentException - if the parent node or the content node is null

importChildNodes

public static void importChildNodes(org.w3c.dom.Node src,
                                    org.w3c.dom.Node dest)
Deep copies the src Node's children to the dest Node. It is assumed that the src and dest node exist in different Documents, and so the nodes are first imported into the dest doc before adding them.

Parameters:
src - Node in Document A that should have all it's children copied.
dest - Node in Document B that is the destination of the copy from the src node.
Throws:
java.lang.IllegalArgumentException - if the provided nodes are null

moveChildNodes

public static void moveChildNodes(org.w3c.dom.Node src,
                                  org.w3c.dom.Node dest)
Move all child nodes or src to the dest node. It is assumed that both nodes are in the same document

Parameters:
src - Node that should have all it's children removed.
dest - Node that is the destination of the move from the src node.
Throws:
java.lang.IllegalArgumentException - if the provided nodes are null

createOutputProperties

public static java.util.Properties createOutputProperties(boolean omitXMLDeclaration,
                                                          boolean enableIndenting,
                                                          java.lang.String[] elements)
create the output properties for an xsl style sheet (like )

Parameters:
omitXMLDeclaration - omit-xml-declaration 'yes' or 'no'
enableIndenting - indent 'yes' or 'no'
elements - cdata-section-elements will be converted to a space separated list
Returns:
the properties object to pass to the Transformer
See Also:
#setOutputProperties(Properties), OutputKeys, Properties

serialize

public static void serialize(org.w3c.dom.Node doc,
                             java.io.OutputStream output)
                      throws java.io.IOException,
                             javax.xml.transform.TransformerConfigurationException,
                             javax.xml.transform.TransformerException
serialize a Document to the provided OutputStream (using a Transformer)

Parameters:
doc - Document (-fragment) to be serialized
output - the OutputStream to write to
Throws:
java.io.IOException - on read problems
javax.xml.transform.TransformerConfigurationException - on parser configuration problems
javax.xml.transform.TransformerException - on trandformation problems
java.lang.IllegalArgumentException - if the output stream or the document is null

serialize

public static void serialize(org.w3c.dom.Node doc,
                             java.io.OutputStream output,
                             javax.xml.transform.Transformer transformer)
                      throws java.io.IOException,
                             javax.xml.transform.TransformerConfigurationException,
                             javax.xml.transform.TransformerException
serialize a Document to the provided OutputStream (using the passed Transformer)

Parameters:
doc - Document (-fragment) to be serialized
output - the OutputStream to write to
transformer - the transformer to use
Throws:
java.io.IOException - on read problems
javax.xml.transform.TransformerConfigurationException - on transformer configuration problems
javax.xml.transform.TransformerException - on trnaformation problems
java.lang.IllegalArgumentException - if the output stream or the document or the transformer is null

serialize

public static void serialize(org.w3c.dom.Node doc,
                             java.io.Writer writer)
                      throws java.io.IOException,
                             javax.xml.transform.TransformerConfigurationException,
                             javax.xml.transform.TransformerException
serialize a Document to the provided Writer (using a Transformer)

Parameters:
doc - Document (-fragment) to be serialized
writer - the writer to write to
Throws:
java.io.IOException - on read problems
javax.xml.transform.TransformerConfigurationException - on transformer configuration problems
javax.xml.transform.TransformerException - on trnaformation problems
java.lang.IllegalArgumentException - if the document or the writer is null

serialize

public static void serialize(org.w3c.dom.Node doc,
                             java.io.Writer writer,
                             javax.xml.transform.Transformer transformer)
                      throws java.io.IOException,
                             javax.xml.transform.TransformerConfigurationException,
                             javax.xml.transform.TransformerException
serialize a Document to the provided Writer (using a Transformer) This call uses the transformer's output encoding to convert the content to a String (default is UTF-8)

Parameters:
doc - Document (-fragment) to be serialized
writer - the writer to write to
transformer - the transformer to use
Throws:
java.io.IOException - on read problems
javax.xml.transform.TransformerConfigurationException - on transformer configuration problems
javax.xml.transform.TransformerException - on trnaformation problems
java.lang.IllegalArgumentException - if the document or the writer or the transformer is null

serialize

public static java.lang.String serialize(org.w3c.dom.Node doc)
                                  throws java.io.IOException,
                                         javax.xml.transform.TransformerConfigurationException,
                                         javax.xml.transform.TransformerException
serialize a Document to String (using a Transformer) This call uses a javax.xml.transform.Transformer, and it's output encoding to convert the content to a String (default is UTF-8). If you want to use a different encoding, get a transformer via #getTransformer(Properties) and set the output property "encoding" to the desired one, then use #serialize(Node, Transformer)

Parameters:
doc - Document (-fragment) to be serialized
Returns:
the String representation of the Document
Throws:
java.io.IOException - on read problems
javax.xml.transform.TransformerConfigurationException - on transformer configuration problems
javax.xml.transform.TransformerException - on trnaformation problems
java.lang.IllegalArgumentException - if the document is null

serialize

public static java.lang.String serialize(org.w3c.dom.Node doc,
                                         javax.xml.transform.Transformer transformer)
                                  throws java.io.IOException,
                                         javax.xml.transform.TransformerConfigurationException,
                                         javax.xml.transform.TransformerException
serialize a Document to String (using the passed Transformer) This call uses the transformer's output encoding to convert the content to a String

Parameters:
doc - Document (-fragment) to be serialized
transformer - the transformer to use
Returns:
the String representation of the Document
Throws:
java.io.IOException - on read problems
javax.xml.transform.TransformerConfigurationException - on transformer configuration problems
javax.xml.transform.TransformerException - on trnaformation problems
java.lang.IllegalArgumentException - if the document or the transformer is null

addDirectiveToXSL

public static org.w3c.dom.Node addDirectiveToXSL(org.w3c.dom.Document xslDom,
                                                 java.lang.String directiveName,
                                                 java.lang.String attributeName,
                                                 java.lang.String attributeValue)
                                          throws javax.xml.transform.TransformerException
Add an xsl:import or xsl:include etc. node to an existing xsl style sheet (represented as DOM)

Parameters:
xslDom - the DOM representation of the XSL style sheet
directiveName - the tag name (@see #DIRECTIVE_INCLUDE and #DIRECTIVE_IMPORT)
attributeName - the name of an attribute to create, or null
attributeValue - the value for the attribute, or null
Returns:
the newly created node
Throws:
javax.xml.transform.TransformerException - when problems adding the xsl directive occur
java.lang.IllegalArgumentException - if the document or the directive name is null, or if the document is not an xsl style sheet

addDirectiveToXSLBeforeSibling

public static org.w3c.dom.Node addDirectiveToXSLBeforeSibling(org.w3c.dom.Node sibling,
                                                              java.lang.String directiveName,
                                                              java.lang.String attributeName,
                                                              java.lang.String attributeValue)
Add an xsl:import or xsl:include node to an existing xsl style sheet (represented as DOM) before the passed sibling node.

Parameters:
sibling - the node before which the new node will be added as a sibling (same level)
directiveName - (@see #DIRECTIVE_INCLUDE and #DIRECTIVE_IMPORT)
attributeName - the name of an attribute to create, or null
attributeValue - the value for the attribute, or null
Returns:
the newly created node
Throws:
java.lang.IllegalArgumentException - if the sibling node or the directive name is null (no check if this is a style sheet!)

xslTransform

public static void xslTransform(org.w3c.dom.Document contentDom,
                                org.w3c.dom.Document styleDom,
                                java.io.Writer out)
                         throws javax.xml.transform.TransformerException,
                                javax.xml.transform.TransformerConfigurationException,
                                java.io.FileNotFoundException,
                                java.io.IOException
Transforms an xml with the provided xsl document and writes it to the writer.

Parameters:
contentDom - the document to be transformed
styleDom - the style to apply to the content
out - the writer to write the result to
Throws:
javax.xml.transform.TransformerException - on trnaformation problems
javax.xml.transform.TransformerConfigurationException - on transformer configuration problems
java.io.FileNotFoundException - if the write operation fails
java.io.IOException - on read problems
java.lang.IllegalArgumentException - if any of the arguments is null

xslTransform

public static java.lang.String xslTransform(org.w3c.dom.Document contentDom,
                                            javax.xml.transform.Transformer transformer,
                                            java.io.OutputStream out)
                                     throws javax.xml.transform.TransformerException,
                                            javax.xml.transform.TransformerConfigurationException
Transforms an xml document with the provided xsl style (compiled version) and write it to the provided writer

Parameters:
contentDom - the document to be transformed
transformer - the compiled xsl style sheet that will be applied to the content document
out - the OutputStream to write the result to
Returns:
the encoding in which to read from the stream (taken from the transformers encoding property)

Note: you can set that encoding via #Transformer.getOutputProperties().setProperty("encoding", String); or in you xsl style sheet via xsl:output encoding="your encoding here" .....; the default encoding is UTF-8

Throws:
javax.xml.transform.TransformerException - if the transformation fails
javax.xml.transform.TransformerConfigurationException - if the transformer is misconfigured
java.lang.IllegalArgumentException - if any of the arguments is null

xslTransform

public static void xslTransform(org.w3c.dom.Document contentDom,
                                javax.xml.transform.Transformer transformer,
                                java.io.Writer writer)
                         throws javax.xml.transform.TransformerException,
                                javax.xml.transform.TransformerConfigurationException
Transforms an xml document with the provided xsl style (compiled version) and write it to the provided writer

Parameters:
contentDom - the document to be transformed
transformer - the compiled xsl style sheet that will be applied to the content document
writer - the writer to write the result to
Throws:
javax.xml.transform.TransformerException - if the transformation fails
javax.xml.transform.TransformerConfigurationException - if the transformer is misconfigured
java.lang.IllegalArgumentException - if any of the arguments is null

getTransformer

public static javax.xml.transform.Transformer getTransformer()
                                                      throws javax.xml.transform.TransformerConfigurationException
get a new Transformer from the TransformerFactory with indent turned on

Returns:
the new Transformer
Throws:
javax.xml.transform.TransformerConfigurationException - if the underlying parser does

getTransformer

public static javax.xml.transform.Transformer getTransformer(java.util.Properties transProps)
                                                      throws javax.xml.transform.TransformerConfigurationException
get a new Transformer from the TransformerFactory with the passed output properties

Parameters:
transProps - a Porperties file containing the desired Output properties
Returns:
the new Transformer
Throws:
javax.xml.transform.TransformerConfigurationException - if the underlying parser does

getTransformer

public static javax.xml.transform.Transformer getTransformer(javax.xml.transform.Source strSource)
                                                      throws javax.xml.transform.TransformerConfigurationException
get a new Transformer for the passed Source (the xsl) from the TransformerFactory with indent turned on

Parameters:
strSource - a Source (StreamSource, DOMSource, SAXSource) representing the style we need the Transformer for
Returns:
the new Transformer
Throws:
javax.xml.transform.TransformerConfigurationException - if the underlying parser does

getTransformer

public static javax.xml.transform.Transformer getTransformer(javax.xml.transform.Templates templates)
                                                      throws javax.xml.transform.TransformerConfigurationException
get a new Transformer for the passed compiled xsl template (with indent turned on)

Parameters:
templates - the pre compile xsl style sheet
Returns:
the new Transformer
Throws:
javax.xml.transform.TransformerConfigurationException - if the underlying parser does

getTransformer

public static javax.xml.transform.Transformer getTransformer(org.w3c.dom.Document doc)
                                                      throws javax.xml.transform.TransformerException,
                                                             java.io.IOException
get a new Transformer for the passed Document (the xsl) from the TransformerFactory with indent turned on

Parameters:
doc - a document representing the style we need the Transformer for
Returns:
the new Transformer (compiled xsl style sheet)
Throws:
javax.xml.transform.TransformerException - if the underlying parser does
java.io.IOException - if converting the document to a stream source fails

getTemplates

public static javax.xml.transform.Templates getTemplates(javax.xml.transform.Source source)
                                                  throws javax.xml.transform.TransformerConfigurationException
compile the provided style sheet into templates

Parameters:
source - a StreamSource, DOMSource, ... that contains the xsl style sheet to compile
Returns:
the compiled style sheet (where you can get the Transformer from)
Throws:
javax.xml.transform.TransformerConfigurationException - if the underlying parser does

getSelectedNodes

public static org.w3c.dom.NodeList getSelectedNodes(org.w3c.dom.Node contextNode,
                                                    java.lang.String str)
                                             throws javax.xml.transform.TransformerException
Use an XPath string to select a nodelist. XPath namespace prefixes are resolved from the contextNode.

Parameters:
contextNode - the node from which on to search in the tree
str - the XPATH expression
Returns:
the NodeList containing the valid nodes, or length == 0
Throws:
java.lang.RuntimeException - (possibly wrapping the original checked exception) if any exception happens
javax.xml.transform.TransformerException - if the xpath expression is not valid

getSelectedNode

public static org.w3c.dom.Node getSelectedNode(org.w3c.dom.Node contextNode,
                                               java.lang.String str)
                                        throws javax.xml.transform.TransformerException
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.

Parameters:
contextNode - the node from which on to search in the tree
str - the XPATH expression
Returns:
The first node found that matches the XPath, or null
Throws:
java.lang.RuntimeException - (possibly wrapping the original checked exception) if any exception happens
javax.xml.transform.TransformerException - if the xpath expression is not valid

getSelectedNode

public static org.w3c.dom.Node getSelectedNode(org.apache.xpath.CachedXPathAPI xpath,
                                               org.w3c.dom.Node contextNode,
                                               java.lang.String str)
                                        throws javax.xml.transform.TransformerException
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.

Parameters:
xpath - a org.apache.xpath.CachedXPathAPI instance to use for xpath navigation
contextNode - the node from which on to search in the tree
str - the XPATH expression
Returns:
The first node found that matches the XPath, or null
Throws:
java.lang.RuntimeException - (possibly wrapping the original checked exception) if any exception happens
javax.xml.transform.TransformerException - if the xpath expression is not valid

getSAXParserFactory

public static javax.xml.parsers.SAXParserFactory getSAXParserFactory(boolean validation,
                                                                     boolean nameSpaceAware)
get a SAXParserFactory (from cache) for the validation and name space aware properties

Parameters:
validation - if the factory should validate the document
nameSpaceAware - if the factory should be name space aware
Returns:
a SAXParserFactory to get a SAXParser from

saxParse

public static void saxParse(java.io.InputStream in,
                            org.xml.sax.helpers.DefaultHandler handler,
                            boolean validation,
                            boolean nameSpaceAware)
                     throws javax.xml.parsers.ParserConfigurationException,
                            org.xml.sax.SAXException,
                            java.io.IOException
parse the document from an InputStream with the provided handler

Parameters:
in - the InputStream pointing to an xml document (from file ...)
handler - the handler to use for parsing (extends DefaultHandler)
validation - if the parser should validate the document
nameSpaceAware - if the parser should be name space aware
Throws:
javax.xml.parsers.ParserConfigurationException - if the parser is misconfigured
org.xml.sax.SAXException - if the parsing fails
java.io.IOException - if the read fails

saxParse

public static void saxParse(org.xml.sax.InputSource source,
                            org.xml.sax.helpers.DefaultHandler handler,
                            boolean validation,
                            boolean nameSpaceAware)
                     throws javax.xml.parsers.ParserConfigurationException,
                            org.xml.sax.SAXException,
                            java.io.IOException
parse the document from an InputStream with the provided handler

Parameters:
source - the InputSource to parse
handler - the handler to use for parsing (extends DefaultHandler)
validation - if the parser should validate the document
nameSpaceAware - if the parser should be name space aware
Throws:
javax.xml.parsers.ParserConfigurationException - if the parser is misconfigured
org.xml.sax.SAXException - if the parsing fails
java.io.IOException - if the read fails

getFirstElementValue

public static java.lang.String getFirstElementValue(org.w3c.dom.Node node,
                                                    java.lang.String element)
Returns the value of the first occurence of the child element specified for the node specified

Parameters:
node - the node from where on to search for a node with the name specified by #element
element - the name of the node to look for
Returns:
the value of the first child node of #node whose name matches #element, or null if the node can't be found
Throws:
java.lang.IllegalArgumentException - if any of the arguments is null

getElementValue

public static java.lang.String getElementValue(org.w3c.dom.Node node)
entities are often considered serperate text nodes. for example Jim's wagon is represented by three text nodes "Jim", "'", and "s wagon" Thus all children need to be concatenated in order to retrieve the proper text node value

Parameters:
node - the node that will be inspected for children
Returns:
the concatenated String of child element values, or an empty String (not null!)
Throws:
java.lang.IllegalArgumentException - if the provided node is null

copyAttributes

public static void copyAttributes(org.w3c.dom.Element src,
                                  org.w3c.dom.Element dest)
Copies all of the attributes from the src Element to the dest Element.

Parameters:
src - The Element from which all attributes will be copied.
dest - The Element to recieve the attributes in the src element.
Throws:
java.lang.IllegalArgumentException - if the provided elements are null