Open SiteSearch 4.1.1
Final

ORG.oclc.util
Class IniFile

java.lang.Object
  |
  +--ORG.oclc.util.IniFile

public class IniFile
extends Object
implements RichProperties

IniFile reads, indexes and provides access to 'windows' type .ini files


Field Summary
 String fileName
           
static String rootDir
           
 
Constructor Summary
IniFile()
          Constructs a new IniFile object.
IniFile(InputStream inputStream)
          Create a new IniFile object
IniFile(Reader reader)
          Create a new IniFile object
IniFile(String fileName)
           
IniFile(String fileName, boolean preserveOrder)
           
 
Method Summary
static void clearIncludeDataCache()
           
protected  void dump(PrintStream ps)
           
 Vector getAllIncludeFileNames()
           
 Vector getAllIncludes()
           
 boolean getBooleanValue(String mainKey, String subKey)
          Given a section name, return the value specified for the input key
 boolean getBooleanValue(String mainKey, String subKey, boolean defaultValue)
          Given a section name, return the boolean value(true/false) specified for the input key
 byte getByteValue(String mainKey, String subKey)
          Given a section name, return the value specified for the input key
 byte getByteValue(String mainKey, String subKey, byte defaultValue)
          Given a section name, return the value specified for the input key
 double getDoubleValue(String mainKey, String subKey)
          Given a section name, return the value specified for the input key
 double getDoubleValue(String mainKey, String subKey, double defaultValue)
          Given a section name, return the value specified for the input key
 float getFloatValue(String mainKey, String subKey)
          Given a section name, return the value specified for the input key
 float getFloatValue(String mainKey, String subKey, float defaultValue)
          Given a section name, return the Float value specified for the input key - use for numeric values
 int getIntValue(String mainKey, String subKey)
          Given a section name, return the value specified for the input key
 int getIntValue(String mainKey, String subKey, int defaultValue)
          Given a section name, return the Integer value specified for the input key - use for numeric values
 long getLongValue(String mainKey, String subKey)
          Given a section name, return the value specified for the input key
 long getLongValue(String mainKey, String subKey, long defaultValue)
          Given a section name, return the value specified for the input key
static String getPath()
          Gets the lookup Path for locating the inifile, by looking at the directory structure and locating the first occurrence of the file.
 IniFileSection getSection(String mainKey)
          Retrieve all the variables in a section
 Enumeration getSectionKeys(String mainKey)
          Retrieve all the variables in a section
 Enumeration getSections()
          Get the section names in the inifile
 short getShortValue(String mainKey, String subKey)
          Given a section name, return the value specified for the input key
 short getShortValue(String mainKey, String subKey, short defaultValue)
          Given a section name, return the value specified for the input key
 String getStringValue(String mainKey, String subKey)
          Given a section name, return the value specified for the input key
 String getStringValue(String mainKey, String subKey, String defaultValue)
          Given a section name, return the value specified for the input key
 String getValue(String mainKey, String subKey)
          Given a section name, return the value specified for the input key
 String getValue(String mainKey, String subKey, String defaultValue)
          Given a section name, return the value specified for the input key.
static void main(String[] argv)
           
static String makeBoolean(String label, boolean flag)
          Create an Inifile string for a boolean.
static String makeBoolean(String label, boolean flag, boolean deflt)
          Create an Inifile string for a boolean.
static String makeInt(String label, int value)
          Create an Inifile string for an integer.
static String makeInt(String label, int value, int deflt)
          Create an Inifile string for an integer.
static String makeString(String label, String name)
          Create an Inifile string for a String.
static String makeString(String label, String name, String deft)
          Create an Inifile string for a String.
static String makeString(String label, String name, String deft, boolean quoteOutput)
          Create an Inifile string for a String.
 String origFilename()
           
protected  String printSections(Hashtable sections)
           
 boolean putBooleanValue(String section, String key, boolean value)
          Given a section name, key and value, add (or update) it in the IniFile object.
 boolean putIntValue(String section, String key, int value)
          Given a section name, key and value, add (or update) it in the IniFile object.
 boolean putValue(String section, String key, String value)
          Given a section name, key and value, add (or update) it in the IniFile object.
static String readEscapedLine(IniData inid)
           
static String readEscapedLine(Reader reader)
          Read a line from Reader and interpret embedded \ escapes.
 void removeKey(String section, String key)
           
 void removeSection(String section)
           
 void renameSection(String oldname, String newname)
          Renames a section in the inifile with the newname.
 IniFile resync()
           
 void setFilename(String filename)
           
static void setPath(String path)
          Sets a lookup Path for locating the inifile, by looking at the directory structure and locating the first occurrence of the file.
static void setRootDir(String dir)
          Set the the directory path for all the inifile reads
 String showOrder()
           
 String toString()
           
 void writeIniFile()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

rootDir

public static String rootDir

fileName

public String fileName
Constructor Detail

IniFile

public IniFile()
Constructs a new IniFile object.

IniFile

public IniFile(String fileName)
        throws IOException

IniFile

public IniFile(String fileName,
               boolean preserveOrder)
        throws IOException

IniFile

public IniFile(InputStream inputStream)
Create a new IniFile object
Parameters:
inputStream - is the InputStream to read

IniFile

public IniFile(Reader reader)
Create a new IniFile object
Parameters:
reader - is the Reader to use
Method Detail

setRootDir

public static void setRootDir(String dir)
Set the the directory path for all the inifile reads
Parameters:
dir - the name of the directory to pre-pend to input filenames

readEscapedLine

public static String readEscapedLine(Reader reader)
                              throws IniInvalidValueException,
                                     IOException
Read a line from Reader and interpret embedded \ escapes. This method reads until a newline or until end of file; a newline at the end of the file is not required. Escapes include:
Parameters:
reader - where to read from
Returns:
interpreted String (without trailing newline) or null on end of file
Throws:
IniInvalidValueException - when an illegal escape is read. Octal escapes begin with \[0-3] and be followed by [0-7]. Unicode escapes begin with \u, followed by 1-4 characters in [0-9A-Fa-f].
IOException - on an I/O error

readEscapedLine

public static String readEscapedLine(IniData inid)
                              throws IniInvalidValueException,
                                     IOException

setPath

public static void setPath(String path)
Sets a lookup Path for locating the inifile, by looking at the directory structure and locating the first occurrence of the file.

getPath

public static String getPath()
Gets the lookup Path for locating the inifile, by looking at the directory structure and locating the first occurrence of the file.
Returns:
path the directory path to look up.

setFilename

public void setFilename(String filename)

origFilename

public String origFilename()

clearIncludeDataCache

public static void clearIncludeDataCache()

showOrder

public String showOrder()

resync

public IniFile resync()

writeIniFile

public void writeIniFile()

getAllIncludeFileNames

public Vector getAllIncludeFileNames()

getAllIncludes

public Vector getAllIncludes()

putIntValue

public boolean putIntValue(String section,
                           String key,
                           int value)
Given a section name, key and value, add (or update) it in the IniFile object.
Parameters:
section - the section name
key - the key to look for
value - the value to store.

putBooleanValue

public boolean putBooleanValue(String section,
                               String key,
                               boolean value)
Given a section name, key and value, add (or update) it in the IniFile object.
Parameters:
section - the section name
key - the key to look for
value - the value to store.

putValue

public boolean putValue(String section,
                        String key,
                        String value)
Given a section name, key and value, add (or update) it in the IniFile object.
Parameters:
section - the section name
key - the key to look for
value - the value to store.

removeSection

public void removeSection(String section)

removeKey

public void removeKey(String section,
                      String key)

renameSection

public void renameSection(String oldname,
                          String newname)
Renames a section in the inifile with the newname.
Parameters:
oldname - the old section name.
newname - the new section name.

getValue

public String getValue(String mainKey,
                       String subKey)
Given a section name, return the value specified for the input key
Specified by:
getValue in interface RichProperties
Parameters:
mainKey - the section name
subKey - the key to look for
Returns:
String the key value or null if the key value does not exist

getValue

public String getValue(String mainKey,
                       String subKey,
                       String defaultValue)
Given a section name, return the value specified for the input key. If the value doesn't exist return the default.
Specified by:
getValue in interface RichProperties
Parameters:
mainKey - the section name
subKey - the key to look for
defaultValue - the default value
Returns:
String the key value

getStringValue

public String getStringValue(String mainKey,
                             String subKey)
                      throws IniMissingSectionException,
                             IniMissingValueException
Given a section name, return the value specified for the input key
Specified by:
getStringValue in interface RichProperties
Parameters:
mainKey - the section name
subKey - the key to look for
Returns:
String the key value or null if the key value does not exist
Throws:
IniMissingSectionException - if the section name is not found
IniMissingValueException - if the subKey value is not found within the section.

getStringValue

public String getStringValue(String mainKey,
                             String subKey,
                             String defaultValue)
Given a section name, return the value specified for the input key
Specified by:
getStringValue in interface RichProperties
Parameters:
mainKey - the section name
subKey - the key to look for
Returns:
String the key value or the defaultValue if the key value does not exist

getIntValue

public int getIntValue(String mainKey,
                       String subKey)
                throws IniMissingSectionException,
                       IniMissingValueException,
                       IniInvalidValueException
Given a section name, return the value specified for the input key
Specified by:
getIntValue in interface RichProperties
Parameters:
mainKey - the section name
subKey - the key to look for
Returns:
int the key value
Throws:
IniMissingSectionException - if the section name is not found
IniMissingValueException - if the subKey value is not found within the section
IniInvalidValueException - if the subKey value is not a valid int

getIntValue

public int getIntValue(String mainKey,
                       String subKey,
                       int defaultValue)
Given a section name, return the Integer value specified for the input key - use for numeric values
Specified by:
getIntValue in interface RichProperties
Parameters:
mainKey - the section name
subKey - the key to look for
defaultValue - the value to return if the key is not found
Returns:
integer the key value

getFloatValue

public float getFloatValue(String mainKey,
                           String subKey)
                    throws IniMissingSectionException,
                           IniMissingValueException,
                           IniInvalidValueException
Given a section name, return the value specified for the input key
Specified by:
getFloatValue in interface RichProperties
Parameters:
mainKey - the section name
subKey - the key to look for
Returns:
int the key value
Throws:
IniMissingSectionException - if the section name is not found
IniMissingValueException - if the subKey value is not found within the section
IniInvalidValueException - if the subKey value is not a valid float

getFloatValue

public float getFloatValue(String mainKey,
                           String subKey,
                           float defaultValue)
Given a section name, return the Float value specified for the input key - use for numeric values
Specified by:
getFloatValue in interface RichProperties
Parameters:
mainKey - the section name
subKey - the key to look for
defaultValue - the value to return if the key is not found
Returns:
float the key value

getBooleanValue

public boolean getBooleanValue(String mainKey,
                               String subKey)
                        throws IniMissingSectionException,
                               IniMissingValueException,
                               IniInvalidValueException
Given a section name, return the value specified for the input key
Specified by:
getBooleanValue in interface RichProperties
Parameters:
mainKey - the section name
subKey - the key to look for
Returns:
int the key value
Throws:
IniMissingSectionException - if the section name is not found
IniMissingValueException - if the subKey value is not found within the section
IniInvalidValueException - if the subKey value is not set to true or false

getBooleanValue

public boolean getBooleanValue(String mainKey,
                               String subKey,
                               boolean defaultValue)
Given a section name, return the boolean value(true/false) specified for the input key
Specified by:
getBooleanValue in interface RichProperties
Parameters:
mainKey - the section name
subKey - the key to look for
defaultValue - the value to return if the key is not found
Returns:
float the key value

getByteValue

public byte getByteValue(String mainKey,
                         String subKey)
                  throws IniMissingSectionException,
                         IniMissingValueException,
                         IniInvalidValueException
Given a section name, return the value specified for the input key
Specified by:
getByteValue in interface RichProperties
Parameters:
mainKey - the section name
subKey - the key to look for
Returns:
byte the key value
Throws:
IniMissingSectionException - if the section name is not found
IniMissingValueException - if the subKey value is not found within the section
IniInvalidValueException - if the subKey value is not a valid byte

getByteValue

public byte getByteValue(String mainKey,
                         String subKey,
                         byte defaultValue)
Given a section name, return the value specified for the input key
Specified by:
getByteValue in interface RichProperties
Parameters:
mainKey - the section name
subKey - the key to look for
Returns:
byte the key value or defaultValue if a key value can't be found

getShortValue

public short getShortValue(String mainKey,
                           String subKey)
                    throws IniMissingSectionException,
                           IniMissingValueException,
                           IniInvalidValueException
Given a section name, return the value specified for the input key
Specified by:
getShortValue in interface RichProperties
Parameters:
mainKey - the section name
subKey - the key to look for
Returns:
byte the key value
Throws:
IniMissingSectionException - if the section name is not found
IniMissingValueException - if the subKey value is not found within the section
IniInvalidValueException - if the subKey value is not a valid short

getShortValue

public short getShortValue(String mainKey,
                           String subKey,
                           short defaultValue)
Given a section name, return the value specified for the input key
Specified by:
getShortValue in interface RichProperties
Parameters:
mainKey - the section name
subKey - the key to look for
Returns:
short the key value or defaultValue if a key value can't be found

getLongValue

public long getLongValue(String mainKey,
                         String subKey)
                  throws IniMissingSectionException,
                         IniMissingValueException,
                         IniInvalidValueException
Given a section name, return the value specified for the input key
Specified by:
getLongValue in interface RichProperties
Parameters:
mainKey - the section name
subKey - the key to look for
Returns:
long the key value
Throws:
IniMissingSectionException - if the section name is not found
IniMissingValueException - if the subKey value is not found within the section
IniInvalidValueException - if the subKey value is not a valid long

getLongValue

public long getLongValue(String mainKey,
                         String subKey,
                         long defaultValue)
Given a section name, return the value specified for the input key
Specified by:
getLongValue in interface RichProperties
Parameters:
mainKey - the section name
subKey - the key to look for
Returns:
long the key value or defaultValue if a key value can't be found

getDoubleValue

public double getDoubleValue(String mainKey,
                             String subKey)
                      throws IniMissingSectionException,
                             IniMissingValueException,
                             IniInvalidValueException
Given a section name, return the value specified for the input key
Specified by:
getDoubleValue in interface RichProperties
Parameters:
mainKey - the section name
subKey - the key to look for
Returns:
double the key value
Throws:
IniMissingSectionException - if the section name is not found
IniMissingValueException - if the subKey value is not found within the section
IniInvalidValueException - if the subKey value is not a valid double

getDoubleValue

public double getDoubleValue(String mainKey,
                             String subKey,
                             double defaultValue)
Given a section name, return the value specified for the input key
Specified by:
getDoubleValue in interface RichProperties
Parameters:
mainKey - the section name
subKey - the key to look for
Returns:
double the key value or defaultValue if a key value can't be found

getSection

public IniFileSection getSection(String mainKey)
Retrieve all the variables in a section
Parameters:
mainKey - the section name
Returns:
IniFileSection the section variables

getSectionKeys

public Enumeration getSectionKeys(String mainKey)
Retrieve all the variables in a section
Specified by:
getSectionKeys in interface RichProperties
Parameters:
mainKey - the section name
Returns:
Enumeration of the section variables

getSections

public Enumeration getSections()
Get the section names in the inifile
Specified by:
getSections in interface RichProperties
Returns:
Enumeration the enumeration of all the section name strings

dump

protected void dump(PrintStream ps)

printSections

protected String printSections(Hashtable sections)

toString

public String toString()
Overrides:
toString in class Object

makeInt

public static String makeInt(String label,
                             int value)
Create an Inifile string for an integer.
Parameters:
label - the variable part of the string
value - the value part of the string
Returns:
String 'label = value\n'.

makeInt

public static String makeInt(String label,
                             int value,
                             int deflt)
Create an Inifile string for an integer.
Parameters:
label - the variable part of the string
value - the value part of the string
deflt - the default value for the variable
Returns:
String 'label = value\n'. If the value == deflt, return empty String

makeBoolean

public static String makeBoolean(String label,
                                 boolean flag)
Create an Inifile string for a boolean.
Parameters:
label - the variable part of the string
value - the value part of the string
Returns:
String 'label = value\n'.

makeBoolean

public static String makeBoolean(String label,
                                 boolean flag,
                                 boolean deflt)
Create an Inifile string for a boolean.
Parameters:
label - the variable part of the string
value - the value part of the string
deflt - the default value for the variable
Returns:
String 'label = value\n'. If the value == deflt, return empty String

makeString

public static String makeString(String label,
                                String name)
Create an Inifile string for a String.
Parameters:
label - the variable part of the string
name - the value part of the string
Returns:
String 'label = value\n'. If the value == null, return empty String

makeString

public static String makeString(String label,
                                String name,
                                String deft)
Create an Inifile string for a String.
Parameters:
label - the variable part of the string
name - the value part of the string
deft - the default value
Returns:
String 'label = value\n'. If the value == null, return empty String

makeString

public static String makeString(String label,
                                String name,
                                String deft,
                                boolean quoteOutput)
Create an Inifile string for a String.
Parameters:
label - the variable part of the string
name - the value part of the string
deft - the default value
quoteOutput - flag indicating to surround output with single quotes
Returns:
String 'label = value\n'. If the value == null, return empty String

main

public static void main(String[] argv)

Open SiteSearch 4.1.1
Final