archivo3000
Class INIFile

java.lang.Object
  extended by archivo3000.INIFile

public final class INIFile
extends java.lang.Object

INIFile class provides methods for manipulating (Read/Write) windows ini files.

Since:
1.0

Constructor Summary
INIFile(java.lang.String pstrPathAndName)
          Create a iniFile object from the file named in the parameter.
 
Method Summary
 void addSection(java.lang.String pstrSection, java.lang.String pstrComments)
          Sets the comments associated with a section.
 java.lang.String[] getAllSectionNames()
          Returns a string array containing names of all sections in INI file.
 java.lang.Boolean getBooleanProperty(java.lang.String pstrSection, java.lang.String pstrProp)
          Returns the specified boolean property from the specified section.
 java.util.Date getDateProperty(java.lang.String pstrSection, java.lang.String pstrProp)
          Returns the specified date property from the specified section.
 java.lang.Double getDoubleProperty(java.lang.String pstrSection, java.lang.String pstrProp)
          Returns the specified double property from the specified section.
 java.lang.String getFileName()
          Returns the ini file name being used.
 java.lang.Integer getIntegerProperty(java.lang.String pstrSection, java.lang.String pstrProp)
          Returns the specified integer property from the specified section.
 java.lang.Long getLongProperty(java.lang.String pstrSection, java.lang.String pstrProp)
          Returns the specified long property from the specified section.
 java.util.Map getProperties(java.lang.String pstrSection)
          Returns a map containing all the properties under specified section.
 java.lang.String[] getPropertyNames(java.lang.String pstrSection)
          Returns a string array containing names of all the properties under specified section.
 java.lang.String getStringProperty(java.lang.String pstrSection, java.lang.String pstrProp)
          Returns the specified string property from the specified section.
 java.util.Date getTimestampProperty(java.lang.String pstrSection, java.lang.String pstrProp)
          Returns the specified date property from the specified section.
 int getTotalSections()
           
 void removeProperty(java.lang.String pstrSection, java.lang.String pstrProp)
          Removed specified property from the specified section.
 void removeSection(java.lang.String pstrSection)
          Removes the specified section if one exists, otherwise does nothing.
 boolean save()
          Flush changes back to the disk file.
 void setBooleanProperty(java.lang.String pstrSection, java.lang.String pstrProp, boolean pblnVal, java.lang.String pstrComments)
          Sets the specified boolean property.
 void setDateFormat(java.lang.String pstrDtFmt)
          Sets the format to be used to interpreat date values.
 void setDateProperty(java.lang.String pstrSection, java.lang.String pstrProp, java.util.Date pdtVal, java.lang.String pstrComments)
          Sets the specified java.util.Date property.
 void setDoubleProperty(java.lang.String pstrSection, java.lang.String pstrProp, double pdblVal, java.lang.String pstrComments)
          Sets the specified double property.
 void setIntegerProperty(java.lang.String pstrSection, java.lang.String pstrProp, int pintVal, java.lang.String pstrComments)
          Sets the specified integer property.
 void setLongProperty(java.lang.String pstrSection, java.lang.String pstrProp, long plngVal, java.lang.String pstrComments)
          Sets the specified long property.
 void setStringProperty(java.lang.String pstrSection, java.lang.String pstrProp, java.lang.String pstrVal, java.lang.String pstrComments)
          Sets the specified string property.
 void setTimeStampFormat(java.lang.String pstrTSFmt)
          Sets the format to be used to interpreat timestamp values.
 void setTimestampProperty(java.lang.String pstrSection, java.lang.String pstrProp, java.sql.Timestamp ptsVal, java.lang.String pstrComments)
          Sets the specified java.sql.Timestamp property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

INIFile

public INIFile(java.lang.String pstrPathAndName)
Create a iniFile object from the file named in the parameter.

Parameters:
pstrPathAndName - The full path and name of the ini file to be used.
Method Detail

getFileName

public java.lang.String getFileName()
Returns the ini file name being used.

Returns:
the INI file name.

getStringProperty

public java.lang.String getStringProperty(java.lang.String pstrSection,
                                          java.lang.String pstrProp)
Returns the specified string property from the specified section.

Parameters:
pstrSection - the INI section name.
pstrProp - the property to be retrieved.
Returns:
the string property value.

getBooleanProperty

public java.lang.Boolean getBooleanProperty(java.lang.String pstrSection,
                                            java.lang.String pstrProp)
Returns the specified boolean property from the specified section. This method considers the following values as boolean values.
  1. YES/yes/Yes - boolean true
  2. NO/no/No - boolean false
  3. 1 - boolean true
  4. 0 - boolean false
  5. TRUE/True/true - boolean true
  6. FALSE/False/false - boolean false

Parameters:
pstrSection - the INI section name.
pstrProp - the property to be retrieved.
Returns:
the boolean value

getIntegerProperty

public java.lang.Integer getIntegerProperty(java.lang.String pstrSection,
                                            java.lang.String pstrProp)
Returns the specified integer property from the specified section.

Parameters:
pstrSection - the INI section name.
pstrProp - the property to be retrieved.
Returns:
the integer property value.

getLongProperty

public java.lang.Long getLongProperty(java.lang.String pstrSection,
                                      java.lang.String pstrProp)
Returns the specified long property from the specified section.

Parameters:
pstrSection - the INI section name.
pstrProp - the property to be retrieved.
Returns:
the long property value.

getDoubleProperty

public java.lang.Double getDoubleProperty(java.lang.String pstrSection,
                                          java.lang.String pstrProp)
Returns the specified double property from the specified section.

Parameters:
pstrSection - the INI section name.
pstrProp - the property to be retrieved.
Returns:
the double property value.

getDateProperty

public java.util.Date getDateProperty(java.lang.String pstrSection,
                                      java.lang.String pstrProp)
Returns the specified date property from the specified section.

Parameters:
pstrSection - the INI section name.
pstrProp - the property to be retrieved.
Returns:
the date property value.

getTimestampProperty

public java.util.Date getTimestampProperty(java.lang.String pstrSection,
                                           java.lang.String pstrProp)
Returns the specified date property from the specified section.

Parameters:
pstrSection - the INI section name.
pstrProp - the property to be retrieved.
Returns:
the date property value.

addSection

public void addSection(java.lang.String pstrSection,
                       java.lang.String pstrComments)
Sets the comments associated with a section.

Parameters:
pstrSection - the section name
pstrComments - the comments.

setStringProperty

public void setStringProperty(java.lang.String pstrSection,
                              java.lang.String pstrProp,
                              java.lang.String pstrVal,
                              java.lang.String pstrComments)
Sets the specified string property.

Parameters:
pstrSection - the INI section name.
pstrProp - the property to be set.

setBooleanProperty

public void setBooleanProperty(java.lang.String pstrSection,
                               java.lang.String pstrProp,
                               boolean pblnVal,
                               java.lang.String pstrComments)
Sets the specified boolean property.

Parameters:
pstrSection - the INI section name.
pstrProp - the property to be set.
pblnVal - the boolean value to be persisted

setIntegerProperty

public void setIntegerProperty(java.lang.String pstrSection,
                               java.lang.String pstrProp,
                               int pintVal,
                               java.lang.String pstrComments)
Sets the specified integer property.

Parameters:
pstrSection - the INI section name.
pstrProp - the property to be set.
pintVal - the int property to be persisted.

setLongProperty

public void setLongProperty(java.lang.String pstrSection,
                            java.lang.String pstrProp,
                            long plngVal,
                            java.lang.String pstrComments)
Sets the specified long property.

Parameters:
pstrSection - the INI section name.
pstrProp - the property to be set.
plngVal - the long value to be persisted.

setDoubleProperty

public void setDoubleProperty(java.lang.String pstrSection,
                              java.lang.String pstrProp,
                              double pdblVal,
                              java.lang.String pstrComments)
Sets the specified double property.

Parameters:
pstrSection - the INI section name.
pstrProp - the property to be set.
pdblVal - the double value to be persisted.

setDateProperty

public void setDateProperty(java.lang.String pstrSection,
                            java.lang.String pstrProp,
                            java.util.Date pdtVal,
                            java.lang.String pstrComments)
Sets the specified java.util.Date property.

Parameters:
pstrSection - the INI section name.
pstrProp - the property to be set.
pdtVal - the date value to be persisted.

setTimestampProperty

public void setTimestampProperty(java.lang.String pstrSection,
                                 java.lang.String pstrProp,
                                 java.sql.Timestamp ptsVal,
                                 java.lang.String pstrComments)
Sets the specified java.sql.Timestamp property.

Parameters:
pstrSection - the INI section name.
pstrProp - the property to be set.
ptsVal - the timestamp value to be persisted.

setDateFormat

public void setDateFormat(java.lang.String pstrDtFmt)
                   throws java.lang.IllegalArgumentException
Sets the format to be used to interpreat date values.

Parameters:
pstrDtFmt - the format string
Throws:
java.lang.IllegalArgumentException - if the if the given pattern is invalid

setTimeStampFormat

public void setTimeStampFormat(java.lang.String pstrTSFmt)
Sets the format to be used to interpreat timestamp values.

Parameters:
pstrTSFmt - the format string
Throws:
java.lang.IllegalArgumentException - if the if the given pattern is invalid

getTotalSections

public int getTotalSections()

getAllSectionNames

public java.lang.String[] getAllSectionNames()
Returns a string array containing names of all sections in INI file.

Returns:
the string array of section names

getPropertyNames

public java.lang.String[] getPropertyNames(java.lang.String pstrSection)
Returns a string array containing names of all the properties under specified section.

Parameters:
pstrSection - the name of the section for which names of properties is to be retrieved.
Returns:
the string array of property names.

getProperties

public java.util.Map getProperties(java.lang.String pstrSection)
Returns a map containing all the properties under specified section.

Parameters:
pstrSection - the name of the section for which properties are to be retrieved.
Returns:
the map of properties.

removeProperty

public void removeProperty(java.lang.String pstrSection,
                           java.lang.String pstrProp)
Removed specified property from the specified section. If the specified section or the property does not exist, does nothing.

Parameters:
pstrSection - the section name.
pstrProp - the name of the property to be removed.

removeSection

public void removeSection(java.lang.String pstrSection)
Removes the specified section if one exists, otherwise does nothing.

Parameters:
pstrSection - the name of the section to be removed.

save

public boolean save()
Flush changes back to the disk file. If the disk file does not exists then creates the new one.