jv.rsrc
Class PsXmlNode
- java.lang.Object
-
- jv.rsrc.PsXmlNode
-
- All Implemented Interfaces:
- java.io.Serializable
public class PsXmlNode extends java.lang.Object implements java.io.SerializableNode of an XML resource tree. Each node corresponds to an XML element which consists of- a unique string type which is the name of the XML element
- a set of unordered attribute pairs (key, value) of strings
- a link to its father node
- an ordered set of links to all its child nodes
- a link to the next sibling node (i.e. brother resp. sister)
- a content string
- See Also:
- Serialized Form
- Author:
- Konrad Polthier
- Version:
- 22.07.03, 2.20 revised (kp) String appending optimized using internally a string buffer.
10.02.03, 2.10 revised (kp) Blanks in element content now a word character, speed ups.
18.02.01, 2.00 revised (kp) New internal variable for last child added, speed ups.
07.01.01, 1.50 revised (kp) Mixed mode added.
04.02.00, 1.00 created (kp)
-
-
Constructor Summary
Constructors Constructor and Description PsXmlNode(java.lang.String type)Create a new node with given element type.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description voidaddAttribute(java.lang.String key, java.lang.String value)Add an attribute with given key and value to this node.PsXmlNodeaddChild(PsXmlNode child)PsXmlNodeaddChild(java.lang.String type)PsXmlNodeaddChild(java.lang.String type, boolean content)PsXmlNodeaddChild(java.lang.String type, double content)PsXmlNodeaddChild(java.lang.String type, float content)PsXmlNodeaddChild(java.lang.String type, int content)PsXmlNodeaddChild(java.lang.String type, java.lang.String content)voidaddMixedContent(java.lang.Object obj)Add an item to the mixed mode vector.voidappendContent(java.lang.String content)booleancontentEndsWith(char c)Check if current content ends with the given string.voidexpand(boolean flag)Deprecated.use #setExpanded(boolean).java.lang.StringgetAttribute(java.lang.String key)java.util.HashtablegetAttributes()PsXmlNodegetChild()PsXmlNodegetChild(java.lang.String type)Find child with given element type.PsXmlNode[]getChildren()Get all children in given order.PsXmlNode[]getChildren(java.lang.String type)Get children in given order of specified element type.java.lang.StringgetContent()PsXmlNodegetFather()java.util.EnumerationgetMixedContent()Get content of mixed mode vector.intgetNumChildren()PsXmlNodegetSibling()java.lang.StringgetType()Get name of xml type identifying the element.booleanhasChild(java.lang.String type)Check whether this node has a direct child with given element type.booleanhasContent()booleanisExpanded()booleanisMixedMode()Determine whether node is in mixed mode.voidremoveAttribute(java.lang.String key)booleanremoveChild(java.lang.String type)Remove a direct child with given element type.voidremoveChildren()voidsetChild(PsXmlNode child)voidsetContent(java.lang.String content)voidsetExpanded(boolean flag)voidsetFather(PsXmlNode father)voidsetMixedMode(boolean flag)Set flag that node is in mixed mode.voidsetSibling(PsXmlNode sibling)voidsetType(java.lang.String type)Set name of xml type identifying the element.static java.lang.StringBufferwriteNode(java.lang.StringBuffer xml, PsXmlNode node, java.lang.String tab)Writes an XML node including all children but the node's siblings into a string.static booleanwriteNode(java.io.Writer writer, PsXmlNode node, java.lang.String tab)Writes an XML node including all children but the node's siblings into a writer.
-
-
-
Constructor Detail
-
PsXmlNode
public PsXmlNode(java.lang.String type)
Create a new node with given element type.- Parameters:
type- Name of XML element
-
-
Method Detail
-
isMixedMode
public boolean isMixedMode()
Determine whether node is in mixed mode.
-
setMixedMode
public void setMixedMode(boolean flag)
Set flag that node is in mixed mode.
-
addMixedContent
public void addMixedContent(java.lang.Object obj)
Add an item to the mixed mode vector.
-
getMixedContent
public java.util.Enumeration getMixedContent()
Get content of mixed mode vector.
-
getChildren
public PsXmlNode[] getChildren()
Get all children in given order.- Returns:
- array with children
-
getChildren
public PsXmlNode[] getChildren(java.lang.String type)
Get children in given order of specified element type.- Parameters:
type- Name of element- Returns:
- array with children of requested type
-
hasChild
public boolean hasChild(java.lang.String type)
Check whether this node has a direct child with given element type. This method does not search the children of each child.- See Also:
getChild(String)- Version:
- 11.09.01, 1.00 created (kp)
-
removeChild
public boolean removeChild(java.lang.String type)
Remove a direct child with given element type. This method does not search the children of each child.- Parameters:
type- element type of this node- Returns:
trueif child was found and successfully removed.- See Also:
hasChild(String)- Version:
- 04.10.06, 1.00 created (kp)
-
getChild
public PsXmlNode getChild(java.lang.String type)
Find child with given element type. This method searches all direct children of this node and then via depth-first search the children of each child.- See Also:
hasChild(String)
-
addChild
public PsXmlNode addChild(java.lang.String type, java.lang.String content)
-
addChild
public PsXmlNode addChild(java.lang.String type, boolean content)
-
addChild
public PsXmlNode addChild(java.lang.String type, double content)
-
addChild
public PsXmlNode addChild(java.lang.String type, float content)
-
addChild
public PsXmlNode addChild(java.lang.String type, int content)
-
addChild
public PsXmlNode addChild(java.lang.String type)
-
getChild
public PsXmlNode getChild()
-
removeChildren
public void removeChildren()
-
setChild
public void setChild(PsXmlNode child)
-
getType
public java.lang.String getType()
Get name of xml type identifying the element.- Returns:
- name of element
-
setType
public void setType(java.lang.String type)
Set name of xml type identifying the element.- Parameters:
type- name of element
-
isExpanded
public boolean isExpanded()
-
setExpanded
public void setExpanded(boolean flag)
-
expand
public void expand(boolean flag)
Deprecated. use #setExpanded(boolean).
-
getFather
public PsXmlNode getFather()
-
setFather
public void setFather(PsXmlNode father)
-
getSibling
public PsXmlNode getSibling()
-
setSibling
public void setSibling(PsXmlNode sibling)
-
getNumChildren
public int getNumChildren()
-
contentEndsWith
public boolean contentEndsWith(char c)
Check if current content ends with the given string. This class is optimized for this request since the last appended string is saved internally.- Since:
- JavaView 2.87.000
- Version:
- 22.07.03, 1.00 created (kp)
-
hasContent
public boolean hasContent()
-
getContent
public java.lang.String getContent()
-
setContent
public void setContent(java.lang.String content)
-
appendContent
public void appendContent(java.lang.String content)
-
addAttribute
public void addAttribute(java.lang.String key, java.lang.String value)Add an attribute with given key and value to this node.- Version:
- 30.01.04, 1.10 revised (kp) Now accept an empty string "" as value.
-
getAttributes
public java.util.Hashtable getAttributes()
-
getAttribute
public java.lang.String getAttribute(java.lang.String key)
-
removeAttribute
public void removeAttribute(java.lang.String key)
-
writeNode
public static java.lang.StringBuffer writeNode(java.lang.StringBuffer xml, PsXmlNode node, java.lang.String tab)Writes an XML node including all children but the node's siblings into a string. Calls itself recursively on all its children. The indentation tab is increased on children to format the output.Passing a null tab will avoid indentation.
- Parameters:
xml- string buffer to write into, if null then create a new StringBuffer.node- node to save.tab- indentation tab which is increased on children, maybe null string.- Returns:
- a stringbuffer with formatted XML data
- Author:
- Konrad Polthier
- Version:
- 18.08.03, 2.20 revised (kp) Allow null tab to avoid indentation.
09.01.01, 2.10 revised (kp) Method moved to PsXmlNode from jv.loader.PsXmlLoader.
07.01.01, 2.00 revised (kp) Allow mixed mode content.
05.02.00, 1.00 created (kp)
-
writeNode
public static boolean writeNode(java.io.Writer writer, PsXmlNode node, java.lang.String tab) throws java.io.IOExceptionWrites an XML node including all children but the node's siblings into a writer. Calls itself recursively on all its children. The indentation tab is increased on children to format the output.Passing a null tab will avoid indentation.
- Parameters:
writer- Write all data to this streamnode- node to save.tab- indentation tab which is increased on children, maybe null string.- Returns:
trueon success.- Throws:
java.io.IOException- Author:
- Konrad Polthier
- Version:
- 18.08.03, 1.10 revised (kp) Allow null tab to avoid indentation.
18.02.01, 1.00 created (kp) From existing String writeNode() method.
-
-
"