public class XmlSink
extends java.lang.Object
When writing a complete XML file, this sink will close the underlying writer automatically when the root node is completed. Of course, explicit closing is also possible using the function abandon.
The basic sequence of writing a node is startNode,sinkAttribute zero or more times,do various contents,closeNode. Contents consist of more nodes or text (sinkText).
Constructor and Description |
---|
XmlSink()
Constructor for sink that builds up an XML string using default options.
|
XmlSink(java.io.File file)
Constructor for instance that write XML to a file
|
XmlSink(java.io.File file,
XmlWriteOptions writeOptions)
Constructor for instance that write XML to a file
|
XmlSink(IndentingLineSink lineSink)
Constructor.
|
XmlSink(IndentingLineSink lineSink,
XmlWriteOptions writeOptions)
Constructor.
|
XmlSink(XmlWriteOptions writeOptions)
Constructor for sink that builds up an XML string.
|
Modifier and Type | Method and Description |
---|---|
void |
abandon()
Closes underlying writer.
|
static void |
arrayToFile(java.lang.String arrayRelativeName,
XmlNameSpace arrayNameSpace,
XmlSinkWritable[] objects,
java.io.File xmlFile)
Makes an XML file which contains the objects's XML representation,
utilising the objects's XML functionality.
|
static void |
arrayToFile(java.lang.String arrayRelativeName,
XmlNameSpace arrayNameSpace,
XmlSinkWritable[] objects,
java.io.File xmlFile,
XmlWriteOptions options)
Makes an XML file which contains the objects's XML representation,
utilising the objects's XML functionality.
|
static void |
arrayToFile(java.lang.String arrayName,
XmlSinkWritable[] objects,
java.io.File xmlFile)
Makes an XML file which contains the objects's XML representation,
utilising the objects's XML functionality.
|
static void |
arrayToFile(java.lang.String arrayName,
XmlSinkWritable[] objects,
java.io.File xmlFile,
XmlWriteOptions options)
Makes an XML file which contains the objects's XML representation,
utilising the objects's XML functionality.
|
static void |
arrayToFile(TagNodeId arrayId,
XmlSinkWritable[] objects,
java.io.File xmlFile)
Makes an XML file which contains the objects's XML representation,
utilising the objects's XML functionality.
|
static void |
arrayToFile(TagNodeId arrayId,
XmlSinkWritable[] objects,
java.io.File xmlFile,
XmlWriteOptions options)
Makes an XML file which contains the objects's XML representation,
utilising the objects's XML functionality.
|
static java.lang.String |
arrayToString(java.lang.String arrayRelativeName,
XmlNameSpace arrayNameSpace,
XmlSinkWritable[] objects)
Converts an array of objects to an XML string using the objects's XML
functionality.
|
static java.lang.String |
arrayToString(java.lang.String arrayRelativeName,
XmlNameSpace arrayNameSpace,
XmlSinkWritable[] objects,
XmlWriteOptions options)
Converts an array of objects to an XML string using the objects's XML
functionality.
|
static java.lang.String |
arrayToString(java.lang.String arrayName,
XmlSinkWritable[] objects)
Converts an array of objects to an XML string using the objects's XML
functionality.
|
static java.lang.String |
arrayToString(java.lang.String arrayName,
XmlSinkWritable[] objects,
XmlWriteOptions options)
Converts an array of objects to an XML string using the objects's XML
functionality.
|
static java.lang.String |
arrayToString(TagNodeId arrayId,
XmlSinkWritable[] objects)
Converts an array of objects to an XML string using the objects's XML
functionality.
|
static java.lang.String |
arrayToString(TagNodeId arrayId,
XmlSinkWritable[] objects,
XmlWriteOptions options)
Converts an array of objects to an XML string using the objects's XML
functionality.
|
void |
closeNode()
Closes the currently open node.
|
void |
closeTagAndNode()
Closes the start tag such that no end tag is required.
|
void |
declareNameSpace(XmlNameSpace nameSpace)
Declares a name space (unless the name space is already declared).
|
static void |
objectToFile(XmlSinkWritable object,
java.io.File xmlFile)
Makes an XML file which contains the object's XML representation,
utilising the object's XML functionality.
|
static void |
objectToFile(XmlSinkWritable object,
java.io.File xmlFile,
XmlWriteOptions options)
Makes an XML file which contains the object's XML representation,
utilising the object's XML functionality.
|
static java.lang.String |
objectToString(XmlSinkWritable object)
Converts an object to an XML string using the object's XML functionality.
|
static java.lang.String |
objectToString(XmlSinkWritable object,
XmlWriteOptions options)
Converts an object to an XML string using the object's XML functionality.
|
void |
sinkArrayNode(java.lang.String arrayRelativeName,
XmlNameSpace arrayNameSpace,
XmlSinkWritable[] contents)
Sinks an array node of elements that write themselves to XML.
|
void |
sinkArrayNode(java.lang.String arrayNodeName,
XmlSinkWritable[] contents)
Sinks an array node of elements that write themselves to XML.
|
void |
sinkArrayNode(TagNodeId arrayId,
XmlSinkWritable[] objects)
Sinks an array node of elements that write themselves to XML.
|
void |
sinkAttribute(java.lang.String name,
boolean value)
Sinks an attribute which is not in a name space.
|
void |
sinkAttribute(java.lang.String name,
double value)
Sinks an attribute which is not in a name space.
|
void |
sinkAttribute(java.lang.String name,
float value)
Sinks an attribute which is not in a name space.
|
void |
sinkAttribute(java.lang.String name,
int value)
Sinks an attribute which is not in a name space.
|
void |
sinkAttribute(java.lang.String name,
long value)
Sinks an attribute which is not in a name space.
|
void |
sinkAttribute(java.lang.String name,
java.lang.Object value)
Sinks an attribute which is not in a name space.
|
void |
sinkAttribute(java.lang.String name,
java.lang.String value)
Sinks an attribute which is not in a name space.
|
void |
sinkAttribute(XmlAttribute attribute)
Sinks an attribute, other than a name space declaration.
|
void |
sinkClassOfObjectAttribute(java.lang.Object object)
Records class of object in attribute
ConventionConstants.LABEL_FOR_CLASS_NAME_OF_OBJECT . |
void |
sinkNode(java.lang.String relativeName,
XmlNameSpace nameSpace,
XmlSinkWritable object)
Causes a structured object to write itself to our XML.
|
void |
sinkNode(java.lang.String nodeName,
XmlSinkWritable object)
Causes a structured object to write itself to our XML.
|
void |
sinkNode(TagNodeId id,
XmlSinkWritable object)
Causes a structured object to write itself to our XML.
|
void |
sinkNode(XmlSinkWritable object)
Causes a structured object to write itself to our XML.
|
void |
sinkSimpleNode(java.lang.String nodeName,
boolean contents)
Makes a simple node, consisting of open tag, value, close tag.
|
void |
sinkSimpleNode(java.lang.String nodeName,
char contents)
Makes a simple node, consisting of open tag, value, close tag.
|
void |
sinkSimpleNode(java.lang.String nodeName,
double contents)
Makes a simple node, consisting of open tag, value, close tag.
|
void |
sinkSimpleNode(java.lang.String nodeName,
float contents)
Makes a simple node, consisting of open tag, value, close tag.
|
void |
sinkSimpleNode(java.lang.String nodeName,
int contents)
Makes a simple node, consisting of open tag, value, close tag.
|
void |
sinkSimpleNode(java.lang.String nodeName,
long contents)
Makes a simple node, consisting of open tag, value, close tag.
|
void |
sinkSimpleNode(java.lang.String nodeName,
java.lang.Object object)
Makes a simple node, consisting of open tag, value, close tag.
|
void |
sinkSimpleNode(java.lang.String nodeName,
java.lang.String contents)
Makes a simple node, consisting of open tag, value, close tag.
|
void |
sinkSimpleNode(java.lang.String relativeName,
XmlNameSpace nameSpace,
boolean contents)
Sinks a simple node consisting of open tag, contents, close tag.
|
void |
sinkSimpleNode(java.lang.String relativeName,
XmlNameSpace nameSpace,
double contents)
Sinks a simple node consisting of open tag, contents, close tag.
|
void |
sinkSimpleNode(java.lang.String relativeName,
XmlNameSpace nameSpace,
float contents)
Sinks a simple node consisting of open tag, contents, close tag.
|
void |
sinkSimpleNode(java.lang.String relativeName,
XmlNameSpace nameSpace,
int contents)
Sinks a simple node consisting of open tag, contents, close tag.
|
void |
sinkSimpleNode(java.lang.String relativeName,
XmlNameSpace nameSpace,
long contents)
Sinks a simple node consisting of open tag, contents, close tag.
|
void |
sinkSimpleNode(java.lang.String relativeName,
XmlNameSpace nameSpace,
java.lang.Object object)
Sinks a simple node consisting of open tag, string representation of object, close tag.
|
void |
sinkSimpleNode(java.lang.String relativeName,
XmlNameSpace nameSpace,
java.lang.String contents)
Sinks a simple node consisting of open tag, contents, close tag.
|
void |
sinkSimpleNode(TagNodeId id,
boolean contents)
Sinks a simple node, consisting of open tag, contents, close tag
|
void |
sinkSimpleNode(TagNodeId id,
double contents)
Sinks a simple node, consisting of open tag, contents, close tag
|
void |
sinkSimpleNode(TagNodeId id,
float contents)
Sinks a simple node, consisting of open tag, contents, close tag
|
void |
sinkSimpleNode(TagNodeId id,
int contents)
Sinks a simple node, consisting of open tag, contents, close tag
|
void |
sinkSimpleNode(TagNodeId id,
long contents)
Sinks a simple node, consisting of open tag, contents, close tag
|
void |
sinkSimpleNode(TagNodeId id,
java.lang.Object object)
Sinks a simple node, consisting of open tag, string representation of object, close tag.
|
void |
sinkSimpleNode(TagNodeId id,
java.lang.String contents)
Sinks a simple node, consisting of open tag, contents, close tag
|
void |
sinkText(java.lang.String text)
Sinks the sort of text that goes between start and end tag.
|
void |
sinkToStringArrayNode(java.lang.String arrayNodeName,
java.lang.String elementNodeName,
java.lang.Object[] contents)
Sinks array of objects by calling toString on them to get string representation.
|
void |
sinkToStringArrayNode(java.lang.String relativeArrayName,
XmlNameSpace arrayNameSpace,
java.lang.String elementRelativeName,
XmlNameSpace elementNameSpace,
java.lang.Object[] contents)
Sinks array of objects by calling toString on them to get string representation.
|
void |
sinkToStringArrayNode(TagNodeId arrayId,
TagNodeId elementId,
java.lang.Object[] contents)
Sinks array of objects by calling toString on them to get string representation.
|
void |
startNode(java.lang.String nodeName)
Starts a node.
|
void |
startNode(java.lang.String relativeName,
XmlNameSpace nameSpace)
Starts a start tag for a node.
|
void |
startNode(TagNodeId id)
Starts a node.
|
java.lang.String |
toString()
When building up a string as opposed to writing a file,
you can obtain the XML string through this function.
|
public XmlSink(java.io.File file)
file
- destination for the XMLpublic XmlSink(java.io.File file, XmlWriteOptions writeOptions)
file
- destination for the XMLwriteOption
- public XmlSink()
public XmlSink(XmlWriteOptions writeOptions)
writeOptions
- public XmlSink(IndentingLineSink lineSink)
lineSink
- Make sure this doesn't already have stuff in it, or you could end up with invalid XNL.public XmlSink(IndentingLineSink lineSink, XmlWriteOptions writeOptions)
lineSink
- Make sure this doesn't already have stuff in it, or you could end up with invalid XNL.writeOptions
- public void startNode(java.lang.String relativeName, XmlNameSpace nameSpace)
relativeName
- nameSpace
- public void sinkText(java.lang.String text) throws UnsupportedCharacterEncodeException
text
- Text to go between start and end tag.UnsupportedCharacterEncodeException
public void closeNode()
public void closeTagAndNode()
public void abandon()
This function is named as it is to avoid confusion with the functions that close node and start tag.
public void sinkAttribute(XmlAttribute attribute)
Name space declaration is a tricky business. Because of prefix clashes, a prefix might need to be assigned which is different to the one that was specified. As this function writes attributes exactly as specified, it is not suitable for name space declarations.
attribute
- public void declareNameSpace(XmlNameSpace nameSpace)
There are a few things you should know about declaring name spaces:
nameSpace
- public java.lang.String toString()
toString
in class java.lang.Object
public void sinkAttribute(java.lang.String name, java.lang.String value) throws UnsupportedCharacterEncodeException
name
- of the attributevalue
- of the attributeUnsupportedCharacterEncodeException
public void sinkAttribute(java.lang.String name, java.lang.Object value)
name
- of the attributevalue
- object on which the toString function is called to obtain the value text.UnsupportedCharacterEncodeException
public void sinkAttribute(java.lang.String name, int value)
name
- of the attributevalue
- of the attributeUnsupportedCharacterEncodeException
public void sinkAttribute(java.lang.String name, long value)
name
- of the attributevalue
- of the attributeUnsupportedCharacterEncodeException
public void sinkAttribute(java.lang.String name, float value)
name
- of the attributevalue
- of the attributeUnsupportedCharacterEncodeException
public void sinkAttribute(java.lang.String name, double value)
name
- of the attributevalue
- of the attributeUnsupportedCharacterEncodeException
public void sinkAttribute(java.lang.String name, boolean value)
name
- of the attributevalue
- of the attributeUnsupportedCharacterEncodeException
public void sinkSimpleNode(java.lang.String nodeName, java.lang.String contents)
nodeName
- name of the nodecontents
- value between the tags. Can be null. if so, the method does nothing.public void sinkSimpleNode(java.lang.String nodeName, java.lang.Object object)
nodeName
- name of the nodeobject
- source of value, value obtained through toString function.
object may be null. If so, the method does nothing.public void sinkSimpleNode(java.lang.String nodeName, int contents)
nodeName
- name of the nodecontents
- value between the tags. Can be null. if so, the method does nothing.public void sinkSimpleNode(java.lang.String nodeName, long contents)
nodeName
- name of the nodecontents
- value between the tags. Can be null. if so, the method does nothing.public void sinkSimpleNode(java.lang.String nodeName, float contents)
nodeName
- name of the nodecontents
- value between the tags. Can be null. if so, the method does nothing.public void sinkSimpleNode(java.lang.String nodeName, double contents)
nodeName
- name of the nodecontents
- value between the tags. Can be null. if so, the method does nothing.public void sinkSimpleNode(java.lang.String nodeName, boolean contents)
nodeName
- name of the nodecontents
- value between the tags. Can be null. if so, the method does nothing.public void sinkSimpleNode(java.lang.String nodeName, char contents)
nodeName
- name of the nodecontents
- value between the tags. Can be null. if so, the method does nothing.public void sinkNode(java.lang.String nodeName, XmlSinkWritable object)
nodeName
- name of the node that will contain the structured objectobject
- the object that writes itself to our XML.public void startNode(java.lang.String nodeName)
nodeName
- public void sinkClassOfObjectAttribute(java.lang.Object object)
ConventionConstants.LABEL_FOR_CLASS_NAME_OF_OBJECT
.
This method exists to support higher level XML functions like creating objects from XML through factories
while allowing inheritance.
See overview document.object
- The object whose class we want to record in an attribute.public void sinkSimpleNode(java.lang.String relativeName, XmlNameSpace nameSpace, java.lang.String contents)
relativeName
- for the nodenameSpace
- for the nodecontents
- for between open and close tagpublic void sinkSimpleNode(java.lang.String relativeName, XmlNameSpace nameSpace, java.lang.Object object)
relativeName
- for the nodenameSpace
- for the nodeobject
- String representation goes between open and close tagpublic void sinkSimpleNode(java.lang.String relativeName, XmlNameSpace nameSpace, int contents)
relativeName
- for the nodenameSpace
- for the nodecontents
- for between open and close tagpublic void sinkSimpleNode(java.lang.String relativeName, XmlNameSpace nameSpace, long contents)
relativeName
- for the nodenameSpace
- for the nodecontents
- for between open and close tagpublic void sinkSimpleNode(java.lang.String relativeName, XmlNameSpace nameSpace, float contents)
relativeName
- for the nodenameSpace
- for the nodecontents
- for between open and close tagpublic void sinkSimpleNode(java.lang.String relativeName, XmlNameSpace nameSpace, double contents)
relativeName
- for the nodenameSpace
- for the nodecontents
- for between open and close tagpublic void sinkSimpleNode(java.lang.String relativeName, XmlNameSpace nameSpace, boolean contents)
relativeName
- for the nodenameSpace
- for the nodecontents
- for between open and close tagpublic void sinkNode(XmlSinkWritable object)
object
- the object that writes itself to our XML.public void sinkNode(java.lang.String relativeName, XmlNameSpace nameSpace, XmlSinkWritable object)
relativeName
- of the node that will contain the structured object.
Can be null, then the object will chose it's own
node name/id.nameSpace
- of the node that will contain the structured objectobject
- the object that writes itself to our XML.public void sinkToStringArrayNode(java.lang.String arrayNodeName, java.lang.String elementNodeName, java.lang.Object[] contents)
arrayNodeName
- elementNodeName
- contents
- public void sinkToStringArrayNode(TagNodeId arrayId, TagNodeId elementId, java.lang.Object[] contents)
arrayId
- elementId
- contents
- public void sinkToStringArrayNode(java.lang.String relativeArrayName, XmlNameSpace arrayNameSpace, java.lang.String elementRelativeName, XmlNameSpace elementNameSpace, java.lang.Object[] contents)
relativeArrayName
- arrayNameSpace
- elementRelativeName
- elementNameSpace
- contents
- public void sinkArrayNode(TagNodeId arrayId, XmlSinkWritable[] objects)
arrayId
- for the array node. For the node names/ids of elements,
the natural id of the elements will be used.objects
- will write themselves to XMLpublic void sinkArrayNode(java.lang.String arrayNodeName, XmlSinkWritable[] contents)
arrayNodeName
- for the array node. For the node names/ids of elements,
the natural id of the elements will be used.objects
- will write themselves to XMLpublic void sinkArrayNode(java.lang.String arrayRelativeName, XmlNameSpace arrayNameSpace, XmlSinkWritable[] contents)
arrayRelativeName
- for the array node. For the node names/ids of elements,
the natural id of the elements will be used.arrayNameSpace
- for the array nodeobjects
- will write themselves to XMLpublic void sinkSimpleNode(TagNodeId id, java.lang.String contents)
id
- of the nodecontents
- for between the tagspublic void sinkSimpleNode(TagNodeId id, java.lang.Object object)
id
- of the nodeobject
- string representation goes between open and close tagpublic void sinkSimpleNode(TagNodeId id, int contents)
id
- of the nodecontents
- for between the tagspublic void sinkSimpleNode(TagNodeId id, long contents)
id
- of the nodecontents
- for between the tagspublic void sinkSimpleNode(TagNodeId id, float contents)
id
- of the nodecontents
- for between the tagspublic void sinkSimpleNode(TagNodeId id, double contents)
id
- of the nodecontents
- for between the tagspublic void sinkSimpleNode(TagNodeId id, boolean contents)
id
- of the nodecontents
- for between the tagspublic void sinkNode(TagNodeId id, XmlSinkWritable object)
id
- for the node that will contain the structured objectobject
- the object that writes itself to our XML.public void startNode(TagNodeId id)
id
- for the nodepublic static java.lang.String objectToString(XmlSinkWritable object)
object
- for conversion to XMLpublic static java.lang.String objectToString(XmlSinkWritable object, XmlWriteOptions options)
object
- for conversion to XMLpublic static java.lang.String arrayToString(TagNodeId arrayId, XmlSinkWritable[] objects)
arrayId
- for the array nodeobjects
- to be converted to XMLpublic static java.lang.String arrayToString(java.lang.String arrayName, XmlSinkWritable[] objects)
arrayName
- for the array nodeobjects
- to be converted to XMLpublic static java.lang.String arrayToString(java.lang.String arrayRelativeName, XmlNameSpace arrayNameSpace, XmlSinkWritable[] objects)
arrayRelativeName
- for the array nodearrayNameSpace
- for the array nodeobjects
- to be converted to XMLpublic static java.lang.String arrayToString(TagNodeId arrayId, XmlSinkWritable[] objects, XmlWriteOptions options)
arrayId
- for the array nodeobjects
- to be converted to XMLoptions
- public static java.lang.String arrayToString(java.lang.String arrayName, XmlSinkWritable[] objects, XmlWriteOptions options)
arrayName
- for the array nodeobjects
- to be converted to XMLoptions
- public static java.lang.String arrayToString(java.lang.String arrayRelativeName, XmlNameSpace arrayNameSpace, XmlSinkWritable[] objects, XmlWriteOptions options)
arrayRelativeName
- for the array nodearrayNameSpace
- for the array nodeobjects
- to be converted to XMLoptions
- public static void objectToFile(XmlSinkWritable object, java.io.File xmlFile)
object
- to be converted to XMLxmlFile
- will contain the XMLpublic static void objectToFile(XmlSinkWritable object, java.io.File xmlFile, XmlWriteOptions options)
object
- to be converted to XMLxmlFile
- will contain the XMLoptions
- public static void arrayToFile(TagNodeId arrayId, XmlSinkWritable[] objects, java.io.File xmlFile)
arrayId
- for the arrayNodeobjects
- to be converted to XMLxmlFile
- will contain the XMLpublic static void arrayToFile(java.lang.String arrayName, XmlSinkWritable[] objects, java.io.File xmlFile)
arrayName
- for the arrayNodeobjects
- to be converted to XMLxmlFile
- will contain the XMLpublic static void arrayToFile(java.lang.String arrayRelativeName, XmlNameSpace arrayNameSpace, XmlSinkWritable[] objects, java.io.File xmlFile)
arrayRelativeName
- for the arrayNodearrayNameSpace
- for the arrayNodeobjects
- to be converted to XMLxmlFile
- will contain the XMLpublic static void arrayToFile(TagNodeId arrayId, XmlSinkWritable[] objects, java.io.File xmlFile, XmlWriteOptions options)
arrayId
- for the arrayNodeobjects
- to be converted to XMLxmlFile
- will contain the XMLoptions
- public static void arrayToFile(java.lang.String arrayName, XmlSinkWritable[] objects, java.io.File xmlFile, XmlWriteOptions options)
arrayName
- for the arrayNodeobjects
- to be converted to XMLxmlFile
- will contain the XMLoptions
- public static void arrayToFile(java.lang.String arrayRelativeName, XmlNameSpace arrayNameSpace, XmlSinkWritable[] objects, java.io.File xmlFile, XmlWriteOptions options)
arrayRelativeName
- for the arrayNodearrayNameSpace
- for the arrayNodeobjects
- to be converted to XMLxmlFile
- will contain the XMLoptions
-