Class XmlMethods


  • public final class XmlMethods
    extends Object

    Contains one-liners for reading and writing to XML.

    • Constructor Detail

      • XmlMethods

        XmlMethods()
    • Method Detail

      • gloopObjectToXmlString

        @GloopParameter(name="gloopXml")
        public static String gloopObjectToXmlString​(GloopObject gloopObject,
                                                    @GloopParameter(defaultValue="true")
                                                    boolean insertHeader,
                                                    Map declaredNamespaces)

        Marshals a Gloop object to an XML string.

        Parameters:
        gloopObject - the object to marshall
        insertHeader - flag stating whether to include the <xml version = "1.0">; header
        declaredNamespaces - map of pre-declared namespaces already declared (if any); the key should contain the namespace URIs, and the values should contain their prefixes
        Returns:
        XML string representation of the object
        Since:
        1.0
      • xmlStringToGloopObject

        public static GloopObject xmlStringToGloopObject​(String xmlString)
                                                  throws SAXException

        Unmarshal an XML string to a Gloop object.

        Parameters:
        xmlString - the XML to convert
        Returns:
        Gloop object representation of the XML string
        Throws:
        SAXException
        Since:
        1.0
      • streamToGloopObject

        public static GloopObject streamToGloopObject​(InputStream xmlString)
                                               throws SAXException

        Unmarshal an XML string within an input stream to a Gloop object.

        Parameters:
        xmlString - the input stream containing the XML
        Returns:
        Gloop object representation of the XML string
        Throws:
        SAXException
        Since:
        1.0
      • readerToGloopObject

        public static GloopObject readerToGloopObject​(Reader xmlString)
                                               throws SAXException

        Unmarshal an XML string within a reader to a Gloop object.

        Parameters:
        xmlString - the reader containing the XML
        Returns:
        Gloop object representation of the XML string
        Throws:
        SAXException
        Since:
        1.0
      • writeXml

        public static void writeXml​(@GloopParameter(allowNull=false)
                                    Writer writer,
                                    @GloopParameter(allowNull=false)
                                    GloopObject gloopObject,
                                    @GloopParameter(defaultValue="false")
                                    boolean insertHeader,
                                    @GloopParameter(defaultValue="true")
                                    boolean includeNamespaces,
                                    Map declaredNamespaces,
                                    @GloopParameter(defaultValue="false")
                                    boolean includeNulls)

        Marshals a Gloop object to an XML string, written to a writer.

        Parameters:
        writer - writer to write the XML to
        gloopObject - Gloop object to marshal
        insertHeader - flag stating whether to include the <xml version = "1.0"> header
        includeNamespaces - flag stating whether to include namespace declarations
        declaredNamespaces - map of pre-declared namespaces already declared (if any); the key should contain the namespace URIs, and the values should contain their prefixes
        includeNulls - flag stating whether to include empty elements for properties that have a null value
        Since:
        1.0
      • openXmlOutputCursor

        @GloopObjectParameter("output{\n    cursorXmlOutput{\n        writer:object:printer used to write the xml out to::::java.io.Writer\n        outputXmlCursor[]*{\n        }\n    }\n}")
        public static GloopModel openXmlOutputCursor​(String elementName,
                                                     @GloopParameter(defaultValue="true")
                                                     boolean insertHeader,
                                                     Map declaredNamespaces,
                                                     @GloopParameter(defaultValue="true")
                                                     boolean includeNamespaces,
                                                     @GloopParameter(allowNull=false,defaultValue="    ")
                                                     String indent,
                                                     @GloopParameter(defaultValue="true")
                                                     boolean closeDestination,
                                                     Object destination,
                                                     GloopExecutionContext context)
                                              throws IOException

        Return a Gloop output cursor for writing a large amount of XML data.

        Parameters:
        elementName - the name given to the XML element that this cursor will write
        insertHeader - whether to print the XML header <xml version = "1.0">
        declaredNamespaces - map of declared namespaces for this XML
        includeNamespaces - whether to include the namespaces in the XML elements
        indent - indent to use if pretty printing; default is 4 spaces
        closeDestination - set to true if the cursor will close the underlying destination after printing closing text
        destination - where to write the data to; must be a StringBuffer, Writer, OutputStream, Path, or File
        context - the Gloop execution context (automatically mapped by Gloop)
        Returns:
        an output cursor that can be used to add Gloop objects to for writing to XML
        Throws:
        IOException
        Since:
        1.0
      • setCursorElementName

        public static void setCursorElementName​(GloopXmlOutputCursor gloopCursor,
                                                String elementName)
        Sets the element name of an XML output cursor.
        Parameters:
        gloopCursor - XML output cursor
        elementName - element name
        Since:
        1.0