net.authorize.util
Class XmlUtility

java.lang.Object
  extended by net.authorize.util.XmlUtility

public final class XmlUtility
extends Object

Helper methods for serializing and de-serializing to XML using JAXB

Author:
ramittal

Method Summary
static
<T extends Serializable>
T
create(String xml, Class<T> classType)
          Helper method to de-serialize XML to an object.
static String descapeStringForXml(String valueToDeserialize)
          Helper method to decode a string from XML string Returns the same string if null or empty
static String escapeStringForXml(String valueToSerialize)
          Helper method to encode a string to XML Returns the same string if null or empty
static String getRootElementXml(String xmlString)
          Removes the XML prologue
static
<T extends Serializable>
String
getRootElementXml(T entity)
          Removes the XML prologue
static
<T extends Serializable>
String
getXml(T entity)
          Helper method to serialize an object to XML.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getXml

public static <T extends Serializable> String getXml(T entity)
                     throws IOException,
                            javax.xml.bind.JAXBException
Helper method to serialize an object to XML. Requires object to be Serializable

Type Parameters:
T - class that implements Serializable
Parameters:
entity - Object to serialize
Returns:
String XML representation of object
Throws:
IOException - if errors during serialization
javax.xml.bind.JAXBException - if errors during serialization

create

public static <T extends Serializable> T create(String xml,
                                                Class<T> classType)
                                     throws javax.xml.bind.JAXBException
Helper method to de-serialize XML to an object. Requires object to be Serializable

Type Parameters:
T - class that implements Serializable
Parameters:
xml - object serialized into valid XML
classType - Class Type of the object to be de-serialized into
Returns:
T De-serialized object
Throws:
javax.xml.bind.JAXBException - if errors during de-serialization

escapeStringForXml

public static String escapeStringForXml(String valueToSerialize)
Helper method to encode a string to XML Returns the same string if null or empty

Parameters:
valueToSerialize - string value to encode into xml
Returns:
xml encoded string

descapeStringForXml

public static String descapeStringForXml(String valueToDeserialize)
Helper method to decode a string from XML string Returns the same string if null or empty

Parameters:
valueToDeserialize - string value to decode from xml
Returns:
string decoded from xml

getRootElementXml

public static <T extends Serializable> String getRootElementXml(T entity)
Removes the XML prologue

Parameters:
entity - object to remove prologue
Returns:
String String XML representation of root element xml without prologue

getRootElementXml

public static String getRootElementXml(String xmlString)
Removes the XML prologue

Parameters:
xmlString - string to remove prologue
Returns:
String root element xml without prologue


Copyright © 2014. All Rights Reserved.