org.apache.oozie.util
Class XmlUtils

java.lang.Object
  extended by org.apache.oozie.util.XmlUtils

public class XmlUtils
extends Object

XML utility methods.


Nested Class Summary
static class XmlUtils.PrettyPrint
          Pretty print string representation of an XML document that generates the pretty print on lazy mode when the XmlUtils.PrettyPrint.toString() method is invoked.
 
Constructor Summary
XmlUtils()
           
 
Method Summary
static Schema createSchema(InputStream is)
          Create schema object for the given xsd
static String escapeCharsForXML(String aText)
          Escape characters for text appearing as XML data, between tags.
static String getRootAttribute(String filePath, String attributeName)
          //TODO move this to action registry method Return the value of an attribute from the root element of an XML document.
static org.jdom.Element getSLAElement(org.jdom.Element elem)
           
static org.jdom.Element parseXml(InputStream is)
          Parse a inputstream assuming it is a valid XML document and return an JDOM Element for it.
static org.jdom.Element parseXml(String xmlStr)
          Parse a string assuming it is a valid XML document and return an JDOM Element for it.
static XmlUtils.PrettyPrint prettyPrint(org.apache.hadoop.conf.Configuration conf)
          Return a pretty print string for a Configuration object.
static XmlUtils.PrettyPrint prettyPrint(org.jdom.Element element)
          Return a pretty print string for a JDOM Element.
static XmlUtils.PrettyPrint prettyPrint(String xmlStr)
          Return a pretty print string for a XML string.
static String removeComments(String xmlStr)
          Remove comments from any Xml String.
static void validateData(String xmlData, SchemaService.SchemaName xsdFile)
           
static void validateXml(Schema schema, String xml)
          Schema validation for a given xml.
static String writePropToString(Properties props)
          Convert Properties to string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlUtils

public XmlUtils()
Method Detail

removeComments

public static String removeComments(String xmlStr)
                             throws org.jdom.JDOMException
Remove comments from any Xml String.

Parameters:
xmlStr - XML string to remove comments.
Returns:
String after removing comments.
Throws:
org.jdom.JDOMException - thrown if an error happend while XML parsing.

parseXml

public static org.jdom.Element parseXml(String xmlStr)
                                 throws org.jdom.JDOMException
Parse a string assuming it is a valid XML document and return an JDOM Element for it.

Parameters:
xmlStr - XML string to parse.
Returns:
JDOM element for the parsed XML string.
Throws:
org.jdom.JDOMException - thrown if an error happend while XML parsing.

parseXml

public static org.jdom.Element parseXml(InputStream is)
                                 throws org.jdom.JDOMException,
                                        IOException
Parse a inputstream assuming it is a valid XML document and return an JDOM Element for it.

Parameters:
is - inputstream to parse.
Returns:
JDOM element for the parsed XML string.
Throws:
org.jdom.JDOMException - thrown if an error happend while XML parsing.
IOException - thrown if an IO error occurred.

getRootAttribute

public static String getRootAttribute(String filePath,
                                      String attributeName)
//TODO move this to action registry method Return the value of an attribute from the root element of an XML document.

Parameters:
filePath - path of the XML document.
attributeName - attribute to retrieve value for.
Returns:
value of the specified attribute.

prettyPrint

public static XmlUtils.PrettyPrint prettyPrint(org.jdom.Element element)
Return a pretty print string for a JDOM Element.

Parameters:
element - JDOM element.
Returns:
pretty print of the given JDOM Element.

prettyPrint

public static XmlUtils.PrettyPrint prettyPrint(String xmlStr)
Return a pretty print string for a XML string. If the given string is not valid XML it returns the original string.

Parameters:
xmlStr - XML string.
Returns:
prettyprint of the given XML string or the original string if the given string is not valid XML.

prettyPrint

public static XmlUtils.PrettyPrint prettyPrint(org.apache.hadoop.conf.Configuration conf)
Return a pretty print string for a Configuration object.

Parameters:
conf - Configuration object.
Returns:
prettyprint of the given Configuration object.

validateXml

public static void validateXml(Schema schema,
                               String xml)
                        throws SAXException,
                               IOException
Schema validation for a given xml.

Parameters:
schema - for validation
xml - to be validated
Throws:
SAXException
IOException

createSchema

public static Schema createSchema(InputStream is)
Create schema object for the given xsd

Parameters:
is - inputstream to schema.
Returns:
the schema object.

validateData

public static void validateData(String xmlData,
                                SchemaService.SchemaName xsdFile)
                         throws SAXException,
                                IOException
Throws:
SAXException
IOException

writePropToString

public static String writePropToString(Properties props)
                                throws IOException
Convert Properties to string

Parameters:
props -
Returns:
xml string
Throws:
IOException

escapeCharsForXML

public static String escapeCharsForXML(String aText)
Escape characters for text appearing as XML data, between tags.

The following characters are replaced with corresponding character entities : '<' to '<'; '>' to '>'; '&' to '&' '"' to '"' "'" to "'"

Note that JSTL's <c:out> escapes the exact same set of characters as this method.


getSLAElement

public static org.jdom.Element getSLAElement(org.jdom.Element elem)


Copyright © 2013 Apache Software Foundation. All Rights Reserved.