|
DLESE Tools v1.6.0 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.dlese.dpc.xml.XMLRecord
public class XMLRecord
Creates a wrapper implementation for accessing a JDOM XML document
and for mapping the JDOM elements to a local HashMap
. JDOM
provides the capability to parse, create, edit and write XML documents,
however it lacks an efficient method for locating individual elements,
as well as needing some help with controlling where new elements get
inserted and how comments get processed. It should be noted that
only a limited subset of JDOM's capability is actually utilized by
this implementation.
Individual JDOM XML elements are wrapped in XMLNode
objects before being stored in the local HashMap. The map key for each
XMLNode
is a dot delimited string formed from the paths
through the JDOM hierarchy, obtained when reading in the XML template.
Key paths are constructed and described in the XMLNode
details.
Currently, XMLRecord
is instantiated with an XML
file, to provide the mappings from the JDOM tree to the local
HashMap
. The JDOM document is created, and that
document's root element is wrapped in an XMLNode
. Then each
child element is recursively processed. As each child element is processed,
it is likewise wrapped in an XMLNode
, its key path is
constructed, and then is inserted into the map. Each node maintains the
proper parent-child relations.
Field Summary | |
---|---|
protected org.jdom.Document |
doc
The JDOM document this record maps. |
protected StringBuffer |
footnote
A special comment intended as the final comment in the XML file. |
protected HashMap |
map
Maps reference pointers to elements in the XML hierarchy. |
protected XMLNode |
root
The root node of this XMLRecord . |
protected File |
xmlFile
The source XML file used to identify the XML hierarchy. |
Constructor Summary | |
---|---|
XMLRecord(File file)
Accepts an XML file and maps its XML structure to a HashMap . |
Method Summary | |
---|---|
void |
addNode(XMLNode parent,
org.jdom.Element element)
Adds a JDOM element to the current record. |
void |
addNodes(String name,
XMLNode parent,
int num)
Adds one or more like elements to the current record. |
protected void |
cleanMap(XMLNode node)
Called by removeNodes to remove a node and its children
from the local map. |
void |
clear()
|
protected void |
clearMap(XMLNode node)
|
String |
getFootnote()
Getter method for the XML footnote comment. |
XMLNode |
getNode(String name)
Returns a node of the current record, or null if the node does not exist. |
XMLNode |
getRoot()
Returns the root node of the current record. |
boolean |
outputRecord()
Ouputs the current record to xmlFile , which
is the same file used to create the current record unless
outputRecord(newfile) has been called. |
boolean |
outputRecord(String newfile)
A convenience method for outputting the current record to a given filename. |
protected void |
process(XMLNode parentNode)
Recursively iterates through the children XML elements, wrapping each in an XMLNode and adding the created node to the local map. |
protected void |
processComments()
Process the document's (as opposed to an element's) comments for purposes of extracting the footnote. |
void |
removeNodes(String name,
XMLNode parent,
int num)
Removes one or more like elements from the parent XMLNode . |
void |
setFootnote(String value)
Setter method for the XML footnote comment. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected XMLNode root
XMLRecord
.
protected org.jdom.Document doc
protected HashMap map
protected File xmlFile
protected StringBuffer footnote
Constructor Detail |
---|
public XMLRecord(File file) throws Exception
HashMap
.
file
- A well-formed XML file.
Exception
Method Detail |
---|
public void clear()
protected void clearMap(XMLNode node)
protected void process(XMLNode parentNode)
If called on the root node, this method effectively builds the entire map. If called on a subordinate node, then it will build only the local sub-hierarchy.
parentNode
- The node from which to start processing.public boolean outputRecord(String newfile)
outputRecord
method used to write
the record to that same file. This method, however, reassigns the
protected member xmlFile
in order to write to a new
file. This is done in the case when an XML template file is used,
and the template should be preserved.
newfile
- String representing the filename or absolute filename
of the new file to write.
public boolean outputRecord()
xmlFile
, which
is the same file used to create the current record unless
outputRecord(newfile)
has been called. Once that method
is called, xmlFile
is changed, and subsequent
calls to this method will output to the new file.
public XMLNode getRoot()
XMLNode
wrapper for the JDOM document
root elementpublic XMLNode getNode(String name)
XMLNode
for details on path construction.
name
- String representing the node path in the JDOM tree.
XMLNode
wrapper for the element requestedpublic void addNode(XMLNode parent, org.jdom.Element element)
XMLNode
and processed (added to
the local map).
NOTE: Both parent and element are assumed to be non-null in the current implementation, future implementations will provide this assertion check.
parent
- XMLNode that this element should be added to.element
- A new JDOM element to add to this parent node.public void addNodes(String name, XMLNode parent, int num)
XMLNode
, and it is assumed that
there already exists one such element as a child to the parent node.
If no such like element exists, then it should be created and the
addNode
method called first. Then invoke this method to
add multiples of the same element as new XMLNodes in the local map.
Once the elements are added as nodes to the map, their content
may be defined.
NOTE: New elements are created as copies of existing elements, which means their text content cannot be assumed empty.
name
- String representing the name of like elements to add.parent
- XMLNode that the like elements should be added to.num
- Number of like elements to add.public void removeNodes(String name, XMLNode parent, int num)
XMLNode
.
No more elements can be removed than what exists, and no errors are
generated if an attempt to do so is made. The wrapping nodes are also
removed from the local map, preserving the integrity of the relationship
with the JDOM tree.
name
- String representing the name of the like elements.parent
- XMLNode that the like elements should be removed from.num
- Number of like elements to remove.protected void cleanMap(XMLNode node)
removeNodes
to remove a node and its children
from the local map.
node
- XMLNode to be removed.public String getFootnote()
public void setFootnote(String value)
value
- String representing the footnote comment to add.protected void processComments()
|
DLESE Tools v1.6.0 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |