org.ow2.orchestra.util
Class XmlUtil

java.lang.Object
  extended by org.ow2.orchestra.util.XmlUtil

public abstract class XmlUtil
extends Object

convenience methods to make reading org.w3c.dom models easier.

Author:
Tom Baeyens

Nested Class Summary
static class XmlUtil.NamespaceValue
           
 
Method Summary
static boolean areNodeEquals(Node n1, Node n2)
          Test the equality of two nodes following same conditions that org.w3c.dom.Node.isEqualNode(Node n) except for prefix.
static String attribute(Element element, String attributeName)
          the attribute value or null if the attribute is not present
static XmlUtil.NamespaceValue attributeNamespaceValue(Element element, String attributeName)
           
static QName attributeQName(Element element, String attributeName)
           
static List<Attr> attributes(Element element)
           
static Document copyDocument(Document src)
           
static Element element(Element element)
           
static Element element(Element element, String tagName)
           
static Element element(Element element, String ns, String localName)
           
static List<Element> elements(Element element)
           
static List<Element> elements(Element element, Set<String> allowedTagNames)
           
static List<Element> elements(Element element, String tagName)
           
static List<Element> elements(Element father, String ns, String localName)
           
static List<Element> elementsQName(Element element, Set<QName> allowedTagNames)
           
static String errorMessageAttribute(Element element, String attributeName, String attributeValue, String message)
           
static String getContentText(Element element)
           
static Document getDocumentFromFile(File xmlFile)
           
static Document getDocumentFromInputStream(InputStream is)
           
static Document getDocumentFromReader(Reader r)
           
static Document getDocumentFromString(String s)
           
static Document getDocumentFromString(String s, boolean createProxy)
           
static Document getDocumentFromURL(URL xmlUrl)
           
static Element getDocumentWithOneElement(QName elementQName)
           
static String getNamespaceURI(Node n, String prefix)
           
static Document getNewDocument()
           
static ByteArrayOutputStream getNodeAsBAOS(Node n)
           
static QName getQNameFromString(Element element, String qnameAsString)
           
static String getTagLocalName(Element element)
           
static TransformerFactory getTransformerFactory()
           
static boolean isTextOnly(Element element)
           
static Boolean parseBooleanValue(String valueText)
           
static List<String> parseCommaSeparatedList(String commaSeparatedListText)
          parses comma or space separated list.
static List<String> parseList(Element element, String singularTagName)
           
static String toString(Node node)
           
static void writeXmlFile(Document doc, File file)
          This method writes a DOM document to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

elements

public static List<Element> elements(Element element,
                                     String tagName)

elements

public static List<Element> elements(Element element,
                                     Set<String> allowedTagNames)

element

public static Element element(Element element,
                              String tagName)

element

public static Element element(Element element,
                              String ns,
                              String localName)

elements

public static List<Element> elements(Element element)

elements

public static List<Element> elements(Element father,
                                     String ns,
                                     String localName)

elementsQName

public static List<Element> elementsQName(Element element,
                                          Set<QName> allowedTagNames)

element

public static Element element(Element element)

toString

public static String toString(Node node)

getContentText

public static String getContentText(Element element)

isTextOnly

public static boolean isTextOnly(Element element)

attributes

public static List<Attr> attributes(Element element)

getTagLocalName

public static String getTagLocalName(Element element)

attribute

public static String attribute(Element element,
                               String attributeName)
the attribute value or null if the attribute is not present


parseBooleanValue

public static Boolean parseBooleanValue(String valueText)

errorMessageAttribute

public static String errorMessageAttribute(Element element,
                                           String attributeName,
                                           String attributeValue,
                                           String message)

parseList

public static List<String> parseList(Element element,
                                     String singularTagName)

parseCommaSeparatedList

public static List<String> parseCommaSeparatedList(String commaSeparatedListText)
parses comma or space separated list. A null return value means a wildcard.

Returns:
List of tokens or null if the commaSeparatedListText is null, '*', or empty

attributeNamespaceValue

public static XmlUtil.NamespaceValue attributeNamespaceValue(Element element,
                                                             String attributeName)

attributeQName

public static QName attributeQName(Element element,
                                   String attributeName)

getTransformerFactory

public static TransformerFactory getTransformerFactory()

getQNameFromString

public static QName getQNameFromString(Element element,
                                       String qnameAsString)

getNamespaceURI

public static String getNamespaceURI(Node n,
                                     String prefix)

getNewDocument

public static Document getNewDocument()

writeXmlFile

public static void writeXmlFile(Document doc,
                                File file)
This method writes a DOM document to a file.

Parameters:
doc - - doc to write
file - - dest file;

getNodeAsBAOS

public static ByteArrayOutputStream getNodeAsBAOS(Node n)

getDocumentFromString

public static Document getDocumentFromString(String s)

getDocumentFromString

public static Document getDocumentFromString(String s,
                                             boolean createProxy)

getDocumentFromInputStream

public static Document getDocumentFromInputStream(InputStream is)

getDocumentFromReader

public static Document getDocumentFromReader(Reader r)

getDocumentFromFile

public static Document getDocumentFromFile(File xmlFile)

getDocumentFromURL

public static Document getDocumentFromURL(URL xmlUrl)

getDocumentWithOneElement

public static Element getDocumentWithOneElement(QName elementQName)

copyDocument

public static Document copyDocument(Document src)

areNodeEquals

public static boolean areNodeEquals(Node n1,
                                    Node n2)
Test the equality of two nodes following same conditions that org.w3c.dom.Node.isEqualNode(Node n) except for prefix. The two nodes prefix doesn't need to be equals.

Parameters:
n1 - First node
n2 - Second node
Returns:
true if the two nodes are equals, false otherwise


Copyright © 2012 OW2 Consortium. All Rights Reserved.