de.fu_berlin.ties.xml
Class TagContainer

java.lang.Object
  extended by de.fu_berlin.ties.xml.TagContainer
Direct Known Subclasses:
OpenTags, UnprocessedTags

public class TagContainer
extends Object

This class manages tag sequences by keeping track of names and appearances of tags. It is a helper class used for XML adjustment. Instances of this class are not thread-safe.

Version:
$Revision: 1.2 $, $Date: 2004/09/07 10:01:48 $, $Author: siefkes $
Author:
Christian Siefkes

Constructor Summary
TagContainer()
          Creates a new instance.
 
Method Summary
 boolean contains(String tagname)
          Checks whether this instance contains at least one appearance of the specified tag.
 TagConstituent findFirst(String tagname)
          Finds the first appearance of a tag.
 TagConstituent findInSeries(String tagname, int markupSeriesNo, boolean returnFirst)
          Finds the appearance of a tag within a specified markup series.
 void forceRemove(TagConstituent tag)
          Forces the removal of a single appearance of a tag from the container.
protected  Map getTagMap()
          Grants subclasses direct access to the map that is used internally for managing the tags.
 boolean isEmpty()
          Whether this tag container is empty.
 void push(TagConstituent tag)
          Inserts an appearance of a tag into the container.
 void push(TagConstituent tag, boolean appendAtEnd)
          Inserts an appearance of a tag into the container.
 boolean remove(TagConstituent tag)
          Removes a single appearance of a tag from the container.
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TagContainer

public TagContainer()
Creates a new instance.

Method Detail

contains

public boolean contains(String tagname)
Checks whether this instance contains at least one appearance of the specified tag.

Parameters:
tagname - the name of the tag to check
Returns:
true iff the container contains one or more appearances of the specified tag

findFirst

public TagConstituent findFirst(String tagname)
Finds the first appearance of a tag. If the specified tag did never appear within the requested markup series, null is returned instead.

Parameters:
tagname - the name of the tag to check
Returns:
the found apearance of the tag, or null if no matching appearance was found

findInSeries

public TagConstituent findInSeries(String tagname,
                                   int markupSeriesNo,
                                   boolean returnFirst)
Finds the appearance of a tag within a specified markup series. If the specified tag didn't appear within the requested markup series, null is returned instead.

Parameters:
tagname - the name of the tag to check
markupSeriesNo - the markup series number to match
returnFirst - whether to return the first or the last appearance of the tag within the specified series, if several appearances are found
Returns:
the found apearance of the tag, or null if no matching appearance was found

forceRemove

public final void forceRemove(TagConstituent tag)
                       throws RuntimeException
Forces the removal of a single appearance of a tag from the container. Throws a RuntimeException if the appearance could not be removed, i.e. it didn't not exist in the container. Use this method if you are sure that the specified appearance exists.

Parameters:
tag - the tag to remove
Throws:
RuntimeException - stating an "Implementation error" if the specified tag appearance could not be removed

isEmpty

public boolean isEmpty()
Whether this tag container is empty.

Returns:
true iff this container is empty, i.e. doesn't contain any tags

getTagMap

protected Map getTagMap()
Grants subclasses direct access to the map that is used internally for managing the tags. Maps tag names Strings to nested TreeMaps mapping markup series Integers to LinkedLists of TagConstituents.

Returns:
the tag map manages by this class

push

public final void push(TagConstituent tag)
Inserts an appearance of a tag into the container. The name of the tag is used as key; the whole constituent is appended at the end of the list of appearances stored for this tag name.

Parameters:
tag - the tag to insert

push

public void push(TagConstituent tag,
                 boolean appendAtEnd)
          throws UnsupportedOperationException
Inserts an appearance of a tag into the container. The name of the tag is used as key; the whole constituent is inserted in the list of appearances stored for this tag name.

Parameters:
tag - the tag to insert
appendAtEnd - whether to insert the tag at the end or at the begin of appearances within a series
Throws:
UnsupportedOperationException - might be thrown by child classes that don't support prepending if appendAtEnd is false

remove

public boolean remove(TagConstituent tag)
Removes a single appearance of a tag from the container.

Parameters:
tag - the tag to remove
Returns:
true if the specified TagConstituent was removed successfully; false otherwise (the specified constituent wasn't found in the container)

toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class Object
Returns:
a textual representation


Copyright © 2003-2004 Christian Siefkes. All Rights Reserved.