atg.search.query.formhandlers
Class TagBuilder

java.lang.Object
  extended by atg.search.query.formhandlers.TagBuilder
Direct Known Subclasses:
XMLPreProcessorVisitor, XMLTagBuilderVisitor

public class TagBuilder
extends java.lang.Object

This class is a base class for things that iterate the HashMapMap objects


Field Summary
protected static java.lang.String ATTRIBUTES_KEY
           
protected static java.lang.String BODY_KEY
           
static java.lang.String CLASS_VERSION
           
protected static java.lang.String NESTED_ATTR
           
protected static java.lang.String OPTIONS_KEY
           
protected static java.lang.String TAGNAME_KEY
           
 
Constructor Summary
TagBuilder()
          Create a builder with an initially empty buffer and a zero indentation value.
TagBuilder(java.lang.StringBuffer pBuffer)
          Create a builder which will use an existing string buffer
TagBuilder(java.lang.StringBuffer pBuffer, int pInitialIndent, java.lang.String pNestedTagRegex)
          Create a builder which will use an existing string buffer and which also uses the specified indentation level
 
Method Summary
protected  void addIndent()
          Add current level of indentation (whitespace) to output buffer
 java.lang.StringBuffer escape(java.lang.Object pObject)
          Append escaped string to buffer
 java.lang.StringBuffer escape(java.lang.String pString, java.lang.StringBuffer pBuffer)
          Append escaped string to buffer
protected  java.lang.StringBuffer formatAttributes(java.util.Map pAttributes)
          Format all values of map as XML tag attributes, return result in string buffer.
 int getIndent()
           
protected static java.util.Map getMapValueOrNull(java.util.Map pMap, java.lang.Object pKey)
          Return a Map value in the map for the specified key or null.
protected  java.util.regex.Pattern getNestedTagPattern()
          Return a pattern that matches the 'tagname' of nested tags.
protected  HashMapMap getParentTag(HashMapMap pTag)
          Look up the HashMapMap hierarchy for the parent tag
 java.lang.StringBuffer getStringBuffer()
          Get the string buffer into which all the XML is written
protected static java.lang.String getStringValueOrNull(java.util.Map pMap, java.lang.Object pKey)
          Return a String value in the map for the specified key or null.
protected  java.lang.String getTagName(java.util.Map pMap)
           
protected  boolean hasValue(java.util.Map pMap, java.lang.String pKey)
          Return true if map contains a value associated with the specified key.
 int indent()
          Indent one level
protected  boolean isNested(java.util.Map pMap)
          Identify tags that can contain nested tags.
 void setIndent(int pIndent)
          Set the indentation level
 int unindent()
          unindent one level
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION

TAGNAME_KEY

protected static final java.lang.String TAGNAME_KEY
See Also:
Constant Field Values

ATTRIBUTES_KEY

protected static final java.lang.String ATTRIBUTES_KEY
See Also:
Constant Field Values

OPTIONS_KEY

protected static final java.lang.String OPTIONS_KEY
See Also:
Constant Field Values

NESTED_ATTR

protected static final java.lang.String NESTED_ATTR
See Also:
Constant Field Values

BODY_KEY

protected static final java.lang.String BODY_KEY
See Also:
Constant Field Values
Constructor Detail

TagBuilder

public TagBuilder()
Create a builder with an initially empty buffer and a zero indentation value.


TagBuilder

public TagBuilder(java.lang.StringBuffer pBuffer)
Create a builder which will use an existing string buffer

Parameters:
pBuffer - string buffer to use

TagBuilder

public TagBuilder(java.lang.StringBuffer pBuffer,
                  int pInitialIndent,
                  java.lang.String pNestedTagRegex)
Create a builder which will use an existing string buffer and which also uses the specified indentation level

Parameters:
pBuffer - string buffer to use
pInitialIndent - initial indentation level
pNestedTagRegex - the regular expression matching tags which can contain other tags or null for default
Throws:
PatternSyntaxException - If the expression's syntax is invalid
Method Detail

setIndent

public void setIndent(int pIndent)
Set the indentation level

Parameters:
pIndent - the indentation level

getIndent

public int getIndent()
Returns:
the current indentation level

indent

public int indent()
Indent one level


unindent

public int unindent()
unindent one level


getStringBuffer

public java.lang.StringBuffer getStringBuffer()
Get the string buffer into which all the XML is written

Returns:
the generated XML

getTagName

protected java.lang.String getTagName(java.util.Map pMap)
Returns:
the name of the tag specified in the map or null if not present

getParentTag

protected HashMapMap getParentTag(HashMapMap pTag)
Look up the HashMapMap hierarchy for the parent tag

Parameters:
pTag - the current tag

isNested

protected boolean isNested(java.util.Map pMap)
Identify tags that can contain nested tags. If map contains a "nested" key, returns true if that value is set to "true". Otherwise, returns true if tagname (via getTagName()) equals the nested tag patter.

Parameters:
pTagname - name of tag
pMap - map of tag values
Returns:
true if this tag matches the nested tag regex

getNestedTagPattern

protected java.util.regex.Pattern getNestedTagPattern()
Return a pattern that matches the 'tagname' of nested tags.

Returns:
the nested tag name pattern

getStringValueOrNull

protected static java.lang.String getStringValueOrNull(java.util.Map pMap,
                                                       java.lang.Object pKey)
Return a String value in the map for the specified key or null. If a value exists for the key but it is not of type string, return null.

Parameters:
pMap - the map
pKey - the key
Returns:
a string value or null

getMapValueOrNull

protected static java.util.Map getMapValueOrNull(java.util.Map pMap,
                                                 java.lang.Object pKey)
Return a Map value in the map for the specified key or null. If a value exists for the key but it is not of type Map return null.

Parameters:
pMap - the map
pKey - the key
Returns:
a Map value or null

addIndent

protected void addIndent()
Add current level of indentation (whitespace) to output buffer


escape

public java.lang.StringBuffer escape(java.lang.Object pObject)
Append escaped string to buffer

Parameters:
pObject - invoke toString() on object, escape result

hasValue

protected boolean hasValue(java.util.Map pMap,
                           java.lang.String pKey)
Return true if map contains a value associated with the specified key. For map and string values, the value must be non-empty (size or length > 0).

Parameters:
pKey - the key to test
pMap - the map in which to locate the key's value
Returns:
true if an associated value exists

formatAttributes

protected java.lang.StringBuffer formatAttributes(java.util.Map pAttributes)
Format all values of map as XML tag attributes, return result in string buffer.

Parameters:
pAttributes - the attribute map
Returns:
the formatted attributes or null if no attributes

escape

public java.lang.StringBuffer escape(java.lang.String pString,
                                     java.lang.StringBuffer pBuffer)
Append escaped string to buffer

Parameters:
pString - the string with characters to escape