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 SummaryConstructors Constructor Description XmlMethods()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static GloopCursorgetInputCursorFromFile(String filename, String encoding, List<String> xmlNodeNames, GloopExecutionContext context)Return a Gloop input cursor for reading the entries of a large XML file.static GloopCursorgetInputCursorFromInputStream(InputStream inputStream, String encoding, List<String> xmlNodeNames, GloopExecutionContext context)Return a Gloop input cursor for reading the entries of a large XML stream.static StringgloopObjectToXmlString(GloopObject gloopObject, boolean insertHeader, Map declaredNamespaces)Marshals a Gloop object to an XML string.static GloopModelopenXmlOutputCursor(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 GloopObjectreaderToGloopObject(Reader xmlString)Unmarshal an XML string within a reader to a Gloop object.static voidsetCursorElementName(GloopXmlOutputCursor gloopCursor, String elementName)Sets the element name of an XML output cursor.static GloopObjectstreamToGloopObject(InputStream xmlString)Unmarshal an XML string within an input stream to a Gloop object.static voidwriteXml(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 GloopObjectxmlStringToGloopObject(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 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
 
 - 
xmlStringToGloopObjectpublic 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
 
 - 
streamToGloopObjectpublic 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
 
 - 
readerToGloopObjectpublic 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
 
 - 
writeXmlpublic 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
 
 - 
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 read
- encoding- encoding used by the XML file
- xmlNodeNames- the element names the cursor should be seeking
- context- 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 xmlNodeNamesparameter
- 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 read
- encoding- encoding used by the XML stream
- xmlNodeNames- the element names the cursor should be seeking
- context- 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 xmlNodeNamesparameter
- 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 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
 
 - 
setCursorElementNamepublic 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
 
 
- 
 
-