Package io.toro.martini
Class XmlMethods
- java.lang.Object
-
- io.toro.martini.XmlMethods
-
public final class XmlMethods extends Object
Contains one-liners for reading and writing to XML.
-
-
Constructor Summary
Constructors Constructor Description XmlMethods()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static GloopCursor
getInputCursorFromFile(String filename, String encoding, List<String> xmlNodeNames, GloopExecutionContext context)
Return a Gloop input cursor for reading the entries of a large XML file.static GloopCursor
getInputCursorFromInputStream(InputStream inputStream, String encoding, List<String> xmlNodeNames, GloopExecutionContext context)
Return a Gloop input cursor for reading the entries of a large XML stream.static String
gloopObjectToXmlString(GloopObject gloopObject, boolean insertHeader, Map declaredNamespaces)
Marshals a Gloop object to an XML string.static GloopModel
openXmlOutputCursor(String elementName, boolean insertHeader, Map declaredNamespaces, boolean includeNamespaces, String indent, boolean closeDestination, Object destination, GloopExecutionContext context)
Return a Gloop output cursor for writing a large amount of XML data.static GloopObject
readerToGloopObject(Reader xmlString)
Unmarshal an XML string within a reader to a Gloop object.static void
setCursorElementName(GloopXmlOutputCursor gloopCursor, String elementName)
Sets the element name of an XML output cursor.static GloopObject
streamToGloopObject(InputStream xmlString)
Unmarshal an XML string within an input stream to a Gloop object.static void
writeXml(Writer writer, GloopObject gloopObject, boolean insertHeader, boolean includeNamespaces, Map declaredNamespaces, boolean includeNulls)
Marshals a Gloop object to an XML string, written to a writer.static GloopObject
xmlStringToGloopObject(String xmlString)
Unmarshal an XML string to a Gloop object.
-
-
-
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 marshallinsertHeader
- flag stating whether to include the <xml version = "1.0">; headerdeclaredNamespaces
- 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 togloopObject
- Gloop object to marshalinsertHeader
- flag stating whether to include the <xml version = "1.0"> headerincludeNamespaces
- flag stating whether to include namespace declarationsdeclaredNamespaces
- map of pre-declared namespaces already declared (if any); the key should contain the namespace URIs, and the values should contain their prefixesincludeNulls
- flag stating whether to include empty elements for properties that have a null value- Since:
- 1.0
-
getInputCursorFromFile
@GloopObjectParameter("gloopXmlCursor{\n gloopXmlCursor[]{\n nodeName\n cursorRecord:object\n }\n}") public static GloopCursor getInputCursorFromFile(String filename, @GloopParameter(defaultValue="UTF-8") String encoding, List<String> xmlNodeNames, GloopExecutionContext context) throws FileNotFoundException, XMLStreamException, TransformerConfigurationException
Return a Gloop input cursor for reading the entries of a large XML file.
- Parameters:
filename
- the name of the large XML file to readencoding
- encoding used by the XML filexmlNodeNames
- the element names the cursor should be seekingcontext
- the Gloop execution context (automatically mapped by Gloop)- Returns:
- an input cursor that can iterate over all elements found in the XML,
where the element names are in the
xmlNodeNames
parameter - Throws:
FileNotFoundException
XMLStreamException
TransformerConfigurationException
- Since:
- 1.0
-
getInputCursorFromInputStream
@GloopObjectParameter("gloopXmlCursor{\n gloopXmlCursor[]{\n nodeName\n cursorRecord:object\n }\n}") public static GloopCursor getInputCursorFromInputStream(InputStream inputStream, @GloopParameter(defaultValue="UTF-8") String encoding, List<String> xmlNodeNames, GloopExecutionContext context) throws XMLStreamException, TransformerConfigurationException
Return a Gloop input cursor for reading the entries of a large XML stream.
- Parameters:
inputStream
- input stream containing the XML to readencoding
- encoding used by the XML streamxmlNodeNames
- the element names the cursor should be seekingcontext
- the Gloop execution context (automatically mapped by Gloop)- Returns:
- an input cursor that can iterate over all elements found in the XML,
where the element names are in the
xmlNodeNames
parameter - Throws:
XMLStreamException
TransformerConfigurationException
- 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 writeinsertHeader
- whether to print the XML header <xml version = "1.0">declaredNamespaces
- map of declared namespaces for this XMLincludeNamespaces
- whether to include the namespaces in the XML elementsindent
- indent to use if pretty printing; default is 4 spacescloseDestination
- set to true if the cursor will close the underlying destination after printing closing textdestination
- where to write the data to; must be aStringBuffer
,Writer
,OutputStream
,Path
, orFile
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 cursorelementName
- element name- Since:
- 1.0
-
-