rails.util
Class Tag

java.lang.Object
  extended by rails.util.Tag

public class Tag
extends java.lang.Object

Each object of this class both contains and represents a DOM Element object. Its purpose it to hide the XML parsing details from the application program. The methods of this class intend to replace the corresponding methods in XmlUtils.

Author:
Erik Vos

Field Summary
protected static org.apache.log4j.Logger log
           
 
Constructor Summary
Tag(org.w3c.dom.Element element)
           
Tag(org.w3c.dom.Element element, java.util.Map<java.lang.String,java.lang.String> gameOptions)
           
 
Method Summary
static Tag findTopTagInFile(java.lang.String filename, java.util.List<java.lang.String> directories, java.lang.String tagName)
          Opens and parses an xml file.
 boolean getAttributeAsBoolean(java.lang.String name)
           
 boolean getAttributeAsBoolean(java.lang.String name, boolean defaultValue)
           
 float getAttributeAsFloat(java.lang.String name)
           
 float getAttributeAsFloat(java.lang.String name, float defaultValue)
           
 int getAttributeAsInteger(java.lang.String name)
           
 int getAttributeAsInteger(java.lang.String name, int defaultValue)
           
 int[] getAttributeAsIntegerArray(java.lang.String name)
           
 int[] getAttributeAsIntegerArray(java.lang.String name, int[] defaultArray)
           
 java.lang.String getAttributeAsString(java.lang.String name)
           
 java.lang.String getAttributeAsString(java.lang.String name, java.lang.String defaultValue)
           
 java.util.Map<java.lang.String,java.lang.String> getAttributes()
           
 Tag getChild(java.lang.String tagName)
          Return the (first) child Element with a given name from an Element.
 java.util.Map<java.lang.String,java.util.List<Tag>> getChildren()
           
 java.util.List<Tag> getChildren(java.lang.String tagName)
          Return all child Elements with a given name of an Element.
 org.w3c.dom.Element getElement()
           
 java.util.Map<java.lang.String,java.lang.String> getGameOptions()
           
 java.lang.String getText()
           
 boolean hasAttribute(java.lang.String name)
           
 boolean hasChild(java.lang.String tagName)
           
 void setGameOptions(java.util.Map<java.lang.String,java.lang.String> gameOptions)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.apache.log4j.Logger log
Constructor Detail

Tag

public Tag(org.w3c.dom.Element element)

Tag

public Tag(org.w3c.dom.Element element,
           java.util.Map<java.lang.String,java.lang.String> gameOptions)
Method Detail

setGameOptions

public void setGameOptions(java.util.Map<java.lang.String,java.lang.String> gameOptions)

getGameOptions

public java.util.Map<java.lang.String,java.lang.String> getGameOptions()

getChildren

public java.util.Map<java.lang.String,java.util.List<Tag>> getChildren()
                                                                throws ConfigurationException
Throws:
ConfigurationException

getChildren

public java.util.List<Tag> getChildren(java.lang.String tagName)
                                throws ConfigurationException
Return all child Elements with a given name of an Element.

Parameters:
element -
tagName -
Returns:
Throws:
ConfigurationException

getChild

public Tag getChild(java.lang.String tagName)
             throws ConfigurationException
Return the (first) child Element with a given name from an Element.

Parameters:
element -
tagName -
Returns:
Throws:
ConfigurationException

hasChild

public boolean hasChild(java.lang.String tagName)
                 throws ConfigurationException
Throws:
ConfigurationException

getText

public java.lang.String getText()
                         throws ConfigurationException
Throws:
ConfigurationException

getAttributes

public java.util.Map<java.lang.String,java.lang.String> getAttributes()
                                                               throws ConfigurationException
Throws:
ConfigurationException

getAttributeAsString

public java.lang.String getAttributeAsString(java.lang.String name,
                                             java.lang.String defaultValue)
                                      throws ConfigurationException
Throws:
ConfigurationException

getAttributeAsString

public java.lang.String getAttributeAsString(java.lang.String name)
                                      throws ConfigurationException
Throws:
ConfigurationException

getAttributeAsInteger

public int getAttributeAsInteger(java.lang.String name,
                                 int defaultValue)
                          throws ConfigurationException
Throws:
ConfigurationException

getAttributeAsFloat

public float getAttributeAsFloat(java.lang.String name)
                          throws ConfigurationException
Throws:
ConfigurationException

getAttributeAsFloat

public float getAttributeAsFloat(java.lang.String name,
                                 float defaultValue)
                          throws ConfigurationException
Throws:
ConfigurationException

getAttributeAsInteger

public int getAttributeAsInteger(java.lang.String name)
                          throws ConfigurationException
Throws:
ConfigurationException

getAttributeAsIntegerArray

public int[] getAttributeAsIntegerArray(java.lang.String name,
                                        int[] defaultArray)
                                 throws ConfigurationException
Throws:
ConfigurationException

getAttributeAsIntegerArray

public int[] getAttributeAsIntegerArray(java.lang.String name)
                                 throws ConfigurationException
Throws:
ConfigurationException

getAttributeAsBoolean

public boolean getAttributeAsBoolean(java.lang.String name,
                                     boolean defaultValue)
                              throws ConfigurationException
Throws:
ConfigurationException

getAttributeAsBoolean

public boolean getAttributeAsBoolean(java.lang.String name)
                              throws ConfigurationException
Throws:
ConfigurationException

hasAttribute

public boolean hasAttribute(java.lang.String name)
                     throws ConfigurationException
Throws:
ConfigurationException

findTopTagInFile

public static Tag findTopTagInFile(java.lang.String filename,
                                   java.util.List<java.lang.String> directories,
                                   java.lang.String tagName)
                            throws ConfigurationException
Opens and parses an xml file. Searches the root level of the file for an element with the supplied name.

Parameters:
fileName - the name of the file to open
tagName - the name of the top-level tag to find
Returns:
the named element in the named file
Throws:
ConfigurationException - if there is any problem opening and parsing the file, or if the file does not contain a top level element with the given name.

getElement

public org.w3c.dom.Element getElement()