org.apache.commons.configuration.plist
Class PropertyListConfiguration

java.lang.Object
  extended by org.apache.commons.configuration.event.EventSource
      extended by org.apache.commons.configuration.AbstractConfiguration
          extended by org.apache.commons.configuration.HierarchicalConfiguration
              extended by org.apache.commons.configuration.AbstractHierarchicalFileConfiguration
                  extended by org.apache.commons.configuration.plist.PropertyListConfiguration
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Configuration, ConfigurationListener, FileConfiguration

public class PropertyListConfiguration
extends AbstractHierarchicalFileConfiguration

NeXT / OpenStep style configuration. This configuration can read and write ASCII plist files. It support the GNUStep extension to specify date objects.

References:

Example:

 {
     foo = "bar";

     array = ( value1, value2, value3 );

     data = <4f3e0145ab>;

     date = <*D2007-05-05 20:05:00 +0100>;

     nested =
     {
         key1 = value1;
         key2 = value;
         nested =
         {
             foo = bar
         }
     }
 }
 

Since:
1.2
Version:
$Revision: 590474 $, $Date: 2007-10-30 22:35:11 +0100 (Di, 30 Okt 2007) $
Author:
Emmanuel Bourg
See Also:
Serialized Form

Nested Class Summary
private static class PropertyListConfiguration.DateComponentParser
          A helper class for parsing and formatting date literals.
private static class PropertyListConfiguration.DateFieldParser
          A specialized date component parser implementation that deals with numeric calendar fields.
private static class PropertyListConfiguration.DateSeparatorParser
          A specialized date component parser implementation that deals with separator characters.
private static class PropertyListConfiguration.DateTimeZoneParser
          A specialized date component parser implementation that deals with the time zone part of a date component.
 
Nested classes/interfaces inherited from class org.apache.commons.configuration.AbstractHierarchicalFileConfiguration
AbstractHierarchicalFileConfiguration.FileConfigurationDelegate
 
Nested classes/interfaces inherited from class org.apache.commons.configuration.HierarchicalConfiguration
HierarchicalConfiguration.BuilderVisitor, HierarchicalConfiguration.Node, HierarchicalConfiguration.NodeVisitor
 
Field Summary
private static PropertyListConfiguration.DateComponentParser BLANK_SEPARATOR_PARSER
          Constant for the separator parser for blanks between the parts.
private static PropertyListConfiguration.DateComponentParser[] DATE_PARSERS
          An array with the component parsers for dealing with dates.
private static PropertyListConfiguration.DateComponentParser DATE_SEPARATOR_PARSER
          Constant for the separator parser for the date part.
private static int INDENT_SIZE
          Size of the indentation for the generated file.
private static int MILLIS_PER_MINUTE
          Constant for the milliseconds of a minute.
private static int MINUTES_PER_HOUR
          Constant for the minutes per hour.
private static char PAD_CHAR
          Constant for the padding character in the date format.
private static long serialVersionUID
          The serial version UID.
private static PropertyListConfiguration.DateComponentParser TIME_SEPARATOR_PARSER
          Constant for the separator parser for the time part.
private static int TIME_ZONE_LENGTH
          Constant for the length of a time zone.
private static java.lang.String TIME_ZONE_PREFIX
          Constant for the ID prefix for GMT time zones.
 
Fields inherited from class org.apache.commons.configuration.HierarchicalConfiguration
EVENT_ADD_NODES, EVENT_CLEAR_TREE, EVENT_SUBNODE_CHANGED
 
Fields inherited from class org.apache.commons.configuration.AbstractConfiguration
END_TOKEN, EVENT_ADD_PROPERTY, EVENT_CLEAR, EVENT_CLEAR_PROPERTY, EVENT_READ_PROPERTY, EVENT_SET_PROPERTY, START_TOKEN
 
Constructor Summary
PropertyListConfiguration()
          Creates an empty PropertyListConfiguration object which can be used to synthesize a new plist file by adding values and then saving().
PropertyListConfiguration(java.io.File file)
          Creates and loads the property list from the specified file.
PropertyListConfiguration(HierarchicalConfiguration c)
          Creates a new instance of PropertyListConfiguration and copies the content of the specified configuration into this object.
PropertyListConfiguration(java.lang.String fileName)
          Creates and loads the property list from the specified file.
PropertyListConfiguration(java.net.URL url)
          Creates and loads the property list from the specified URL.
 
Method Summary
 void addProperty(java.lang.String key, java.lang.Object value)
          Add a property to the configuration.
(package private) static java.lang.String formatDate(java.util.Calendar cal)
          Returns a string representation for the date specified by the given calendar.
(package private) static java.lang.String formatDate(java.util.Date date)
          Returns a string representation for the specified date.
 void load(java.io.Reader in)
          Load the configuration from the specified reader.
(package private) static java.util.Date parseDate(java.lang.String s)
          Parses a date in a format like <*D2002-03-22 11:30:00 +0100>.
private  void printNode(java.io.PrintWriter out, int indentLevel, HierarchicalConfiguration.Node node)
          Append a node to the writer, indented according to a specific level.
private  void printValue(java.io.PrintWriter out, int indentLevel, java.lang.Object value)
          Append a value to the writer, indented according to a specific level.
(package private)  java.lang.String quoteString(java.lang.String s)
          Quote the specified string if necessary, that's if the string contains: a space character (' ', '\t', '\r', '\n') a quote '"' special characters in plist files ('(', ')', '{', '}', '=', ';', ',') Quotes within the string are escaped.
 void save(java.io.Writer out)
          Save the configuration to the specified writer.
 void setProperty(java.lang.String key, java.lang.Object value)
          Sets the value of the specified property.
 
Methods inherited from class org.apache.commons.configuration.AbstractHierarchicalFileConfiguration
addNodes, addPropertyDirect, clearProperty, clearTree, configurationChanged, containsKey, createDelegate, fetchNodeList, getBasePath, getDelegate, getEncoding, getFile, getFileName, getKeys, getProperty, getReloadingStrategy, getURL, isAutoSave, isEmpty, load, load, load, load, load, load, reload, save, save, save, save, save, save, setAutoSave, setBasePath, setDelegate, setEncoding, setFile, setFileName, setReloadingStrategy, setURL, subnodeConfigurationChanged
 
Methods inherited from class org.apache.commons.configuration.HierarchicalConfiguration
clearNode, clearNode, clearReferences, clone, configurationAt, configurationAt, configurationsAt, createAddPath, createNode, createSubnodeConfiguration, createSubnodeConfiguration, fetchAddNode, findLastPathNode, findPropertyNodes, getDefaultExpressionEngine, getExpressionEngine, getKeys, getMaxIndex, getRoot, getRootNode, interpolatedConfiguration, nodeDefined, nodeDefined, removeNode, removeNode, setDefaultExpressionEngine, setExpressionEngine, setRoot, setRootNode, subset
 
Methods inherited from class org.apache.commons.configuration.AbstractConfiguration
addErrorLogListener, append, clear, clearPropertyDirect, copy, createInterpolator, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDefaultListDelimiter, getDelimiter, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getList, getList, getListDelimiter, getLogger, getLong, getLong, getLong, getProperties, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, getSubstitutor, interpolate, interpolate, interpolateHelper, isDelimiterParsingDisabled, isThrowExceptionOnMissing, resolveContainerStore, setDefaultListDelimiter, setDelimiter, setDelimiterParsingDisabled, setListDelimiter, setLogger, setThrowExceptionOnMissing
 
Methods inherited from class org.apache.commons.configuration.event.EventSource
addConfigurationListener, addErrorListener, clearConfigurationListeners, clearErrorListeners, createErrorEvent, createEvent, fireError, fireEvent, getConfigurationListeners, getErrorListeners, isDetailEvents, removeConfigurationListener, removeErrorListener, setDetailEvents
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.commons.configuration.Configuration
clear, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getList, getList, getLong, getLong, getLong, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, subset
 

Field Detail

DATE_SEPARATOR_PARSER

private static final PropertyListConfiguration.DateComponentParser DATE_SEPARATOR_PARSER
Constant for the separator parser for the date part.


TIME_SEPARATOR_PARSER

private static final PropertyListConfiguration.DateComponentParser TIME_SEPARATOR_PARSER
Constant for the separator parser for the time part.


BLANK_SEPARATOR_PARSER

private static final PropertyListConfiguration.DateComponentParser BLANK_SEPARATOR_PARSER
Constant for the separator parser for blanks between the parts.


DATE_PARSERS

private static final PropertyListConfiguration.DateComponentParser[] DATE_PARSERS
An array with the component parsers for dealing with dates.


TIME_ZONE_PREFIX

private static final java.lang.String TIME_ZONE_PREFIX
Constant for the ID prefix for GMT time zones.

See Also:
Constant Field Values

serialVersionUID

private static final long serialVersionUID
The serial version UID.

See Also:
Constant Field Values

MILLIS_PER_MINUTE

private static final int MILLIS_PER_MINUTE
Constant for the milliseconds of a minute.

See Also:
Constant Field Values

MINUTES_PER_HOUR

private static final int MINUTES_PER_HOUR
Constant for the minutes per hour.

See Also:
Constant Field Values

INDENT_SIZE

private static final int INDENT_SIZE
Size of the indentation for the generated file.

See Also:
Constant Field Values

TIME_ZONE_LENGTH

private static final int TIME_ZONE_LENGTH
Constant for the length of a time zone.

See Also:
Constant Field Values

PAD_CHAR

private static final char PAD_CHAR
Constant for the padding character in the date format.

See Also:
Constant Field Values
Constructor Detail

PropertyListConfiguration

public PropertyListConfiguration()
Creates an empty PropertyListConfiguration object which can be used to synthesize a new plist file by adding values and then saving().


PropertyListConfiguration

public PropertyListConfiguration(HierarchicalConfiguration c)
Creates a new instance of PropertyListConfiguration and copies the content of the specified configuration into this object.

Parameters:
c - the configuration to copy
Since:
1.4

PropertyListConfiguration

public PropertyListConfiguration(java.lang.String fileName)
                          throws ConfigurationException
Creates and loads the property list from the specified file.

Parameters:
fileName - The name of the plist file to load.
Throws:
ConfigurationException - Error while loading the plist file

PropertyListConfiguration

public PropertyListConfiguration(java.io.File file)
                          throws ConfigurationException
Creates and loads the property list from the specified file.

Parameters:
file - The plist file to load.
Throws:
ConfigurationException - Error while loading the plist file

PropertyListConfiguration

public PropertyListConfiguration(java.net.URL url)
                          throws ConfigurationException
Creates and loads the property list from the specified URL.

Parameters:
url - The location of the plist file to load.
Throws:
ConfigurationException - Error while loading the plist file
Method Detail

setProperty

public void setProperty(java.lang.String key,
                        java.lang.Object value)
Description copied from class: HierarchicalConfiguration
Sets the value of the specified property.

Specified by:
setProperty in interface Configuration
Overrides:
setProperty in class AbstractHierarchicalFileConfiguration
Parameters:
key - the key of the property to set
value - the new value of this property

addProperty

public void addProperty(java.lang.String key,
                        java.lang.Object value)
Description copied from interface: Configuration
Add a property to the configuration. If it already exists then the value stated here will be added to the configuration entry. For example, if the property:
resource.loader = file
is already present in the configuration and you call
addProperty("resource.loader", "classpath")
Then you will end up with a List like the following:
["file", "classpath"]

Specified by:
addProperty in interface Configuration
Overrides:
addProperty in class AbstractConfiguration
Parameters:
key - The key to add the property to.
value - The value to add.

load

public void load(java.io.Reader in)
          throws ConfigurationException
Description copied from interface: FileConfiguration
Load the configuration from the specified reader.

Parameters:
in - the reader
Throws:
ConfigurationException - if an error occurs during the load operation

save

public void save(java.io.Writer out)
          throws ConfigurationException
Description copied from interface: FileConfiguration
Save the configuration to the specified writer.

Parameters:
out - the writer
Throws:
ConfigurationException - if an error occurs during the save operation

printNode

private void printNode(java.io.PrintWriter out,
                       int indentLevel,
                       HierarchicalConfiguration.Node node)
Append a node to the writer, indented according to a specific level.


printValue

private void printValue(java.io.PrintWriter out,
                        int indentLevel,
                        java.lang.Object value)
Append a value to the writer, indented according to a specific level.


quoteString

java.lang.String quoteString(java.lang.String s)
Quote the specified string if necessary, that's if the string contains: Quotes within the string are escaped.

Examples:


parseDate

static java.util.Date parseDate(java.lang.String s)
                         throws ParseException
Parses a date in a format like <*D2002-03-22 11:30:00 +0100>.

Parameters:
s - the string with the date to be parsed
Returns:
the parsed date
Throws:
ParseException - if an error occurred while parsing the string

formatDate

static java.lang.String formatDate(java.util.Calendar cal)
Returns a string representation for the date specified by the given calendar.

Parameters:
cal - the calendar with the initialized date
Returns:
a string for this date

formatDate

static java.lang.String formatDate(java.util.Date date)
Returns a string representation for the specified date.

Parameters:
date - the date
Returns:
a string for this date