Package adams.doc.xml

Class AbstractTag

    • 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 attribute
        value - 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 insert
        childIndex - 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 insert
        childIndex - 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 insert
        childIndex - the index
      • insert

        public void insert​(MutableTreeNode newChild,
                           int childIndex)
        Removes newChild 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 index childIndex. newChild must not be null and must not be an ancestor of this node.
        Specified by:
        insert in interface MutableTreeNode
        Overrides:
        insert in class DefaultMutableTreeNode
        Parameters:
        newChild - the MutableTreeNode to insert under this node
        childIndex - 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)