org.apache.oozie.util
Class XmlUtils

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

public class XmlUtils
extends java.lang.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.
 
Field Summary
static java.lang.String SLA_NAME_SPACE_URI
           
 
Constructor Summary
XmlUtils()
           
 
Method Summary
static javax.xml.validation.Schema createSchema(java.io.InputStream is)
          Create schema object for the given xsd
static java.lang.String getRootAttribute(java.lang.String filePath, java.lang.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 parseXml(java.io.InputStream is)
          Parse a inputstream assuming it is a valid XML document and return an JDOM Element for it.
static org.jdom.Element parseXml(java.lang.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(java.lang.String xmlStr)
          Return a pretty print string for a XML string.
static java.lang.String removeComments(java.lang.String xmlStr)
          Remove comments from any Xml String.
static void validateData(java.lang.String xmlData, SchemaService.SchemaName xsdFile)
           
static void validateXml(javax.xml.validation.Schema schema, java.lang.String xml)
          Schema validation for a given xml.
static java.lang.String writePropToString(java.util.Properties props)
          Convert Properties to string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SLA_NAME_SPACE_URI

public static final java.lang.String SLA_NAME_SPACE_URI
See Also:
Constant Field Values
Constructor Detail

XmlUtils

public XmlUtils()
Method Detail

removeComments

public static java.lang.String removeComments(java.lang.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(java.lang.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(java.io.InputStream is)
                                 throws org.jdom.JDOMException,
                                        java.io.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.
java.io.IOException - thrown if an IO error occurred.

getRootAttribute

public static java.lang.String getRootAttribute(java.lang.String filePath,
                                                java.lang.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(java.lang.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(javax.xml.validation.Schema schema,
                               java.lang.String xml)
                        throws org.xml.sax.SAXException,
                               java.io.IOException
Schema validation for a given xml.

Parameters:
schema - for validation
xml - to be validated
Throws:
org.xml.sax.SAXException
java.io.IOException

createSchema

public static javax.xml.validation.Schema createSchema(java.io.InputStream is)
Create schema object for the given xsd

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

validateData

public static void validateData(java.lang.String xmlData,
                                SchemaService.SchemaName xsdFile)
                         throws org.xml.sax.SAXException,
                                java.io.IOException
Throws:
org.xml.sax.SAXException
java.io.IOException

writePropToString

public static java.lang.String writePropToString(java.util.Properties props)
                                          throws java.io.IOException
Convert Properties to string

Parameters:
props -
Returns:
xml string
Throws:
java.io.IOException


Copyright © 2010 Yahoo. All Rights Reserved.