org.w3c.util
Class XMLProperties

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<java.lang.Object,java.lang.Object>
          extended by java.util.Properties
              extended by org.w3c.util.XMLProperties
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,java.lang.Object>

public class XMLProperties
extends java.util.Properties

The Properties class represents a persistent set of properties. The Properties can be saved to a stream or loaded from a stream. Each key and its corresponding value in the property list is a string.

A property list can contain another property list as its "defaults"; this second property list is searched if the property key is not found in the original property list. Because Properties inherits from Hashtable, the put and putAll methods can be applied to a Properties object. Their use is strongly discouraged as they allow the caller to insert entries whose keys or values are not Strings. The setProperty method should be used instead. If the store or save method is called on a "compromised" Properties object that contains a non-String key or value, the call will fail.

This is a special implementation for XML :

   <properties>
      <key name="My_key1">My_Value1</key>
      <key name="My_key2">My_Value2</key>
   </properties>
 

See Also:
Serialized Form

Field Summary
 boolean debug
           
static java.lang.String PARSER_P
           
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
XMLProperties()
          Creates an empty property list with no default values.
XMLProperties(java.util.Properties defaults)
          Creates an empty property list with the specified defaults.
XMLProperties(java.lang.String parser, java.util.Properties defaults)
          Creates an empty property list with the specified defaults.
 
Method Summary
protected  java.lang.StringBuffer encode(java.lang.String string)
           
 void load(java.io.File file)
          Reads a property list from an input stream.
 void load(java.io.InputStream in)
          Reads a property list from an input stream.
 void save(java.io.OutputStream out, java.lang.String header)
          Deprecated. This method does not throw an IOException if an I/O error occurs while saving the property list. As of JDK 1.2, the preferred way to save a properties list is via the store(OutputStream out, String header) method.
 void setDebug(boolean debug)
           
 void store(java.io.OutputStream out, java.lang.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.
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, loadFromXML, propertyNames, setProperty, storeToXML, storeToXML
 
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

PARSER_P

public static final java.lang.String PARSER_P
See Also:
Constant Field Values

debug

public boolean debug
Constructor Detail

XMLProperties

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


XMLProperties

public XMLProperties(java.util.Properties defaults)
Creates an empty property list with the specified defaults.

Parameters:
defaults - the defaults.

XMLProperties

public XMLProperties(java.lang.String parser,
                     java.util.Properties defaults)
Creates an empty property list with the specified defaults.

Parameters:
parser - the XML Parser classname (default is PARSER_P)
defaults - the defaults.
Method Detail

load

public void load(java.io.InputStream in)
          throws java.io.IOException
Reads a property list from an input stream.

Overrides:
load in class java.util.Properties
Parameters:
in - the input stream.
Throws:
java.io.IOException - if an error occurred when reading from the input stream.
Since:
JDK1.0

load

public void load(java.io.File file)
          throws java.io.IOException
Reads a property list from an input stream. This method try to load properties with super.load() if the XMLParser failed. Use this method to translate an Property set to an XML Property set.

Parameters:
file - the properties file.
Throws:
java.io.IOException - if an error occurred when reading from the input stream.
Since:
JDK1.0

save

public void save(java.io.OutputStream out,
                 java.lang.String header)
Deprecated. This method does not throw an IOException if an I/O error occurs while saving the property list. As of JDK 1.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.

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

store

public void store(java.io.OutputStream out,
                  java.lang.String header)
           throws java.io.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.

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

Overrides:
store in class java.util.Properties
Parameters:
out - an output stream.
header - a description of the property list.
Throws:
java.lang.ClassCastException - if this Properties object contains any keys or values that are not Strings.
java.io.IOException

encode

protected java.lang.StringBuffer encode(java.lang.String string)

setDebug

public void setDebug(boolean debug)