Class 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 Detail

      • XmlUtil

        public XmlUtil()
    • 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 to FileFormat.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 a Reader.
        Parameters:
        r - Source of the xml.
        Returns:
        The object contained in r.
      • loadXML

        public static Object loadXML​(Reader r)
        Loads an object from a Reader. 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 in w.
        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 file f.
        Parameters:
        o - The object to convert.
        f - The output file. This file is overwritten if it already exists.
      • saveXML

        public static String saveXML​(Object o)
        Converts the given object to a String in xml format. This is the same as calling saveXML(FileFormat, Object) with FileFormat.XSTREAM as 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 calling saveXML(FileFormat, Object) with FileFormat. as the file format.