org.kuali.rice.core.util.xml
Class XmlHelper

java.lang.Object
  extended by org.kuali.rice.core.util.xml.XmlHelper

public final class XmlHelper
extends Object

Provides a set of utilities for XML-related operations on org.jdom & org.w3c xml Objects.

Author:
Kuali Rice Team (rice.collab@kuali.org)

Field Summary
private static org.apache.commons.logging.Log LOG
           
 
Constructor Summary
private XmlHelper()
           
 
Method Summary
static void appendXml(Node parentNode, String xml)
           
static org.jdom.Document buildJDocument(Document document)
          Creates jdom Document from a w3c Document.
static org.jdom.Document buildJDocument(Reader xmlStream)
          Creates jdom Document from a Reader.
static Collection<org.jdom.Element> findElements(org.jdom.Element root, String elementName)
          Find all Elements in document of a particular name
private static void findElements(org.jdom.Element root, String elementName, Collection<org.jdom.Element> list)
          This function is tail-recursive and just adds the root to the list if it matches and checks the children.
static boolean pathExists(XPath xpath, String expression, Object object)
          Convenience method that performs an xpath evaluation to determine whether the expression evaluates to true (a node exists).
static void propagateNamespace(org.jdom.Element element, org.jdom.Namespace namespace)
           
static Element propertiesToXml(Document doc, Object o, String elementName)
           
static Document readXml(String xml)
           
private static void trimElement(Node node)
           
private static void trimSAXElement(org.jdom.Element element)
           
static org.jdom.Document trimSAXXml(InputStream input)
           
static Document trimXml(InputStream input)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

private static final org.apache.commons.logging.Log LOG
Constructor Detail

XmlHelper

private XmlHelper()
Method Detail

buildJDocument

public static org.jdom.Document buildJDocument(Reader xmlStream)
Creates jdom Document from a Reader. Does not close the reader.

Parameters:
xmlStream - the reader representing the xmlstream
Returns:
jdom document

buildJDocument

public static org.jdom.Document buildJDocument(Document document)
Creates jdom Document from a w3c Document. Does not close the reader.

Parameters:
document - the w3c document
Returns:
jdom document

findElements

public static Collection<org.jdom.Element> findElements(org.jdom.Element root,
                                                        String elementName)
Find all Elements in document of a particular name

Parameters:
root - the starting Element to scan
elementName - name of the Element to scan for
Returns:
collection of the Elements found. returns an empty collection if none are found.

appendXml

public static void appendXml(Node parentNode,
                             String xml)
                      throws SAXException,
                             IOException,
                             ParserConfigurationException
Throws:
SAXException
IOException
ParserConfigurationException

readXml

public static Document readXml(String xml)
                        throws TransformerException
Throws:
TransformerException

propagateNamespace

public static void propagateNamespace(org.jdom.Element element,
                                      org.jdom.Namespace namespace)

trimXml

public static Document trimXml(InputStream input)
                        throws SAXException,
                               IOException,
                               ParserConfigurationException
Throws:
SAXException
IOException
ParserConfigurationException

trimSAXXml

public static org.jdom.Document trimSAXXml(InputStream input)
                                    throws org.jdom.JDOMException,
                                           SAXException,
                                           IOException,
                                           ParserConfigurationException
Throws:
org.jdom.JDOMException
SAXException
IOException
ParserConfigurationException

pathExists

public static boolean pathExists(XPath xpath,
                                 String expression,
                                 Object object)
                          throws XPathExpressionException
Convenience method that performs an xpath evaluation to determine whether the expression evaluates to true (a node exists). This is method exists only to disambiguate the cases of determining the *presence* of a node and determining the *boolean value of the node as converted from a string*, as the syntaxes are very similar and could be misleading.

Parameters:
xpath - the XPath object
expression - the XPath expression
object - the object on which to evaluate the expression as required by the XPath API, typically a Node
Returns:
whether the result of the expression evaluation, which is whether or not a node was present
Throws:
XPathExpressionException - if the expression fails

propertiesToXml

public static Element propertiesToXml(Document doc,
                                      Object o,
                                      String elementName)
                               throws Exception
Throws:
Exception

findElements

private static void findElements(org.jdom.Element root,
                                 String elementName,
                                 Collection<org.jdom.Element> list)
This function is tail-recursive and just adds the root to the list if it matches and checks the children.

Parameters:
root - the root element to search under
elementName - the element name to find
list - a list of found element

trimElement

private static void trimElement(Node node)
                         throws SAXException,
                                IOException,
                                ParserConfigurationException
Throws:
SAXException
IOException
ParserConfigurationException

trimSAXElement

private static void trimSAXElement(org.jdom.Element element)
                            throws SAXException,
                                   IOException,
                                   ParserConfigurationException
Throws:
SAXException
IOException
ParserConfigurationException


Copyright © 2004-2011 The Kuali Foundation. All Rights Reserved.