org.icenigrid.gridsam.core.util
Class XMLConfigReader

java.lang.Object
  extended by java.util.ResourceBundle
      extended by org.icenigrid.gridsam.core.util.XMLConfigReader

public class XMLConfigReader
extends java.util.ResourceBundle

Reads structured resource text data from an XML file and store it on a hashtable.

The hashtable keys are taken from the value of the first attribute of the <item> elements.
The hash table values are hashtables containing the sub-items names as keys and the sub-items data as value.

Implementation notes

You instantiate the XMLConfigReader class in a program to read data from a XML file. Once the class is instantiated, it reads all the data in a XML file and loads into a DOM tree. Then it populates a hashtable so the getString method can be called to find text information based on a key and subkey.

Copyright (c) 2004-2005 Tecnick.com S.r.l (www.tecnick.com) Via Ugo Foscolo n.19 - 09045 Quartu Sant'Elena (CA) - ITALY www.tecnick.com - info@tecnick.com
Project homepage: http://xmlconfigreader.sourceforge.net
License: http://www.gnu.org/copyleft/lesser.html LGPL

Version:
1.0.003
Author:
Nicola Asuni [www.tecnick.com].

Field Summary
protected  java.util.Hashtable hashcontents
          The hastable that will contain data loaded from XML.
protected  int numberOfItems
          Number of items (<item> elements).
protected  java.util.Vector vectOfItems
          Vector to store items keys (<item>).
 
Fields inherited from class java.util.ResourceBundle
parent
 
Constructor Summary
XMLConfigReader(java.lang.String xmlfile)
          TMX to Hashtable conversion.
 
Method Summary
 double getDouble(java.lang.String key, java.lang.String subkey, double def)
          Call getString method to get a double value.
 int getInt(java.lang.String key, java.lang.String subkey, int def)
          Call getString method to get an int value.
 java.lang.String getKey(java.lang.String subkey, java.lang.String value)
          Get the key for the selected subkey and value.
 java.util.Enumeration getKeys()
          Define getKeys method.
 int getNumberOfItems()
          Returns the number of items.
 java.lang.String getString(java.lang.String key, java.lang.String subkey)
          Overloading of getString method with additional subkey.
 java.lang.String getString(java.lang.String key, java.lang.String subkey, java.lang.String def)
          Overloading of getString method with additional subkey and default parameter.
 java.lang.Object handleGetObject(java.lang.String key)
          handleGetObject implementation.
 org.w3c.dom.Document parseXmlFile(java.lang.String filename, boolean validating)
          Parses an XML file and returns a DOM document.
 
Methods inherited from class java.util.ResourceBundle
getBundle, getBundle, getBundle, getLocale, getObject, getString, getStringArray, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hashcontents

protected java.util.Hashtable hashcontents
The hastable that will contain data loaded from XML.


numberOfItems

protected int numberOfItems
Number of items (<item> elements).


vectOfItems

protected java.util.Vector vectOfItems
Vector to store items keys (<item>).

Constructor Detail

XMLConfigReader

public XMLConfigReader(java.lang.String xmlfile)
TMX to Hashtable conversion. Reads XML and store data in HashTable.

Parameters:
xmlfile - the XML file to read, supports also URI resources or JAR resources
Method Detail

parseXmlFile

public org.w3c.dom.Document parseXmlFile(java.lang.String filename,
                                         boolean validating)
Parses an XML file and returns a DOM document.

Parameters:
filename - the name of XML file
validating - If true, the contents is validated against the DTD specified in the file.
Returns:
the parsed document

handleGetObject

public final java.lang.Object handleGetObject(java.lang.String key)
                                       throws java.util.MissingResourceException
handleGetObject implementation.

Specified by:
handleGetObject in class java.util.ResourceBundle
Parameters:
key - the resource key
Returns:
the content associated to the specified key
Throws:
java.util.MissingResourceException

getNumberOfItems

public int getNumberOfItems()
Returns the number of items.

Returns:
number of Items

getKeys

public java.util.Enumeration getKeys()
Define getKeys method.

Specified by:
getKeys in class java.util.ResourceBundle
Returns:
item elements

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String subkey,
                                  java.lang.String def)
Overloading of getString method with additional subkey and default parameter.

Parameters:
key - name of key
subkey - name of sub key
def - default value
Returns:
parameter value or default

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String subkey)
Overloading of getString method with additional subkey.

Parameters:
key - name of key
subkey - name of sub key
Returns:
parameter value or void string
See Also:
getString(String, String, String)

getInt

public int getInt(java.lang.String key,
                  java.lang.String subkey,
                  int def)
Call getString method to get an int value.

Parameters:
key - name of key
subkey - name of sub key
def - default value
Returns:
parameter value or default

getDouble

public double getDouble(java.lang.String key,
                        java.lang.String subkey,
                        double def)
Call getString method to get a double value.

Parameters:
key - name of key
subkey - name of sub key
def - default value
Returns:
parameter value or default

getKey

public java.lang.String getKey(java.lang.String subkey,
                               java.lang.String value)
Get the key for the selected subkey and value.

Parameters:
subkey - String the subkey
value - String the value to search
Returns:
String the main key or null if not found


Copyright © 2008. All Rights Reserved.