Package jasima.core.util
Class XmlUtil
- java.lang.Object
-
- jasima.core.util.XmlUtil
-
public class XmlUtil extends Object
Provides utility methods to read and write arbitrary Java objects as xml (xml-Serialization using the xstream library).- Author:
- Torsten Hildebrandt
-
-
Constructor Summary
Constructors Constructor Description XmlUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ObjectloadJSON(String jsonString)Loads an object from a String containing JSON data suitable for XSTREAM.static ObjectloadXML(FileFormat format, File f)Loads an object from a file.static ObjectloadXML(FileFormat format, Reader r)Loads an object from aReader.static ObjectloadXML(FileFormat format, String xmlString)Loads an object from a String containing xml.static ObjectloadXML(File f)Loads an object from a file.static ObjectloadXML(Reader r)Loads an object from aReader.static ObjectloadXML(String xmlString)Loads an object from a String containing xml.static StringsaveJSON(Object o)Converts the given object to a String in JSON format.static StringsaveXML(FileFormat format, Object o)Converts an object into a xml String.static voidsaveXML(FileFormat format, Object o, File f)Converts an object into xml and saves the result in a filef.static voidsaveXML(FileFormat format, Object o, Writer w)Converts an object into xml and writes the result inw.static StringsaveXML(Object o)Converts the given object to a String in xml format.static voidsaveXML(Object o, File f)Saves the given object in the filef.static voidsaveXML(Object o, Writer w)Saves the given object in the writerw.
-
-
-
Method Detail
-
loadXML
public static Object loadXML(FileFormat format, String xmlString)
Loads an object from a String containing xml.- Parameters:
xmlString- A String containing xml data.- Returns:
- The object contained in
xmlString. - See Also:
saveXML(FileFormat,Object)
-
loadXML
public static Object loadXML(String xmlString)
Loads an object from a String containing xml. Format defaults toFileFormat.XSTREAM.- Parameters:
xmlString- A String containing xml data.- Returns:
- The object contained in
xmlString. - See Also:
loadXML(FileFormat,String),saveXML(Object)
-
loadXML
public static Object loadXML(FileFormat format, File f)
Loads an object from a file.- Parameters:
f- The file to load.- Returns:
- The object contained in
f.
-
loadXML
public static Object loadXML(File f)
Loads an object from a file. Format is assumed to be the XML bean format produced by jasima gui.- Parameters:
f- The file to load.- Returns:
- The object contained in
f.
-
loadXML
public static Object loadXML(FileFormat format, Reader r)
Loads an object from aReader.- Parameters:
r- Source of the xml.- Returns:
- The object contained in
r.
-
loadXML
public static Object loadXML(Reader r)
Loads an object from aReader. Format is assumed to be the XML bean format produced by jasima gui.- Parameters:
r- Source of the xml.- Returns:
- The object contained in
r.
-
saveXML
public static String saveXML(FileFormat format, Object o)
Converts an object into a xml String.- Parameters:
o- The object to convert.- Returns:
- The object serialized to xml.
-
saveXML
public static void saveXML(FileFormat format, Object o, Writer w)
Converts an object into xml and writes the result inw.- Parameters:
o- The object to convert.w- The output writer.
-
saveXML
public static void saveXML(FileFormat format, Object o, File f)
Converts an object into xml and saves the result in a filef.- Parameters:
o- The object to convert.f- The output file. This file is overwritten if it already exists.
-
saveXML
public static void saveXML(Object o, File f)
Saves the given object in the filef. This is the same as callingsaveXML(FileFormat, Object, File)withFileFormat.XSTREAMas the file format.
-
saveXML
public static void saveXML(Object o, Writer w)
Saves the given object in the writerw. This is the same as callingsaveXML(FileFormat, Object, Writer)withFileFormat.XSTREAMas the file format.
-
saveXML
public static String saveXML(Object o)
Converts the given object to a String in xml format. This is the same as callingsaveXML(FileFormat, Object)withFileFormat.XSTREAMas the file format.
-
loadJSON
public static Object loadJSON(String jsonString)
Loads an object from a String containing JSON data suitable for XSTREAM.- Parameters:
jsonString- A String containing JSON data.- Returns:
- The object contained in
jsonString. - See Also:
loadXML(FileFormat,String)
-
saveJSON
public static String saveJSON(Object o)
Converts the given object to a String in JSON format. This is the same as callingsaveXML(FileFormat, Object)withFileFormat.as the file format.
-
-