org.springframework.roo.support.util
Class XmlUtils

java.lang.Object
  extended by org.springframework.roo.support.util.XmlUtils

public final class XmlUtils
extends Object

Utilities related to DOM and XML usage.

Since:
1.0
Author:
Stefan Schmidt, Ben Alex, Alan Stewart

Method Summary
static Transformer createIndentingTransformer()
           
static List<Element> findElements(String xPathExpression, Element root)
          Checks in under a given root element whether it can find a child elements which match the XPath expression supplied.
static Node findFirstAttribute(String xPathExpression, Element element)
          Checks for a given element whether it can find an attribute which matches the XPath expression supplied.
static Element findFirstElement(String xPathExpression, Element root)
          Checks in under a given root element whether it can find a child element which matches the XPath expression supplied.
static Element findFirstElementByName(String name, Element root)
          Checks in under a given root element whether it can find a child element which matches the name supplied.
static Node findNode(String xPathExpression, Element root)
          Checks in under a given root element whether it can find a child node which matches the XPath expression supplied.
static Element findRequiredElement(String xPathExpression, Element root)
          Checks in under a given root element whether it can find a child element which matches the XPath expression supplied.
static Element getConfiguration(Class<?> clazz)
          Returns the root element of an addon's configuration file.
static Element getConfiguration(Class<?> clazz, String configurationPath)
          Returns the root element of an addon's configuration file.
static DocumentBuilder getDocumentBuilder()
           
static void removeTextNodes(Element element)
          Removes empty text nodes from the specified element
static void writeXml(OutputStream outputEntry, Document document)
          Write an XML document to the outputstream provided.
static void writeXml(Transformer transformer, OutputStream outputEntry, Document document)
          Write an XML document to the outputstream provided.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

writeXml

public static final void writeXml(OutputStream outputEntry,
                                  Document document)
Write an XML document to the outputstream provided. This will use the preconfigured Roo provided Transformer.

Parameters:
outputEntry - The output stream to write to.
document - The document to write

writeXml

public static final void writeXml(Transformer transformer,
                                  OutputStream outputEntry,
                                  Document document)
Write an XML document to the outputstream provided. This will use the provided Transformer.

Parameters:
transformer - The transformer (can be obtained from XmlUtils.createIndentingTransformer())
outputEntry - The output stream to write to.
document - The document to write

findFirstElement

public static Element findFirstElement(String xPathExpression,
                                       Element root)
Checks in under a given root element whether it can find a child element which matches the XPath expression supplied. Returns Element if exists. Please note that the XPath parser used is NOT namespace aware. So if you want to find a element you need to use the following XPath expression '/beans/http'.

Parameters:
xPathExpression - the xPathExpression (required)
root - the parent DOM element (required)
Returns:
the Element if discovered (null if not found)

findNode

public static Node findNode(String xPathExpression,
                            Element root)
Checks in under a given root element whether it can find a child node which matches the XPath expression supplied. Returns Node if exists. Please note that the XPath parser used is NOT namespace aware. So if you want to find a element you need to use the following XPath expression '/beans/http'.

Parameters:
xPathExpression - the xPathExpression (required)
root - the parent DOM element (required)
Returns:
the Node if discovered (null if not found)

findFirstElementByName

public static Element findFirstElementByName(String name,
                                             Element root)
Checks in under a given root element whether it can find a child element which matches the name supplied. Returns Element if exists.

Parameters:
name - the Element name (required)
root - the parent DOM element (required)
Returns:
the Element if discovered

findRequiredElement

public static Element findRequiredElement(String xPathExpression,
                                          Element root)
Checks in under a given root element whether it can find a child element which matches the XPath expression supplied. The Element must exist. Returns Element if exists. Please note that the XPath parser used is NOT namespace aware. So if you want to find a element you need to use the following XPath expression '/beans/http'.

Parameters:
xPathExpression - the xPathExpression (required)
root - the parent DOM element (required)
Returns:
the Element if discovered (never null; an exception is thrown if cannot be found)

findElements

public static List<Element> findElements(String xPathExpression,
                                         Element root)
Checks in under a given root element whether it can find a child elements which match the XPath expression supplied. Returns a List of Element if they exist. Please note that the XPath parser used is NOT namespace aware. So if you want to find a element you need to use the following XPath expression '/beans/http'.

Parameters:
xPathExpression - the xPathExpression
root - the parent DOM element
Returns:
a List of type Element if discovered, otherwise null

findFirstAttribute

public static Node findFirstAttribute(String xPathExpression,
                                      Element element)
Checks for a given element whether it can find an attribute which matches the XPath expression supplied. Returns Node if exists.

Parameters:
xPathExpression - the xPathExpression (required)
element - (required)
Returns:
the Node if discovered (null if not found)

createIndentingTransformer

public static final Transformer createIndentingTransformer()
Returns:
a transformer that indents entries by 4 characters (never null)

getDocumentBuilder

public static final DocumentBuilder getDocumentBuilder()
Returns:
a new document builder (never null)

removeTextNodes

public static void removeTextNodes(Element element)
Removes empty text nodes from the specified element

Parameters:
element - the element where empty etxt nodes will be removed

getConfiguration

public static Element getConfiguration(Class<?> clazz,
                                       String configurationPath)
Returns the root element of an addon's configuration file.

Parameters:
clazz - which owns the configuration
configurationPath - the path of the configuration file.
Returns:
the configuration root element

getConfiguration

public static Element getConfiguration(Class<?> clazz)
Returns the root element of an addon's configuration file.

Parameters:
clazz - which owns the configuration
Returns:
the configuration root element


Copyright © 2009-2010 VMware, Inc. All Rights Reserved.