Package javaforce.webui
Class XMLTree
java.lang.Object
javaforce.webui.XMLTree
- All Implemented Interfaces:
TreeModelListener
XML is a TreeModel data model that encapsules a complete XML file.
Each XML tag (element) is treated as a node in the tree. Once read() it can be viewed and edited with a JTree. Then you can write() it back to a file. XML will monitor changes made and update nodes as needed. The read() functions include a callback interface so you can further tweak the layout of the XML tree.
Typical XML Tag:
<name [attributes...]> content | children </name>
Singleton XML Tag: (no children)
<name [attributes...] />
Caveats:
Only leaf nodes can contain actual data (content) (in other words @XmlMixed is not supported).
Mixed tags are read, but when written the content is lost.
There must be only one root tag.
Support for the standard XML header is provided (see header).
readClass() and writeClass() support : int, short, byte, float, double, boolean, String, Color and Custom Classes.
Arrays of any of these.
All classes and fields MUST be public. static and transient members are skipped. No special annotations are required.
Each XML tag (element) is treated as a node in the tree. Once read() it can be viewed and edited with a JTree. Then you can write() it back to a file. XML will monitor changes made and update nodes as needed. The read() functions include a callback interface so you can further tweak the layout of the XML tree.
Typical XML Tag:
<name [attributes...]> content | children </name>
Singleton XML Tag: (no children)
<name [attributes...] />
Caveats:
Only leaf nodes can contain actual data (content) (in other words @XmlMixed is not supported).
Mixed tags are read, but when written the content is lost.
There must be only one root tag.
Support for the standard XML header is provided (see header).
readClass() and writeClass() support : int, short, byte, float, double, boolean, String, Color and Custom Classes.
Arrays of any of these.
All classes and fields MUST be public. static and transient members are skipped. No special annotations are required.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassXMLAttr is one attribute that is listed in each XML tag.static interfaceXMLEvent is an interface for a callback handler used during XML loading.class -
Field Summary
FieldsModifier and TypeFieldDescriptionThe XML header tag.The root tag. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddSetTag(XMLTree.XMLTag targetParent, String name, String attrs, String content) Adds (a non-existing) or sets (an existing) node with the name, attrs and content specified.addTag(XMLTree.XMLTag targetParent, String name, String attrs, String content) Adds node with the name, attrs and content specified.addTag(XMLTree.XMLTag targetParent, XMLTree.XMLTag tag) Adds the node to the targetParent.voidchangedTag(XMLTree.XMLTag tag) Notify the treemodel that you changed a node.Creates an empty node that can be inserted into the tree using addTag().voidDeletes the entire tree and resets the root and header tags.booleandeleteTag(XMLTree.XMLTag tag) Deletes a node from the parent.getName(XMLTree.XMLTag tag) Returns the unique name of a node.Returns a node based on the objs[] path.Returns a node based on the TreePath path;Returns the TreeModel that can be passed to WebUI Tree constructor.booleanForces getName() to return the tags content instead of the actual name.booleanForces getName() to return the tags content instead of the actual name.booleanForces getName() to return the tags content instead of the actual name.booleanread(InputStream in) Reads the entire tree from a XML file from the InputStream.booleanread(InputStream is, XMLTree.XMLEvent event) Reads the entire tree from a XML file from the InputStream.booleanReads the entire tree from a XML file from filename.booleanread(String filename, XMLTree.XMLEvent event) Reads the entire tree from a XML file from filename.voidReads entire XML tree from object (deletes entire tree first).voidreadClass(XMLTree.XMLTag tag, Object obj) Reads all fields from an object and places into tag.voidsetEventListener(XMLTree.XMLEvent event) voidsetName(XMLTree.XMLTag tag, String newName) Sets the name of a node.voidSets the name, attrs and contents of the true root node.voidsetRoot(XMLTree.XMLTag newRoot) Sets the root node for the tree.voidsetTag(XMLTree.XMLTag tag, String name, String attrs, String content) Sets the name, attrs and content for an existing node.voidsetUseAttributeNameForName(boolean state) Forces getName() to return the tags attribute 'name' (if available)voidsetUseContentForName(boolean state) Forces getName() to return the tags content instead of the actual name.voidsetUseUniqueNames(boolean state) Forces getName() to return unique names.voidvoidvoidvoidbooleanwrite(OutputStream os) Writes the entire tree as a XML file to the OutputStream.booleanWrites the entire tree as a XML file to the filename.voidwriteClass(Object obj) Writes entire XML tree to object.voidwriteClass(XMLTree.XMLTag tag, Object obj) Writes all children of tag to object.
-
Field Details
-
header
The XML header tag. -
root
The root tag.
-
-
Constructor Details
-
XMLTree
public XMLTree()Constructs a new XML object.
-
-
Method Details
-
getTreeModel
Returns the TreeModel that can be passed to WebUI Tree constructor. -
read
Reads the entire tree from a XML file from filename. No call handler is used.- Parameters:
filename- name of file to load XML data from
-
read
Reads the entire tree from a XML file from filename.- Parameters:
filename- name of file to load XML data fromevent- callback handler to process each loaded XML tag
-
read
Reads the entire tree from a XML file from the InputStream. No callback handler is used.- Parameters:
in- InputStream to load XML data from
-
read
Reads the entire tree from a XML file from the InputStream.- Parameters:
is- InputStream to load XML data fromevent- callback handler to process each loaded XML tag
-
write
Writes the entire tree as a XML file to the filename. -
write
Writes the entire tree as a XML file to the OutputStream. -
deleteAll
public void deleteAll()Deletes the entire tree and resets the root and header tags. -
deleteTag
Deletes a node from the parent. Also deletes all it's children. -
createTag
Creates an empty node that can be inserted into the tree using addTag(). -
addTag
Adds the node to the targetParent. -
addTag
public XMLTree.XMLTag addTag(XMLTree.XMLTag targetParent, String name, String attrs, String content) Adds node with the name, attrs and content specified. If another node already exists with the same name the new node's unique name will differ. -
addSetTag
public XMLTree.XMLTag addSetTag(XMLTree.XMLTag targetParent, String name, String attrs, String content) Adds (a non-existing) or sets (an existing) node with the name, attrs and content specified. -
changedTag
Notify the treemodel that you changed a node. -
setRoot
Sets the name, attrs and contents of the true root node. -
getName
Returns the unique name of a node. -
setName
Sets the name of a node. It's unique name may differ when shown in a tree. -
getTag
Returns a node based on the TreePath path; -
getTag
Returns a node based on the objs[] path. Relative to virtual root tag. (see setRoot()) -
setTag
Sets the name, attrs and content for an existing node. -
setRoot
Sets the root node for the tree. This doesn't effect the true root node. This is usefull in hiding parts of a XML file from view when viewed in a JTree. -
setUseContentForName
public void setUseContentForName(boolean state) Forces getName() to return the tags content instead of the actual name.- Parameters:
state-
-
getUseContentForName
public boolean getUseContentForName()Forces getName() to return the tags content instead of the actual name. -
setUseAttributeNameForName
public void setUseAttributeNameForName(boolean state) Forces getName() to return the tags attribute 'name' (if available)- Parameters:
state-
-
getUseAttributeNameForName
public boolean getUseAttributeNameForName()Forces getName() to return the tags content instead of the actual name. -
setUseUniqueNames
public void setUseUniqueNames(boolean state) Forces getName() to return unique names.- Parameters:
state-
-
getUseUniqueNames
public boolean getUseUniqueNames()Forces getName() to return the tags content instead of the actual name. -
writeClass
Writes all children of tag to object. -
writeClass
Writes entire XML tree to object. -
readClass
Reads all fields from an object and places into tag. -
readClass
Reads entire XML tree from object (deletes entire tree first).- Parameters:
rootName- = name to assign to root tag.
-
setEventListener
-
treeNodesChanged
- Specified by:
treeNodesChangedin interfaceTreeModelListener
-
treeNodesInserted
- Specified by:
treeNodesInsertedin interfaceTreeModelListener
-
treeNodesRemoved
- Specified by:
treeNodesRemovedin interfaceTreeModelListener
-
treeStructureChanged
- Specified by:
treeStructureChangedin interfaceTreeModelListener
-