org.omegahat.Environment.Utils
Class TrimmedProperties

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--java.util.Properties
                    |
                    +--org.omegahat.Environment.Utils.TrimmedProperties
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable
Direct Known Subclasses:
ColorTable, Options, SubstitutedTrimmedProperties, XMLAttributeTable

public class TrimmedProperties
extends java.util.Properties

This class extends the Properties class and differs only in that the properties are loaded and trimmed in one step to remove leading and trailing white space. This allows the application to be more forgiving about the resource files we read and avoids some annoying conditions when comparing strings. Also, it can optionally remove the quotes around a phrase which allows white space to be placed at the beginning or end of an entry and escaped from the trimming procedure.

Suppliess a merge facility. The add() method is available from super class.

See Also:
Serialized Form

Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
 java.lang.String[][] booleanStrings
           
protected  boolean stripQuotes
          Flag indicating whether quotes are removed from the value of each property.
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
TrimmedProperties()
          Empty constructor to allocate the object
TrimmedProperties(boolean quotes)
          Sets the stripQuotes variable to the specified value.
TrimmedProperties(java.io.File file)
          Create the properties table by reading the name-value pairs from a file
TrimmedProperties(java.io.File file, boolean quotes)
          Specifies whether to strip quotes from the different values and then reads these name-value pairs from the contents of the specified file.
TrimmedProperties(InputFileInt f)
           
TrimmedProperties(InputFileInt f, boolean quotes)
           
TrimmedProperties(java.io.InputStream s)
           
TrimmedProperties(java.util.Properties props)
          Create the trimmed properties from an existing properties object.
TrimmedProperties(java.util.Properties props, boolean quotes)
          Create the trimmed properties from an existing properties object, stripping quotes as specfied by the value of quotes.
TrimmedProperties(java.lang.String txt)
          Creates the properties by parsing the supplied string as if it were the contents of a file.
TrimmedProperties(java.lang.String txt, boolean quotes)
          Specifies whether to strip quotes from the different values and then reads these name-value pairs from the contents of the specified text.
 
Method Summary
 boolean asBoolean(java.lang.String val)
           
 boolean isBoolean(java.lang.String v)
           
 void load(java.io.File file)
           
 void load(java.io.InputStream in)
           
 int merge(java.util.Properties alt)
          Merge the entries in the specified table with this one, skipping entries already in this table.
 int merge(java.util.Properties alt, boolean override)
          Merge the contents of the specified properties table with this one, allowing the entries in that remote table to override the ones in this table iff override is true.
 boolean parse(java.lang.String contents)
           
 boolean processElement(java.lang.String name, java.lang.String val)
          Basic, degenerate method for process which should be overridden to provide any functionality.
 int processElements()
          Loops over the elements in the table and calls processElement() on each.
 java.lang.String[] stringList(java.lang.String tmp)
           
 java.lang.String[] stringList(java.lang.String tmp, char sep)
           
 boolean stripQuotes()
          Determine whether we are intending to remove the quotes from the entries.
 boolean stripQuotes(boolean val)
          Set the flag that dictates whether we strip the quotes from the entries in the table.
 void trim()
          Strip the white-space from all entries, except those whose name ends with .separator, and also remove the quotes if the stripQuotes variable is set to true.
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, propertyNames, save, setProperty, store
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

booleanStrings

public java.lang.String[][] booleanStrings

stripQuotes

protected boolean stripQuotes
Flag indicating whether quotes are removed from the value of each property.
See Also:
trim()
Constructor Detail

TrimmedProperties

public TrimmedProperties()
Empty constructor to allocate the object

TrimmedProperties

public TrimmedProperties(boolean quotes)
Sets the stripQuotes variable to the specified value.

TrimmedProperties

public TrimmedProperties(java.lang.String txt)
Creates the properties by parsing the supplied string as if it were the contents of a file. This is done directly using parse().

TrimmedProperties

public TrimmedProperties(java.lang.String txt,
                         boolean quotes)
Specifies whether to strip quotes from the different values and then reads these name-value pairs from the contents of the specified text.

TrimmedProperties

public TrimmedProperties(java.io.File file)
Create the properties table by reading the name-value pairs from a file

TrimmedProperties

public TrimmedProperties(java.io.File file,
                         boolean quotes)
Specifies whether to strip quotes from the different values and then reads these name-value pairs from the contents of the specified file.

TrimmedProperties

public TrimmedProperties(java.util.Properties props)
Create the trimmed properties from an existing properties object.

TrimmedProperties

public TrimmedProperties(java.util.Properties props,
                         boolean quotes)
Create the trimmed properties from an existing properties object, stripping quotes as specfied by the value of quotes.

TrimmedProperties

public TrimmedProperties(java.io.InputStream s)

TrimmedProperties

public TrimmedProperties(InputFileInt f)

TrimmedProperties

public TrimmedProperties(InputFileInt f,
                         boolean quotes)
Method Detail

parse

public boolean parse(java.lang.String contents)

load

public void load(java.io.InputStream in)
Overrides:
load in class java.util.Properties

load

public void load(java.io.File file)

trim

public void trim()
Strip the white-space from all entries, except those whose name ends with .separator, and also remove the quotes if the stripQuotes variable is set to true.

merge

public int merge(java.util.Properties alt,
                 boolean override)
Merge the contents of the specified properties table with this one, allowing the entries in that remote table to override the ones in this table iff override is true.
Parameters:
alt - the properties which are to be added to this table.
override - whether entries common to both tables are resolved by using the value in the remote table alt

merge

public int merge(java.util.Properties alt)
Merge the entries in the specified table with this one, skipping entries already in this table.

stripQuotes

public boolean stripQuotes()
Determine whether we are intending to remove the quotes from the entries.
See Also:
trim()

stripQuotes

public boolean stripQuotes(boolean val)
Set the flag that dictates whether we strip the quotes from the entries in the table.

processElements

public int processElements()
Loops over the elements in the table and calls processElement() on each.

processElement

public boolean processElement(java.lang.String name,
                              java.lang.String val)
Basic, degenerate method for process which should be overridden to provide any functionality.

asBoolean

public boolean asBoolean(java.lang.String val)
                  throws java.lang.Exception

isBoolean

public boolean isBoolean(java.lang.String v)

stringList

public java.lang.String[] stringList(java.lang.String tmp)

stringList

public java.lang.String[] stringList(java.lang.String tmp,
                                     char sep)