com.autonomy.config
Class ConfigFile

java.lang.Object
  |
  +--com.autonomy.config.ConfigEntry
        |
        +--com.autonomy.config.ConfigSection
              |
              +--com.autonomy.config.ConfigFile

public class ConfigFile
extends ConfigSection

Solid implementation of the ConfigEntry. This is used to read standard Autonomy configuration files. Thus the following assumptions are made about the structure:

The ConfigFile object contains only ConfigSections and those ConfigSections contain only ConfigKeys. This assumption forms the basis of the read / set methods detailed below

See Also:
ConfigSection, ConfigKey

Field Summary
 
Fields inherited from class com.autonomy.config.ConfigEntry
BEGIN_CLOSE, BEGIN_OPEN, COMMENT_END, COMMENT_START, CRLF, END_CLOSE, END_OPEN, IS_FILE, IS_KEY, IS_SECTION, IS_UNKNOWN, KEY_VALUE_SEPARATOR, m_nType, USE_END_TAG
 
Constructor Summary
ConfigFile()
          Constructor.
ConfigFile(com.autonomy.config.ConfigSection csSection)
           
ConfigFile(java.lang.String sFilePath)
          Constructor.
 
Method Summary
 void display()
          Writes the whole file to standard out
 java.lang.String getFilename()
          Get the filename that this ConfigFile was read from
 void parse(java.lang.String sConfig)
          This method parses a String containing Autonomy configuration settings into the ConfigFile object
 void read(java.lang.String sFilename)
          Read in a config file.
 boolean readBoolean(java.lang.String sSection, java.lang.String sKey)
          Get a key from a named section as a boolean
 boolean readBoolean(java.lang.String sSection, java.lang.String sKey, boolean bDefault)
          Get a key from a named section as a boolean
 double readDouble(java.lang.String sSection, java.lang.String sKey)
          Get a key from a named section as a double
 double readDouble(java.lang.String sSection, java.lang.String sKey, double dDefault)
          Get a key from a named section as a double
 int readInt(java.lang.String sSection, java.lang.String sKey)
          Get a key from a named section as an int
 int readInt(java.lang.String sSection, java.lang.String sKey, int nDefault)
          Get a key from a named section as an int
 long readLong(java.lang.String sSection, java.lang.String sKey)
          Get a key from a named section as a long
 long readLong(java.lang.String sSection, java.lang.String sKey, long lnDefault)
          Get a key from a named section as a long
 java.lang.String readString(java.lang.String sSection, java.lang.String sKey)
          Get a key from a named section
 java.lang.String readString(java.lang.String sSection, java.lang.String sKey, java.lang.String sDefault)
          Get a key from a named section
 void setString(java.lang.String sSection, java.lang.String sKey, java.lang.String sValue)
          Set a key in a specified section, overwriting any existing entries there
 java.lang.String toString()
          Creates a string representing the whole file as it would be stored on the file system
 void write()
          Writes the file out to the same location it was read from
 int writeTo(java.lang.String sConfigFileName, boolean dosFormat)
          Write the config out to a file on disk
 
Methods inherited from class com.autonomy.config.ConfigSection
delete, getKeyNames, getKeyNamesVector, getName, getOriginalName, getSectionNames, getSectionNamesVector, readBoolean, readDouble, readInt, readKey, readLong, readSection, readSectionSafely, setKey, setSection, setString, toHashtable
 
Methods inherited from class com.autonomy.config.ConfigEntry
getComments, getOriginalName, getValue, setComments, stringIsValidName
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConfigFile

public ConfigFile()
Constructor. Creates an empty ConfigFile


ConfigFile

public ConfigFile(com.autonomy.config.ConfigSection csSection)

ConfigFile

public ConfigFile(java.lang.String sFilePath)
           throws java.io.FileNotFoundException
Constructor. Loads an existing config file

Parameters:
sFilePath - Full path to configuration file
Method Detail

read

public void read(java.lang.String sFilename)
          throws java.io.FileNotFoundException
Read in a config file.

Parameters:
sFilename - Fully Qualified Path of the config file to read
java.io.FileNotFoundException

parse

public void parse(java.lang.String sConfig)
This method parses a String containing Autonomy configuration settings into the ConfigFile object

Parameters:
sConfig - Buffer containing configuration settings

writeTo

public int writeTo(java.lang.String sConfigFileName,
                   boolean dosFormat)
Write the config out to a file on disk

Parameters:
sConfigFileName - Name of the config file to create
dosFormat - whether to end each line with \n\r or just \n
Returns:
int An Integer to indicate success or failure. 0 is Success, -1 is Failure

write

public void write()
Writes the file out to the same location it was read from


toString

public java.lang.String toString()
Creates a string representing the whole file as it would be stored on the file system

Overrides:
toString in class ConfigSection
Returns:
This section, as a String

display

public void display()
Writes the whole file to standard out

Overrides:
display in class ConfigSection
Returns:
This section, as a String

readString

public java.lang.String readString(java.lang.String sSection,
                                   java.lang.String sKey,
                                   java.lang.String sDefault)
Get a key from a named section

Parameters:
sSection - Name of section to read the key from
sKey - Name of the key to read
sDefault - Value to return if the section or key is not found
Returns:
Value of the specified key, from the specified section

readString

public java.lang.String readString(java.lang.String sSection,
                                   java.lang.String sKey)
Get a key from a named section

Overrides:
readString in class ConfigSection
Parameters:
sSection - Name of section to read the key from
sKey - Name of the key to read
Returns:
Value of the specified key, from the specified section or "" if it cannot be found

readInt

public int readInt(java.lang.String sSection,
                   java.lang.String sKey,
                   int nDefault)
Get a key from a named section as an int

Parameters:
sSection - Name of section to read the key from
sKey - Name of the key to read
nDefault - Value to return if the section or key is not found or cannot be converted to an int
Returns:
Value of the specified key, from the specified section

readInt

public int readInt(java.lang.String sSection,
                   java.lang.String sKey)
Get a key from a named section as an int

Parameters:
sSection - Name of section to read the key from
sKey - Name of the key to read
Returns:
Value of the specified key, from the specified section, or 0 if it cannot be found or converted to an int

readLong

public long readLong(java.lang.String sSection,
                     java.lang.String sKey,
                     long lnDefault)
Get a key from a named section as a long

Parameters:
sSection - Name of section to read the key from
sKey - Name of the key to read
lnDefault - Value to return if the section or key is not found or cannot be converted to an int
Returns:
Value of the specified key, from the specified section

readLong

public long readLong(java.lang.String sSection,
                     java.lang.String sKey)
Get a key from a named section as a long

Parameters:
sSection - Name of section to read the key from
sKey - Name of the key to read
Returns:
Value of the specified key, from the specified section, or 0 if it cannot be found or converted to a long

readBoolean

public boolean readBoolean(java.lang.String sSection,
                           java.lang.String sKey,
                           boolean bDefault)
Get a key from a named section as a boolean

Parameters:
sSection - Name of section to read the key from
sKey - Name of the key to read
bDefault - Value to return if the section or key is not found or cannot be converted to an int
Returns:
Value of the specified key, from the specified section

readBoolean

public boolean readBoolean(java.lang.String sSection,
                           java.lang.String sKey)
Get a key from a named section as a boolean

Parameters:
sSection - Name of section to read the key from
sKey - Name of the key to read
Returns:
Value of the specified key, from the specified section, or false if it cannot be found or converted to a boolean

readDouble

public double readDouble(java.lang.String sSection,
                         java.lang.String sKey,
                         double dDefault)
Get a key from a named section as a double

Parameters:
sSection - Name of section to read the key from
sKey - Name of the key to read
dDefault - Value to return if the section or key is not found or cannot be converted to a double
Returns:
Value of the specified key, from the specified section

readDouble

public double readDouble(java.lang.String sSection,
                         java.lang.String sKey)
Get a key from a named section as a double

Parameters:
sSection - Name of section to read the key from
sKey - Name of the key to read
Returns:
Value of the specified key, from the specified section, or 0 if it cannot be found or converted to a double

setString

public void setString(java.lang.String sSection,
                      java.lang.String sKey,
                      java.lang.String sValue)
Set a key in a specified section, overwriting any existing entries there

Parameters:
sSection - Name of section to set the key in
sKey - Name of the key to set

getFilename

public java.lang.String getFilename()
Get the filename that this ConfigFile was read from

Returns:
The filename, or null if it has not yet been set