org.ChinaVO.FITSManager
Class XMLRWer

java.lang.Object
  extended by org.ChinaVO.FITSManager.XMLRWer
Direct Known Subclasses:
GUILang, SystemSetting

public class XMLRWer
extends java.lang.Object

This class is used for dealing the special xml format files:
<config>
<node1 name="">
<node2 name=""/>
</node1>
</config>
which node/element has only an attribute and the name of the attribute is unique, such as "name","value"

You can read a node/element's attribute value, by get***value(path, defaultValue),example:
getStringValue("config/node1", "");
The path = "config" + "/" + "node1".

Remark, after you new an object of this class, you should remember calling the obj.loadXML() to start reading the xml file. Otherwise, you won't get anything.
And before your application terminated, you should always remember calling the obj.saveXML() to save back the information to your config.xml. If you need not to save the new information, you can ignore this step. example:
//"config" is the root node of the XML tree.
//"value" is the only attribute name for each node/element.
XMLRWer rw = new XMLRWer("value", "config");
rw.loadXML();//start reading the XML file.
rw.getBooleanValue("config/node1", true);//read some value
rw.setSetting("config/node3", "3");//change the node's value, if the node does not exists, this operation will add a new node/element to the XML tree.
rw.saveXML();//save back the XML tree.


Constructor Summary
XMLRWer(java.lang.String strValueAttrStr, java.lang.String strRootName)
          Construct a XMLRWer object.
 
Method Summary
 boolean getBooleanValue(java.lang.String path, boolean defaultValue)
          get a Boolean value, if the path does not exists, return the defaultValue.
 double getDoubleValue(java.lang.String path, double defaultValue)
          get a Double value, if the path does not exists, return the defaultValue.
 int getIntValue(java.lang.String path, int defaultValue)
          get a Integer value, if the path does not exists, return the defaultValue.
 java.lang.String getRootName()
          get the name of the XML file's root.
 java.lang.String getStringValue(java.lang.String path, java.lang.String defaultValue)
          get a String value, if the path does not exists, return the defaultValue.
 java.lang.String getValueAttrStr()
          get the unique attribute's name
 java.lang.String getXMLPath()
          get the XML file's path
 void loadXML()
          Load the XML file.
 void saveXML()
          Save back the xml tree to the xml file.
 void setSetting(java.lang.String path, java.lang.String value)
          change the attribute's value of a node/element which the path specify.
 void setXMLPath(java.lang.String strXMLPath)
          Change the XML file's path.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLRWer

public XMLRWer(java.lang.String strValueAttrStr,
               java.lang.String strRootName)
Construct a XMLRWer object.

Parameters:
strValueAttrStr - name of the unique attribute.
strRootName - name of the XML tree's root.
Method Detail

setXMLPath

public void setXMLPath(java.lang.String strXMLPath)
Change the XML file's path. It will not take any usage after you loadXML().

Parameters:
strXMLPath - new path of the XML file.

getXMLPath

public java.lang.String getXMLPath()
get the XML file's path

Returns:
the XML file's path.

getValueAttrStr

public java.lang.String getValueAttrStr()
get the unique attribute's name

Returns:
name of the unique attribute.

getRootName

public java.lang.String getRootName()
get the name of the XML file's root.

Returns:
name of the XML file's root.

getIntValue

public int getIntValue(java.lang.String path,
                       int defaultValue)
get a Integer value, if the path does not exists, return the defaultValue. And a new node with this path will be added in the XML tree.

Parameters:
path - like "config/system"
defaultValue - an Integer value, like 1,2,3¡­¡­
Returns:
an Integer value

getBooleanValue

public boolean getBooleanValue(java.lang.String path,
                               boolean defaultValue)
get a Boolean value, if the path does not exists, return the defaultValue. And a new node with this path will be added in the XML tree.

Parameters:
path - like "config/system"
defaultValue - an Boolean value, like true,false
Returns:
an Boolean value

getDoubleValue

public double getDoubleValue(java.lang.String path,
                             double defaultValue)
get a Double value, if the path does not exists, return the defaultValue. And a new node with this path will be added in the XML tree.

Parameters:
path - like "config/system"
defaultValue - an Double value, like 1.0,2.2¡­¡­
Returns:
an Double value

getStringValue

public java.lang.String getStringValue(java.lang.String path,
                                       java.lang.String defaultValue)
get a String value, if the path does not exists, return the defaultValue. And a new node with this path will be added in the XML tree.

Parameters:
path - like "config/system"
defaultValue - an String value, like "","string"¡­¡­
Returns:
an String value

setSetting

public void setSetting(java.lang.String path,
                       java.lang.String value)
change the attribute's value of a node/element which the path specify. If the node/elements does not exists, a new node with this path will be added in the XML tree.

Parameters:
path - like "config/system"
value - new value, should be a String

loadXML

public void loadXML()
Load the XML file. You have to call this function yourself to start reading XML file.


saveXML

public void saveXML()
Save back the xml tree to the xml file. If you want to save the change in the xml tree, you have to call this function yourself.