com
Class IniFile

java.lang.Object
  extended by com.IniFile

public class IniFile
extends java.lang.Object

Used to read and parse an .ti file. Sections are defined by inclosing a word with [] brackets, ex. [section] name and value pairs are formated like name = value, the equal sign separates name/value pairs The .ti file will be looked for in jar files first then the current directory.


Field Summary
 boolean fileFound
          Set to true if file was found.
 
Constructor Summary
IniFile(java.lang.String fileName)
          Constructor for the IniFile Class.
 
Method Summary
 boolean addSection(java.lang.String sec)
          Adds a new section with no key/value pairs.
 void addSection(java.lang.String sec, java.lang.String key, java.lang.String value)
          Adds a key/value pair to an existing section or creates the section if it does not exist.
 boolean addValuePair(java.lang.String sec, java.lang.String key, java.lang.String value)
          Adds a key/value pair to the an existing section, if section does not exist the key/value is NOT added.
 boolean appendValuePair(java.lang.String sec, java.lang.String key, java.lang.String value)
          Appends a key/value to an existing section, if the key/value does not exist then it is created.
 void clearAll()
          Clears all sections and key/value pairs.
 java.lang.String getFileName()
          Returns the filename.
 int getSectionCount()
          Returns the number of sections in file.
 java.lang.Object[] getSectionKeys(java.lang.Object sectionName)
          Returns an array of key names in the section.
 java.lang.Object[] getSectionNames()
          Get an array of all section names.
 boolean getSectionValueAsBoolean(java.lang.Object sectionName, java.lang.Object keyName)
          Gets value as a boolean value.
 int getSectionValueAsInt(java.lang.Object sectionName, java.lang.Object keyName)
          Returns a value of a key/value pairs as an integer
 java.lang.String getSectionValueAsString(java.lang.Object sectionName, java.lang.Object keyName)
          Returns the value of a key/value pair as a string but does not expand any variables.
 java.lang.String getSectionValueAsString(java.lang.Object sectionName, java.lang.Object keyName, boolean flag)
          Returns the value of a key/value pair as a string.
 int getSectionValueCount(java.lang.Object sectionName)
          Returns key/value pair count of a section
 ValuePairMap getSectionValues(java.lang.Object sectionName)
          Return the linked list of a section.
 int getValueCount()
          returns the number of total key/values pairs by adding all sections together.
 boolean keyExists(java.lang.Object sectionName, java.lang.Object key)
          Checks if a key exists in given section.
 void moveDownValuePair(java.lang.String sec, java.lang.String key)
          Moves the key/value pair one place down in the linked list if it can.
 void moveToBottomValuePair(java.lang.String sec, java.lang.String key)
          Moves the key/value pair to bottom of linked list.
 void moveToTopValuePair(java.lang.String sec, java.lang.String key)
          Moves the key/value pair to top of the linked list.
 void moveUpValuePair(java.lang.String sec, java.lang.String key)
          Moves the key/value pair one place up in the linked list if it can.
 boolean open(java.lang.String fileName)
          Open the file and parse contents.
 boolean printSection(java.lang.Object sectionName)
          Prints the name/value pairs for a section.
 boolean removeSection(java.lang.String sec)
          Removes an existing section and all of it's key/value pairs.
 boolean removeValuePair(java.lang.String sec, java.lang.String key)
          Removes an existing key/value pair from an existing section.
 boolean renameSection(java.lang.String from, java.lang.String to)
          Renames a section.
 boolean renameValuePair(java.lang.String sec, java.lang.String from, java.lang.String to)
          Rename key of a ValuePair
 void reread()
          Rereads the file, discarding all changes.
 boolean sectionExists(java.lang.Object sectionName)
          Checks if section exists.
 java.lang.String toString()
          Prints all of the sections.
 boolean writeFile(java.lang.String topSection)
          Writes the complete sections to the filename given when you created class.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

fileFound

public boolean fileFound
Set to true if file was found.

Constructor Detail

IniFile

public IniFile(java.lang.String fileName)
Constructor for the IniFile Class.

Parameters:
fileName - name of .ti type file to create or read.
Method Detail

getFileName

public java.lang.String getFileName()
Returns the filename.

Returns:

reread

public void reread()
Rereads the file, discarding all changes.


clearAll

public void clearAll()
Clears all sections and key/value pairs.


open

public boolean open(java.lang.String fileName)
Open the file and parse contents. Searches jar files for the file first.

Parameters:
fileName - full path to file.
Returns:
false if successful.

addSection

public void addSection(java.lang.String sec,
                       java.lang.String key,
                       java.lang.String value)
Adds a key/value pair to an existing section or creates the section if it does not exist.

Parameters:
sec - section name
key - key within section
value - value of the key

addSection

public boolean addSection(java.lang.String sec)
Adds a new section with no key/value pairs.

Parameters:
sec - section name
Returns:
true if already exists, true if already exists.

renameSection

public boolean renameSection(java.lang.String from,
                             java.lang.String to)
Renames a section.

Parameters:
from - from section name
to - to section name
Returns:
false if successful, true if to name exists

moveToTopValuePair

public void moveToTopValuePair(java.lang.String sec,
                               java.lang.String key)
Moves the key/value pair to top of the linked list.

Parameters:
sec - section name.
key - key name.

moveToBottomValuePair

public void moveToBottomValuePair(java.lang.String sec,
                                  java.lang.String key)
Moves the key/value pair to bottom of linked list.

Parameters:
sec - section name.
key - key name.

moveUpValuePair

public void moveUpValuePair(java.lang.String sec,
                            java.lang.String key)
Moves the key/value pair one place up in the linked list if it can.

Parameters:
sec - section name.
key - key name.

moveDownValuePair

public void moveDownValuePair(java.lang.String sec,
                              java.lang.String key)
Moves the key/value pair one place down in the linked list if it can.

Parameters:
sec - section name.
key - key name.

addValuePair

public boolean addValuePair(java.lang.String sec,
                            java.lang.String key,
                            java.lang.String value)
Adds a key/value pair to the an existing section, if section does not exist the key/value is NOT added.

Parameters:
sec - section name
key - key within section
value - value of the key
Returns:
true if section does not exist, else false;

appendValuePair

public boolean appendValuePair(java.lang.String sec,
                               java.lang.String key,
                               java.lang.String value)
Appends a key/value to an existing section, if the key/value does not exist then it is created.

Parameters:
sec - section name
key - key within section
value - value of the key
Returns:
true if section does not exist, else false.

removeSection

public boolean removeSection(java.lang.String sec)
Removes an existing section and all of it's key/value pairs.

Parameters:
sec - section name to remove
Returns:
true if section does not exist.

removeValuePair

public boolean removeValuePair(java.lang.String sec,
                               java.lang.String key)
Removes an existing key/value pair from an existing section.

Parameters:
sec - section name
key - key within section
Returns:
true if section does not exist or key removal fails.

renameValuePair

public boolean renameValuePair(java.lang.String sec,
                               java.lang.String from,
                               java.lang.String to)
Rename key of a ValuePair

Parameters:
sec - section name
from - from value key
to - to value key
Returns:
true if section does not exist.

getSectionCount

public int getSectionCount()
Returns the number of sections in file.

Returns:
int number of sections in a file.

getValueCount

public int getValueCount()
returns the number of total key/values pairs by adding all sections together.

Returns:
int total key/value pair count

getSectionValueCount

public int getSectionValueCount(java.lang.Object sectionName)
Returns key/value pair count of a section

Parameters:
sectionName - section name
Returns:
int count of key/value pairs in a section.

getSectionValueAsString

public java.lang.String getSectionValueAsString(java.lang.Object sectionName,
                                                java.lang.Object keyName)
Returns the value of a key/value pair as a string but does not expand any variables.

Parameters:
sectionName - section name
keyName - key name within section
Returns:
String value

getSectionValueAsString

public java.lang.String getSectionValueAsString(java.lang.Object sectionName,
                                                java.lang.Object keyName,
                                                boolean flag)
Returns the value of a key/value pair as a string.

Parameters:
sectionName - section name
keyName - key name within section
flag - whether to expand variables or not.
Returns:
String value

getSectionValueAsInt

public int getSectionValueAsInt(java.lang.Object sectionName,
                                java.lang.Object keyName)
Returns a value of a key/value pairs as an integer

Parameters:
sectionName - section name
keyName - key name within section
Returns:
int value

getSectionValueAsBoolean

public boolean getSectionValueAsBoolean(java.lang.Object sectionName,
                                        java.lang.Object keyName)
Gets value as a boolean value.

Parameters:
sectionName -
keyName -
Returns:
false if section or key/value does not exist.

getSectionValues

public ValuePairMap getSectionValues(java.lang.Object sectionName)
Return the linked list of a section.

Parameters:
sectionName -
Returns:

getSectionNames

public java.lang.Object[] getSectionNames()
Get an array of all section names.

Returns:
an array of section names as an array of Objects.

getSectionKeys

public java.lang.Object[] getSectionKeys(java.lang.Object sectionName)
Returns an array of key names in the section.

Parameters:
sectionName -
Returns:

sectionExists

public boolean sectionExists(java.lang.Object sectionName)
Checks if section exists.

Parameters:
sectionName -
Returns:
true if section exists.

keyExists

public boolean keyExists(java.lang.Object sectionName,
                         java.lang.Object key)
Checks if a key exists in given section.

Parameters:
sectionName -
key -
Returns:
true if key exists.

writeFile

public boolean writeFile(java.lang.String topSection)
Writes the complete sections to the filename given when you created class.

Parameters:
topSection - - string comment to place at top of file.
Returns:
true if save failed.

printSection

public boolean printSection(java.lang.Object sectionName)
Prints the name/value pairs for a section.

Parameters:
sectionName -
Returns:
true if section does not exist.

toString

public java.lang.String toString()
Prints all of the sections.

Overrides:
toString in class java.lang.Object