Package adams.doc.xml
Class AbstractTag
- java.lang.Object
-
- javax.swing.tree.DefaultMutableTreeNode
-
- adams.doc.xml.AbstractTag
-
- All Implemented Interfaces:
Serializable
,Cloneable
,MutableTreeNode
,TreeNode
- Direct Known Subclasses:
AbstractComplexTag
,AbstractMixedTag
,AbstractSimpleTag
,Break
public abstract class AbstractTag extends DefaultMutableTreeNode
The ancestor of all DocBook and HTML tags.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Hashtable<String,String>
m_Attributes
the attributes.-
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
-
-
Constructor Summary
Constructors Constructor Description AbstractTag(String tag)
Initializes the tag.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
appendContent(StringBuilder buffer)
Appends the content of the element to the buffer.protected void
appendEndTag(StringBuilder buffer)
Appends the end tag to the buffer.protected void
appendStartTag(StringBuilder buffer)
Appends the start tag to the buffer.protected void
doInsert(MutableTreeNode newChild, int childIndex)
Performs the actual inserting of a child element.protected void
doValidate()
Hook method for validating/fixing the XML tree.String
getAttribute(String name)
Returns the value of an attribute.protected String
getIndentation()
Returns the indentation string, depending on the elements level in the XML tree.String
getTag()
Returns the tag name.boolean
hasAttribute(String name)
Checks whether an attribute with the specified name is available.abstract boolean
hasContent()
Checks whether there is any content to append.void
insert(MutableTreeNode newChild, int childIndex)
RemovesnewChild
from its present parent (if it has a parent), sets the child's parent to this node, and then adds the child to this node's child array at indexchildIndex
.protected boolean
isValidChild(AbstractTag child)
Checks whether the child is valid and can be added.protected void
postInsert(MutableTreeNode newChild, int childIndex)
Hook-method after inserting a child element.protected void
preInsert(MutableTreeNode newChild, int childIndex)
Hook-method before inserting a child element.String
removeAttribute(String name)
Removes the specified attribute.void
setAttribute(String name, String value)
Sets the value of the specified attribute.static String
toEntities(String s)
Turns the string into valid XML.void
toXML(StringBuilder buffer)
Turns the XML tree into its string representation.void
validate()
Validates/fixes the XML tree.-
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
add, breadthFirstEnumeration, children, clone, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, isLeaf, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObject, toString
-
-
-
-
Constructor Detail
-
AbstractTag
public AbstractTag(String tag)
Initializes the tag.- Parameters:
tag
- the name of the tag
-
-
Method Detail
-
getTag
public String getTag()
Returns the tag name.- Returns:
- the tag
-
setAttribute
public void setAttribute(String name, String value)
Sets the value of the specified attribute.- Parameters:
name
- the name of the attributevalue
- the value of the attribute
-
hasAttribute
public boolean hasAttribute(String name)
Checks whether an attribute with the specified name is available.- Parameters:
name
- the name of the attribute to check- Returns:
- true if the attribute exists
-
getAttribute
public String getAttribute(String name)
Returns the value of an attribute.- Parameters:
name
- the name of the attribute to return- Returns:
- the value, can be null if attribute does not exist
-
removeAttribute
public String removeAttribute(String name)
Removes the specified attribute.- Parameters:
name
- the name of the attribute to remove- Returns:
- the previously stored value of the attribute
-
isValidChild
protected boolean isValidChild(AbstractTag child)
Checks whether the child is valid and can be added.
Default implementation returns always true.- Parameters:
child
- the child to check- Returns:
- true if valid
-
preInsert
protected void preInsert(MutableTreeNode newChild, int childIndex)
Hook-method before inserting a child element. Checks whether the child is valid.- Parameters:
newChild
- the child to insertchildIndex
- the index- See Also:
isValidChild(AbstractTag)
-
doInsert
protected void doInsert(MutableTreeNode newChild, int childIndex)
Performs the actual inserting of a child element.- Parameters:
newChild
- the child to insertchildIndex
- the index
-
postInsert
protected void postInsert(MutableTreeNode newChild, int childIndex)
Hook-method after inserting a child element.
Default implementation does nothing.- Parameters:
newChild
- the child to insertchildIndex
- the index
-
insert
public void insert(MutableTreeNode newChild, int childIndex)
RemovesnewChild
from its present parent (if it has a parent), sets the child's parent to this node, and then adds the child to this node's child array at indexchildIndex
.newChild
must not be null and must not be an ancestor of this node.- Specified by:
insert
in interfaceMutableTreeNode
- Overrides:
insert
in classDefaultMutableTreeNode
- Parameters:
newChild
- the MutableTreeNode to insert under this nodechildIndex
- the index in this node's child array where this node is to be inserted- See Also:
isValidChild(AbstractTag)
-
getIndentation
protected String getIndentation()
Returns the indentation string, depending on the elements level in the XML tree.- Returns:
- the indentation string
-
appendStartTag
protected void appendStartTag(StringBuilder buffer)
Appends the start tag to the buffer.- Parameters:
buffer
- the buffer to append the start tag to
-
appendEndTag
protected void appendEndTag(StringBuilder buffer)
Appends the end tag to the buffer.- Parameters:
buffer
- the buffer to append the end tag to
-
hasContent
public abstract boolean hasContent()
Checks whether there is any content to append.- Returns:
- true if content available
-
appendContent
protected abstract void appendContent(StringBuilder buffer)
Appends the content of the element to the buffer.- Parameters:
buffer
- the buffer to append the content to
-
doValidate
protected void doValidate()
Hook method for validating/fixing the XML tree.
Default implementation does nothing
-
validate
public void validate()
Validates/fixes the XML tree.
-
toXML
public void toXML(StringBuilder buffer)
Turns the XML tree into its string representation.- Parameters:
buffer
- the buffer to append the tag to
-
toEntities
public static String toEntities(String s)
Turns the string into valid XML.- Parameters:
s
- the string to convert to valid XML- Returns:
- the XML string
- See Also:
HtmlUtils.toHTML(String)
-
-