|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectfacets.util.Tracer
facets.util.datatree.Nodes.TreeRoot
facets.util.datatree.XmlDocRoot
public final class XmlDocRoot
Reads and writes a DataNode tree as an XML document.
DataNodes are written as XML elements, their titles and keypair values
as attributes, other stringified values as text nodes (but see Text segregation below).
Nodes to be written need only fulfil the DataNode contract;
elements are read as ValueNodes to
allow the retrieval and setting of attributes as keypairs.
To separate mechanism from policy, Nodes.TreeRoot is declared final and
document-specific values are provided by a XmlPolicy passed to the constructor.
Unless XmlPolicy.treeAsXmlRoot() returns true,
the root of the DataNode tree is assumed to represent the
XML document itself and the first child only of this root is rendered
as the XML root element.
While it may appear cumbersome that the tree root wrapped is not by default
the XML root, this approach has advantages:
StatefulCore.title()s can be mapped to attribute names
using XmlPolicy.getTitleAttributeNames().
Since ValueNode stores XML attributes as keypairs
which cannot be distinguished from text matching Nodes.isKeyPair(String),
XmlDocRoot enforces segregation of text from elements with attributes:
readFromSource(Object) text from an element with attributes
other than that mapped to StatefulCore.title()
(or all elements if XmlPolicy.segregateAll() returns true)
is wrapped in a node created by XmlPolicy.newSegregated(String[]).
As this node may need to be interim to avoid name collisions,
the complete tree can be tidied up as required in
XmlPolicy.cleanUpSegregated(DataNode).
writeToSink(Object)
(unless XmlPolicy.dataUsesAttributes() returns false)
values matching Nodes.isKeyPair(String) are set as element attributes and
no other values from the same node can be written; nodes identified
by XmlPolicy.isSegregated(DataNode) are written as text nodes.
| Field Summary | |
|---|---|
static java.lang.String |
SHEBANG
|
| Fields inherited from class facets.util.datatree.Nodes.TreeRoot |
|---|
tree |
| Constructor Summary | |
|---|---|
XmlDocRoot(DataNode node,
XmlPolicy p)
Unique constructor. |
|
| Method Summary | |
|---|---|
static TextLines |
newDocumentXml(org.w3c.dom.Document document)
Creates XML text from a Document. |
static org.w3c.dom.Document |
newXmlDocument(TextLines xml)
Reads XML text into a Document. |
static java.lang.String |
newXmlTop(java.lang.String encoding)
|
void |
readFromSource(java.lang.Object src)
Reads an XML document from text. |
void |
writeToSink(java.lang.Object sink)
Creates XML document text. |
| Methods inherited from class facets.util.Tracer |
|---|
trace, trace, trace, trace, trace, traceDebug, traceDebug, traceObjectText, traceOutput, traceOutputWithClass |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String SHEBANG
| Constructor Detail |
|---|
public XmlDocRoot(DataNode node,
XmlPolicy p)
node - passed to superclassp - defines detail behaviour| Method Detail |
|---|
public void readFromSource(java.lang.Object src)
throws java.io.IOException
Text obtained from src is read as follows:
XmlPolicy.treeAsXmlRoot()
returns true)
ExceptionNode set as the
contents of the node.
Each XML element is read into a ValueNode with:
type
children
XmlPolicy.newTitleAttributeNames(String, String[]);
readFromSource in class Nodes.TreeRootsrc - must be either a File or a TextLines
java.io.IOException
public void writeToSink(java.lang.Object sink)
throws java.io.IOException
XML text that renders the DataNode tree wrapped is written to sink,
with members of the tree rendered as XML elements, except for those identified by
XmlPolicy.isSegregated(DataNode) which are rendered as text nodes.
For other nodes the type is used as the element name and
any title other than TypedNode.UNTITLED
is rendered by an attribute as
documented in XmlPolicy.newTitleAttributeNames(String,String[]).
Stringified values are rendered as follows:
XmlPolicy.dataUsesAttributes() returns true and
all values are keypairs, as attributes
writeToSink in class Nodes.TreeRootsink - must be either a File or a TextLines
java.io.IOException
public static org.w3c.dom.Document newXmlDocument(TextLines xml)
throws javax.xml.parsers.ParserConfigurationException,
org.xml.sax.SAXException,
java.io.IOException
Document.
Called internally by readFromSource(Object); exposed to enable
creation of Documents from text rather than a stream.
xml - loaded with XML text
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException
public static TextLines newDocumentXml(org.w3c.dom.Document document)
throws javax.xml.transform.TransformerFactoryConfigurationError,
javax.xml.transform.TransformerConfigurationException,
javax.xml.transform.TransformerException
Document.
Used internally by writeToSink(Object) to enable post-processing of
XML text in XmlPolicy.prettifyRawXML(String); exposed to enable
temporary storage of a Documents as text.
TextLines.newBuffer(String[]) loaded with XML text
javax.xml.transform.TransformerFactoryConfigurationError
javax.xml.transform.TransformerConfigurationException
javax.xml.transform.TransformerExceptionpublic static final java.lang.String newXmlTop(java.lang.String encoding)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||