com.ptc.windchill.structconf.properties
Class PropertiesClone

java.lang.Object
  extended byjava.util.Dictionary
      extended byjava.util.Hashtable
          extended bycom.ptc.windchill.structconf.properties.PropertiesClone
All Implemented Interfaces:
Cloneable, Map, Serializable

public class PropertiesClone
extends Hashtable

This is a modified copy of the jdk 1.4 sources for java.util.Properties. Of note, it adds the ability for subclasses to implement methods to handle blank lines and comments in case they want to preserve formatting.

See Also:
blankLineEncountered(), commentLineEncountered(java.lang.String), Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.Hashtable
 
Field Summary
protected  PropertiesClone defaults
          A property list that contains default values for any keys not found in this property list.
private static char[] hexDigit
          A table of hex digits
private static String keyValueSeparators
           
private static long serialVersionUID
          use serialVersionUID from JDK 1.1.X for interoperability
private static String specialSaveChars
           
private static String strictKeyValueSeparators
           
private static String whiteSpaceChars
           
 
Fields inherited from class java.util.Hashtable
 
Constructor Summary
PropertiesClone()
          Creates an empty property list with no default values.
 
Method Summary
protected  void blankLineEncountered()
           
protected  void commentLineEncountered(String comment)
           
private  boolean continueLine(String line)
           
private  void enumerate(Hashtable h)
          Enumerates all key/value pairs in the specified hastable.
 String getProperty(String key)
          Searches for the property with the specified key in this property list.
 String getProperty(String key, String defaultValue)
          Searches for the property with the specified key in this property list.
 void list(PrintStream out)
          Prints this property list out to the specified output stream.
 void list(PrintWriter out)
          Prints this property list out to the specified output stream.
 void load(InputStream inStream)
          Reads a property list (key and element pairs) from the input stream.
private  String loadConvert(String theString)
           
 Enumeration propertyNames()
          Returns an enumeration of all the keys in this property list, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.
 void save(OutputStream out, String header)
          Deprecated. This method does not throw an IOException if an I/O error occurs while saving the property list. As of the Java 2 platform v1.2, the preferred way to save a properties list is via the store(OutputStream out, String header) method.
private  String saveConvert(String theString, boolean escapeSpace)
           
 Object setProperty(String key, String value)
          Calls the Hashtable method put.
 void store(OutputStream out, String header)
          Writes this property list (key and element pairs) in this Properties table to the output stream in a format suitable for loading into a Properties table using the load method.
private static char toHex(int nibble)
          Convert a nibble to a hex character
private static void writeln(BufferedWriter bw, String s)
           
 
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

serialVersionUID

private static final long serialVersionUID
use serialVersionUID from JDK 1.1.X for interoperability

See Also:
Constant Field Values

defaults

protected PropertiesClone defaults
A property list that contains default values for any keys not found in this property list.


keyValueSeparators

private static final String keyValueSeparators
See Also:
Constant Field Values

strictKeyValueSeparators

private static final String strictKeyValueSeparators
See Also:
Constant Field Values

specialSaveChars

private static final String specialSaveChars
See Also:
Constant Field Values

whiteSpaceChars

private static final String whiteSpaceChars
See Also:
Constant Field Values

hexDigit

private static final char[] hexDigit
A table of hex digits

Constructor Detail

PropertiesClone

public PropertiesClone()
Creates an empty property list with no default values.

Method Detail

setProperty

public Object setProperty(String key,
                          String value)
Calls the Hashtable method put. Provided for parallelism with the getProperty method. Enforces use of strings for property keys and values. The value returned is the result of the Hashtable call to put.

Parameters:
key - the key to be placed into this property list.
value - the value corresponding to key.
Returns:
the previous value of the specified key in this property list, or null if it did not have one.
Since:
1.2
See Also:
getProperty(java.lang.String)

load

public void load(InputStream inStream)
          throws IOException
Reads a property list (key and element pairs) from the input stream. The stream is assumed to be using the ISO 8859-1 character encoding.

Every property occupies one line of the input stream. Each line is terminated by a line terminator (\n or \r or \r\n). Lines from the input stream are processed until end of file is reached on the input stream.

A line that contains only whitespace or whose first non-whitespace character is an ASCII # or ! is ignored (thus, # or ! indicate comment lines).

Every line other than a blank line or a comment line describes one property to be added to the table (except that if a line ends with \, then the following line, if it exists, is treated as a continuation line, as described below). The key consists of all the characters in the line starting with the first non-whitespace character and up to, but not including, the first ASCII =, :, or whitespace character. All of the key termination characters may be included in the key by preceding them with a \. Any whitespace after the key is skipped; if the first non-whitespace character after the key is = or :, then it is ignored and any whitespace characters after it are also skipped. All remaining characters on the line become part of the associated element string. Within the element string, the ASCII escape sequences \t, \n, \r, \\, \", \', \ (a backslash and a space), and \uxxxx are recognized and converted to single characters. Moreover, if the last character on the line is \, then the next line is treated as a continuation of the current line; the \ and line terminator are simply discarded, and any leading whitespace characters on the continuation line are also discarded and are not part of the element string.

As an example, each of the following four lines specifies the key "Truth" and the associated element value "Beauty":

 Truth = Beauty
	Truth:Beauty
 Truth			:Beauty
 
As another example, the following three lines specify a single property:

 fruits				apple, banana, pear, \
                                  cantaloupe, watermelon, \
                                  kiwi, mango
 
The key is "fruits" and the associated element is:

"apple, banana, pear, cantaloupe, watermelon, kiwi, mango"
Note that a space appears before each \ so that a space will appear after each comma in the final result; the \, line terminator, and leading whitespace on the continuation line are merely discarded and are not replaced by one or more other characters.

As a third example, the line:

cheeses
 
specifies that the key is "cheeses" and the associated element is the empty string.

Parameters:
inStream - the input stream.
Throws:
IOException - if an error occurred when reading from the input stream.

blankLineEncountered

protected void blankLineEncountered()

commentLineEncountered

protected void commentLineEncountered(String comment)

continueLine

private boolean continueLine(String line)

loadConvert

private String loadConvert(String theString)

saveConvert

private String saveConvert(String theString,
                           boolean escapeSpace)

save

public void save(OutputStream out,
                 String header)
Deprecated. This method does not throw an IOException if an I/O error occurs while saving the property list. As of the Java 2 platform v1.2, the preferred way to save a properties list is via the store(OutputStream out, String header) method.

Calls the store(OutputStream out, String header) method and suppresses IOExceptions that were thrown.

Parameters:
out - an output stream.
header - a description of the property list.
Throws:
ClassCastException - if this Properties object contains any keys or values that are not Strings.

store

public void store(OutputStream out,
                  String header)
           throws IOException
Writes this property list (key and element pairs) in this Properties table to the output stream in a format suitable for loading into a Properties table using the load method. The stream is written using the ISO 8859-1 character encoding.

Properties from the defaults table of this Properties table (if any) are not written out by this method.

If the header argument is not null, then an ASCII # character, the header string, and a line separator are first written to the output stream. Thus, the header can serve as an identifying comment.

Next, a comment line is always written, consisting of an ASCII # character, the current date and time (as if produced by the toString method of Date for the current time), and a line separator as generated by the Writer.

Then every entry in this Properties table is written out, one per line. For each entry the key string is written, then an ASCII =, then the associated element string. Each character of the element string is examined to see whether it should be rendered as an escape sequence. The ASCII characters \, tab, newline, and carriage return are written as \\, \t, \n, and \r, respectively. Characters less than \u0020 and characters greater than \u007E are written as \uxxxx for the appropriate hexadecimal value xxxx. Leading space characters, but not embedded or trailing space characters, are written with a preceding \. The key and value characters #, !, =, and : are written with a preceding slash to ensure that they are properly loaded.

After the entries have been written, the output stream is flushed. The output stream remains open after this method returns.

Parameters:
out - an output stream.
header - a description of the property list.
Throws:
IOException - if writing this property list to the specified output stream throws an IOException.
ClassCastException - if this Properties object contains any keys or values that are not Strings.
NullPointerException - if out is null.
Since:
1.2

writeln

private static void writeln(BufferedWriter bw,
                            String s)
                     throws IOException
Throws:
IOException

getProperty

public String getProperty(String key)
Searches for the property with the specified key in this property list. If the key is not found in this property list, the default property list, and its defaults, recursively, are then checked. The method returns null if the property is not found.

Parameters:
key - the property key.
Returns:
the value in this property list with the specified key value.
See Also:
setProperty(java.lang.String, java.lang.String), defaults

getProperty

public String getProperty(String key,
                          String defaultValue)
Searches for the property with the specified key in this property list. If the key is not found in this property list, the default property list, and its defaults, recursively, are then checked. The method returns the default value argument if the property is not found.

Parameters:
key - the hashtable key.
defaultValue - a default value.
Returns:
the value in this property list with the specified key value.
See Also:
setProperty(java.lang.String, java.lang.String), defaults

propertyNames

public Enumeration propertyNames()
Returns an enumeration of all the keys in this property list, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

Returns:
an enumeration of all the keys in this property list, including the keys in the default property list.
See Also:
Enumeration, Properties.defaults

list

public void list(PrintStream out)
Prints this property list out to the specified output stream. This method is useful for debugging.

Parameters:
out - an output stream.

list

public void list(PrintWriter out)
Prints this property list out to the specified output stream. This method is useful for debugging.

Parameters:
out - an output stream.
Since:
JDK1.1

enumerate

private void enumerate(Hashtable h)
Enumerates all key/value pairs in the specified hastable.

Parameters:
h - the hashtable

toHex

private static char toHex(int nibble)
Convert a nibble to a hex character

Parameters:
nibble - the nibble to convert.