Docmosis API 4.5.0

com.docmosis.template.population
Class XMLDataProvider

java.lang.Object
  extended bycom.docmosis.template.population.MemoryDataProvider
      extended bycom.docmosis.template.population.XMLDataProvider
All Implemented Interfaces:
Cleanable, DataProvider, MutableDataProvider, Serializable

public class XMLDataProvider
extends MemoryDataProvider

A data provider that can be converted to or from XML.

See Also:
Serialized Form

Constructor Summary
XMLDataProvider()
          Create a new empty XML Data Provider.
XMLDataProvider(Document doc, XMLNodeFilter filter, boolean includeRoot, StringInterceptor[] interceptors)
          Create a new XML Data Provider with data based on the given Document.
 
Method Summary
protected static void addElementsToDocument(MemoryDataProvider dp, Node node, Document doc)
          Adds all immediate fields to the given XML node.
 void cleanup()
          Perform any cleanup duties such as freeing resources.
 void setInjectedAttributeString(String key)
          Marks the given key as an "injected" or "pushed up" attribute meaning that it was artificially injected into this DP when processing the XML structure.
 Document toXML()
          Convert this Data Provider into XML.
static Document toXML(MemoryDataProvider dp)
          Convert the given Data Provider into XML.
 
Methods inherited from class com.docmosis.template.population.MemoryDataProvider
addDataProvider, finalize, getBoolean, getBooleanKeys, getDataProvider, getDataProviderCount, getDataProviderKeys, getImage, getImageKeys, getRealKey, getString, getStringKeys, hasBooleanKey, hasDataProviderKey, hasImageKey, hasStringKey, setBoolean, setFalse, setImage, setImage, setString, setTrue, toDebugString, toDebugString, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XMLDataProvider

public XMLDataProvider()
Create a new empty XML Data Provider.


XMLDataProvider

public XMLDataProvider(Document doc,
                       XMLNodeFilter filter,
                       boolean includeRoot,
                       StringInterceptor[] interceptors)
Create a new XML Data Provider with data based on the given Document. The given filter may be used to exclude parts of the XML document from being added to this data provider. The root node is optionally included as the root of the data.

Parameters:
doc - the XML Document.
filter - an XML filter to only allow nodes of interest, or null
includeRoot - whether or not the root node of the doc should form the root node of the data or whether data building starts with children
interceptors - interceptors that allow key/value pairs in the data to be processed for custom purposes (such as interpreting as images).
Method Detail

cleanup

public void cleanup()
Description copied from interface: Cleanable
Perform any cleanup duties such as freeing resources. This method should be able to be called multiple times and should not throw exceptions.

Specified by:
cleanup in interface Cleanable
Overrides:
cleanup in class MemoryDataProvider

toXML

public Document toXML()
               throws ParserConfigurationException
Convert this Data Provider into XML.

Returns:
a Document containing the XML nodes representing the data within this Data Provider.
Throws:
ParserConfigurationException - for serious unexpected errors.

toXML

public static Document toXML(MemoryDataProvider dp)
                      throws ParserConfigurationException
Convert the given Data Provider into XML.

Parameters:
dp - the Data Provider to convert to XML
Returns:
a Document containing the XML nodes representing the data within this Data Provider.
Throws:
ParserConfigurationException - for serious unexpected errors.
ClassCastException - if any sub data provider of dp is not a MemoryDataProvider (or subclass).

addElementsToDocument

protected static void addElementsToDocument(MemoryDataProvider dp,
                                            Node node,
                                            Document doc)
Adds all immediate fields to the given XML node. Note that this method recursively calls itself for data providers within data providers. WARN: if any sub data-provider contained is not a MemoryDataProvider (or subclass) a ClassCastException will be thrown

Parameters:
node - the node to add elements to.
doc - any document, only used to create elements.
Throws:
ClassCastException - if the given data provider contains any data provider that is not a MemoryDataProvider (or subclass).

setInjectedAttributeString

public void setInjectedAttributeString(String key)
Marks the given key as an "injected" or "pushed up" attribute meaning that it was artificially injected into this DP when processing the XML structure. The injection makes population much more helpful when arbitrary XML is ambiguous as to what a dave might mean to Docmosis (do we create a person DP containing an anonymous "dave" value or do we create a key/pair "name"/"person" on the current dp?).

Parameters:
key - the key to flag

Docmosis API 4.5.0

Copyright © 2014 Docmosis Pty Ltd. All Rights Reserved.