svn commit: r227018 [1/2] - in /jakarta/commons/proper/configuration/trunk: ./ conf/ src/java/org/apache/commons/configuration/ src/java/org/apache/commons/configuration/plist/ src/test/org/apache/commons/configuration/plist/ xdocs/

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r227018 [1/2] - in /jakarta/commons/proper/configuration/trunk: ./ conf/ src/java/org/apache/commons/configuration/ src/java/org/apache/commons/configuration/plist/ src/test/org/apache/commons/configuration/plist/ xdocs/

Emmanuel Bourg-3
Author: ebourg
Date: Tue Aug  2 07:43:20 2005
New Revision: 227018

URL: http://svn.apache.org/viewcvs?rev=227018&view=rev
Log:
New configurations implementing the "property list" formats used in NeXT, OpenStep and Mac OS X

Added:
    jakarta/commons/proper/configuration/trunk/conf/PropertyList-1.0.dtd
    jakarta/commons/proper/configuration/trunk/conf/test.plist
    jakarta/commons/proper/configuration/trunk/conf/test.plist.xml
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractHierarchicalFileConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/ParseException.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.jj
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParserConstants.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParserTokenManager.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/SimpleCharStream.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/Token.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/TokenMgrError.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java
Modified:
    jakarta/commons/proper/configuration/trunk/maven.xml
    jakarta/commons/proper/configuration/trunk/project.properties
    jakarta/commons/proper/configuration/trunk/project.xml
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationFactory.java
    jakarta/commons/proper/configuration/trunk/xdocs/changes.xml

Added: jakarta/commons/proper/configuration/trunk/conf/PropertyList-1.0.dtd
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/conf/PropertyList-1.0.dtd?rev=227018&view=auto
==============================================================================
--- jakarta/commons/proper/configuration/trunk/conf/PropertyList-1.0.dtd (added)
+++ jakarta/commons/proper/configuration/trunk/conf/PropertyList-1.0.dtd Tue Aug  2 07:43:20 2005
@@ -0,0 +1,19 @@
+<!ENTITY % plistObject "(array | data | date | dict | real | integer | string | true | false )" >

+<!ELEMENT plist %plistObject;>

+<!ATTLIST plist version CDATA "1.0" >

+

+<!-- Collections -->

+<!ELEMENT array (%plistObject;)*>

+<!ELEMENT dict (key, %plistObject;)*>

+<!ELEMENT key (#PCDATA)>

+

+<!--- Primitive types -->

+<!ELEMENT string (#PCDATA)>

+<!ELEMENT data (#PCDATA)> <!-- Contents interpreted as Base-64 encoded -->

+<!ELEMENT date (#PCDATA)> <!-- Contents should conform to a subset of ISO 8601 (in particular, YYYY '-' MM '-' DD 'T' HH ':' MM ':' SS 'Z'.  Smaller units may be omitted with a loss of precision) -->

+

+<!-- Numerical primitives -->

+<!ELEMENT true EMPTY>  <!-- Boolean constant true -->

+<!ELEMENT false EMPTY> <!-- Boolean constant false -->

+<!ELEMENT real (#PCDATA)> <!-- Contents should represent a floating point number matching ("+" | "-")? d+ ("."d*)? ("E" ("+" | "-") d+)? where d is a digit 0-9.  -->

+<!ELEMENT integer (#PCDATA)> <!-- Contents should represent a (possibly signed) integer number in base 10 -->


Added: jakarta/commons/proper/configuration/trunk/conf/test.plist
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/conf/test.plist?rev=227018&view=auto
==============================================================================
--- jakarta/commons/proper/configuration/trunk/conf/test.plist (added)
+++ jakarta/commons/proper/configuration/trunk/conf/test.plist Tue Aug  2 07:43:20 2005
@@ -0,0 +1,41 @@
+{

+    simple-string = string1;

+    quoted-string = "string2";

+    quoted-string2 = "this is a string";

+    "complex-string" = "this is a \"complex\" string {(=,;)}";

+

+    array = ( "value1", "value2", "value3" );

+

+    empty-array = ();

+

+    nested-arrays = ( (a , b) , (c, d) );

+

+    dictionary-array =

+    (

+        { foo = bar },

+        { key = value }

+    )

+

+    dictionary =

+    {

+        foo1 = bar1;

+        foo2 = bar2;

+    }

+

+    empty-dictionary = { };

+

+    nested-dictionaries =

+    {

+        foo =

+        {

+            bar =

+            {

+                "key" = "value";

+            }

+        }

+    }

+

+    data = <666F6f 20 626172>;

+

+    empty-data = < >;

+}


Added: jakarta/commons/proper/configuration/trunk/conf/test.plist.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/conf/test.plist.xml?rev=227018&view=auto
==============================================================================
--- jakarta/commons/proper/configuration/trunk/conf/test.plist.xml (added)
+++ jakarta/commons/proper/configuration/trunk/conf/test.plist.xml Tue Aug  2 07:43:20 2005
@@ -0,0 +1,81 @@
+<?xml version="1.0"?>

+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">

+<plist version="1.1">

+    <dict>

+

+        <key>string</key>

+        <string>value1</string>

+

+        <key>integer</key>

+        <integer>12345</integer>

+

+        <key>real</key>

+        <real>-123.45E-1</real>

+

+        <key>boolean1</key>

+        <true/>

+

+        <key>boolean2</key>

+        <false/>

+

+        <key>date</key>

+        <date>2005-01-01T12:00:00-0700</date>

+

+        <key>data</key>

+        <data>RHJhY28gRG9ybWllbnMgTnVucXVhbSBUaXRpbGxhbmR1cw==</data>

+

+        <key>array</key>

+        <array>

+            <string>value1</string>

+            <string>value2</string>

+            <string>value3</string>

+        </array>

+

+        <key>nested-array</key>

+        <array>

+            <array>

+                <string>a</string>

+                <string>b</string>

+            </array>

+            <array>

+                <string>c</string>

+                <string>d</string>

+            </array>

+        </array>

+

+        <key>dictionary-array</key>

+        <array>

+            <dict>

+                <key>foo</key>

+                <string>bar</string>

+            </dict>

+            <dict>

+                <key>key</key>

+                <string>value</string>

+            </dict>

+        </array>

+

+        <key>dictionary</key>

+        <dict>

+            <key>key1</key>

+            <string>value1</string>

+            <key>key2</key>

+            <string>value2</string>

+            <key>key3</key>

+            <string>value3</string>

+        </dict>

+

+        <key>nested</key>

+        <dict>

+            <key>node1</key>

+            <dict>

+                <key>node2</key>

+                <dict>

+                    <key>node3</key>

+                    <string>value</string>

+                </dict>

+            </dict>

+        </dict>

+

+    </dict>

+</plist>


Modified: jakarta/commons/proper/configuration/trunk/maven.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/maven.xml?rev=227018&r1=227017&r2=227018&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/maven.xml (original)
+++ jakarta/commons/proper/configuration/trunk/maven.xml Tue Aug  2 07:43:20 2005
@@ -63,9 +63,30 @@
   -->
   <preGoal name="cactus:compile">
     <copy todir="${basedir}/src/test-cactus/org/apache/commons/configuration">
-        <fileset dir="${basedir}/src/test/" includes="**/NonStringTestHolder.java"/>
+      <fileset dir="${basedir}/src/test/" includes="**/NonStringTestHolder.java"/>
     </copy>
   </preGoal>
+
+  <!-- Remove the files generated previously by JavaCC -->
+  <preGoal name="javacc">
+    <delete>
+      <fileset dir="src/java/org/apache/commons/configuration/plist">
+        <include name="PropertyListParser*.*"/>
+        <include name="Token.java"/>
+        <include name="TokenMgrError.java"/>
+        <include name="SimpleCharStream.java"/>
+        <include name="ParseException.java"/>
+        <exclude name="*.jj"/>
+      </fileset>
+    </delete>
+  </preGoal>
+
+  <!-- Move the files generated by JavaCC to the source directory -->
+  <postGoal name="javacc">
+    <move todir="${basedir}/src/java/org/apache/commons/configuration/plist">
+      <fileset dir="target/generated-src/main/java/org/apache/commons/configuration"/>
+    </move>
+  </postGoal>
 </project>
 
 

Modified: jakarta/commons/proper/configuration/trunk/project.properties
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/project.properties?rev=227018&r1=227017&r2=227018&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/project.properties (original)
+++ jakarta/commons/proper/configuration/trunk/project.properties Tue Aug  2 07:43:20 2005
@@ -22,8 +22,9 @@
 
 maven.junit.fork=true
 maven.test.failure.ignore=false
+maven.test.skip=false
 
-maven.javadoc.links=http://java.sun.com/j2se/1.5/docs/api/, http://jakarta.apache.org/commons/collections/apidocs/, http://jakarta.apache.org/commons/digester/apidocs/, http://jakarta.apache.org/commons/lang/apidocs/, http://www.dom4j.org/apidocs/
+maven.javadoc.links=http://java.sun.com/j2se/1.5/docs/api/, http://java.sun.com/j2ee/1.4/docs/api/, http://jakarta.apache.org/commons/collections/apidocs/, http://jakarta.apache.org/commons/digester/apidocs/, http://jakarta.apache.org/commons/lang/apidocs/, http://www.dom4j.org/apidocs/
 
 #cactus settings.  Make sure to point to your Tomcat!
 cactus.home.tomcat4x = c:/java/tomcat
@@ -33,3 +34,7 @@
 maven.jar.resources=conf/resources.jar
 
 maven.compile.source = 1.3
+
+maven.clover.license.path=src/conf/clover.license
+
+maven.javacc.javacc.grammar=src/java/org/apache/commons/configuration/plist/PropertyListParser.jj

Modified: jakarta/commons/proper/configuration/trunk/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/project.xml?rev=227018&r1=227017&r2=227018&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/project.xml (original)
+++ jakarta/commons/proper/configuration/trunk/project.xml Tue Aug  2 07:43:20 2005
@@ -256,6 +256,15 @@
     </dependency>
 
     <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+      <version>1.3</version>
+      <properties>
+        <war.bundle>true</war.bundle>
+      </properties>
+    </dependency>
+
+    <dependency>
     <groupId>xerces</groupId>
       <artifactId>xerces</artifactId>
       <version>2.2.1</version>

Added: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractHierarchicalFileConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractHierarchicalFileConfiguration.java?rev=227018&view=auto
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractHierarchicalFileConfiguration.java (added)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractHierarchicalFileConfiguration.java Tue Aug  2 07:43:20 2005
@@ -0,0 +1,267 @@
+/*

+ * Copyright 2005 The Apache Software Foundation.

+ *

+ * Licensed under the Apache License, Version 2.0 (the "License")

+ * you may not use this file except in compliance with the License.

+ * You may obtain a copy of the License at

+ *

+ *     http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ */

+

+package org.apache.commons.configuration;

+

+import java.io.Reader;

+import java.io.Writer;

+import java.io.File;

+import java.io.InputStream;

+import java.io.OutputStream;

+import java.net.URL;

+

+import org.apache.commons.configuration.reloading.ReloadingStrategy;

+

+/**

+ * Base class for implementing file based hierarchical configurations.

+ *

+ * @since 1.2

+ *

+ * @author Emmanuel Bourg

+ * @version $Revision$, $Date$

+ */

+public abstract class AbstractHierarchicalFileConfiguration extends HierarchicalConfiguration implements FileConfiguration

+{

+    protected AbstractHierarchicalFileConfiguration.FileConfigurationDelegate delegate = new AbstractHierarchicalFileConfiguration.FileConfigurationDelegate();

+

+    protected class FileConfigurationDelegate extends AbstractFileConfiguration

+    {

+        public void load(Reader in) throws ConfigurationException

+        {

+            AbstractHierarchicalFileConfiguration.this.load(in);

+        }

+

+        public void save(Writer out) throws ConfigurationException

+        {

+            AbstractHierarchicalFileConfiguration.this.save(out);

+        }

+

+        public void clear()

+        {

+            AbstractHierarchicalFileConfiguration.this.clear();

+        }

+    }

+

+    protected AbstractHierarchicalFileConfiguration() { }

+

+    /**

+     * Creates and loads the configuration from the specified file.

+     *

+     * @param fileName The name of the plist file to load.

+     * @throws ConfigurationException Error while loading the file

+     */

+    public AbstractHierarchicalFileConfiguration(String fileName) throws ConfigurationException

+    {

+        // store the file name

+        delegate.setPath(fileName);

+

+        // load the file

+        load();

+    }

+

+    /**

+     * Creates and loads the configuration from the specified file.

+     *

+     * @param file The configuration file to load.

+     * @throws ConfigurationException Error while loading the file

+     */

+    public AbstractHierarchicalFileConfiguration(File file) throws ConfigurationException

+    {

+        // set the file and update the url, the base path and the file name

+        setFile(file);

+

+        // load the file

+        if (file.exists())

+        {

+            load();

+        }

+    }

+

+    /**

+     * Creates and loads the configuration from the specified URL.

+     *

+     * @param url The location of the configuration file to load.

+     * @throws ConfigurationException Error while loading the file

+     */

+    public AbstractHierarchicalFileConfiguration(URL url) throws ConfigurationException

+    {

+        // set the URL and update the base path and the file name

+        setURL(url);

+

+        // load the file

+        load();

+    }

+

+    protected void addPropertyDirect(String key, Object obj)

+    {

+        super.addPropertyDirect(key, obj);

+        delegate.possiblySave();

+    }

+

+    public void clearProperty(String key)

+    {

+        super.clearProperty(key);

+        delegate.possiblySave();

+    }

+

+    public void clearTree(String key)

+    {

+        super.clearTree(key);

+        delegate.possiblySave();

+    }

+

+    public void setProperty(String key, Object value)

+    {

+        super.setProperty(key, value);

+        delegate.possiblySave();

+    }

+

+    public void load() throws ConfigurationException

+    {

+        delegate.load();

+    }

+

+    public void load(String fileName) throws ConfigurationException

+    {

+        delegate.load(fileName);

+    }

+

+    public void load(File file) throws ConfigurationException

+    {

+        delegate.load(file);

+    }

+

+    public void load(URL url) throws ConfigurationException

+    {

+        delegate.load(url);

+    }

+

+    public void load(InputStream in) throws ConfigurationException

+    {

+        delegate.load(in);

+    }

+

+    public void load(InputStream in, String encoding) throws ConfigurationException

+    {

+        delegate.load(in, encoding);

+    }

+

+    public void save() throws ConfigurationException

+    {

+        delegate.save();

+    }

+

+    public void save(String fileName) throws ConfigurationException

+    {

+        delegate.save(fileName);

+    }

+

+    public void save(File file) throws ConfigurationException

+    {

+        delegate.save(file);

+    }

+

+    public void save(URL url) throws ConfigurationException

+    {

+        delegate.save(url);

+    }

+

+    public void save(OutputStream out) throws ConfigurationException

+    {

+        delegate.save(out);

+    }

+

+    public void save(OutputStream out, String encoding) throws ConfigurationException

+    {

+        delegate.save(out, encoding);

+    }

+

+    public String getFileName()

+    {

+        return delegate.getFileName();

+    }

+

+    public void setFileName(String fileName)

+    {

+        delegate.setFileName(fileName);

+    }

+

+    public String getBasePath()

+    {

+        return delegate.getBasePath();

+    }

+

+    public void setBasePath(String basePath)

+    {

+        delegate.setBasePath(basePath);

+    }

+

+    public File getFile()

+    {

+        return delegate.getFile();

+    }

+

+    public void setFile(File file)

+    {

+        delegate.setFile(file);

+    }

+

+    public URL getURL()

+    {

+        return delegate.getURL();

+    }

+

+    public void setURL(URL url)

+    {

+        delegate.setURL(url);

+    }

+

+    public void setAutoSave(boolean autoSave)

+    {

+        delegate.setAutoSave(autoSave);

+    }

+

+    public boolean isAutoSave()

+    {

+        return delegate.isAutoSave();

+    }

+

+    public ReloadingStrategy getReloadingStrategy()

+    {

+        return delegate.getReloadingStrategy();

+    }

+

+    public void setReloadingStrategy(ReloadingStrategy strategy)

+    {

+        delegate.setReloadingStrategy(strategy);

+    }

+

+    public void reload()

+    {

+        delegate.reload();

+    }

+

+    public String getEncoding()

+    {

+        return delegate.getEncoding();

+    }

+

+    public void setEncoding(String encoding)

+    {

+        delegate.setEncoding(encoding);

+    }

+

+}


Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationFactory.java?rev=227018&r1=227017&r2=227018&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationFactory.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationFactory.java Tue Aug  2 07:43:20 2005
@@ -25,6 +25,8 @@
 import java.util.LinkedList;
 import java.util.Stack;
 
+import org.apache.commons.configuration.plist.PropertyListConfiguration;
+import org.apache.commons.configuration.plist.XMLPropertyListConfiguration;
 import org.apache.commons.digester.AbstractObjectCreationFactory;
 import org.apache.commons.digester.Digester;
 import org.apache.commons.digester.ObjectCreationFactory;
@@ -286,6 +288,13 @@
 
         setupDigesterInstance(
             digester,
+            matchString + "plist",
+            new PropertyListConfigurationFactory(),
+            null,
+            additional);
+
+        setupDigesterInstance(
+            digester,
             matchString + "xml",
             new FileConfigurationFactory(XMLConfiguration.class),
             null,
@@ -545,6 +554,34 @@
             else
             {
                 return new PropertiesConfiguration();
+            }
+        }
+    }
+
+    /**
+     * A factory that returns an XMLPropertyListConfiguration for .xml files
+     * and a PropertyListConfiguration for the others.
+     *
+     * @since 1.2
+     */
+    public class PropertyListConfigurationFactory extends FileConfigurationFactory
+    {
+        public PropertyListConfigurationFactory()
+        {
+            super(null);
+        }
+
+        protected FileConfiguration createConfiguration(Attributes attributes) throws Exception
+        {
+            String filename = attributes.getValue(ATTR_FILENAME);
+
+            if (filename != null && filename.toLowerCase().trim().endsWith(".xml"))
+            {
+                return new XMLPropertyListConfiguration();
+            }
+            else
+            {
+                return new PropertyListConfiguration();
             }
         }
     }

Added: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/ParseException.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/ParseException.java?rev=227018&view=auto
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/ParseException.java (added)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/ParseException.java Tue Aug  2 07:43:20 2005
@@ -0,0 +1,192 @@
+/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */

+package org.apache.commons.configuration.plist;

+

+/**

+ * This exception is thrown when parse errors are encountered.

+ * You can explicitly create objects of this exception type by

+ * calling the method generateParseException in the generated

+ * parser.

+ *

+ * You can modify this class to customize your error reporting

+ * mechanisms so long as you retain the public fields.

+ */

+class ParseException extends Exception {

+

+  /**

+   * This constructor is used by the method "generateParseException"

+   * in the generated parser.  Calling this constructor generates

+   * a new object of this type with the fields "currentToken",

+   * "expectedTokenSequences", and "tokenImage" set.  The boolean

+   * flag "specialConstructor" is also set to true to indicate that

+   * this constructor was used to create this object.

+   * This constructor calls its super class with the empty string

+   * to force the "toString" method of parent class "Throwable" to

+   * print the error message in the form:

+   *     ParseException: <result of getMessage>

+   */

+  public ParseException(Token currentTokenVal,

+                        int[][] expectedTokenSequencesVal,

+                        String[] tokenImageVal

+                       )

+  {

+    super("");

+    specialConstructor = true;

+    currentToken = currentTokenVal;

+    expectedTokenSequences = expectedTokenSequencesVal;

+    tokenImage = tokenImageVal;

+  }

+

+  /**

+   * The following constructors are for use by you for whatever

+   * purpose you can think of.  Constructing the exception in this

+   * manner makes the exception behave in the normal way - i.e., as

+   * documented in the class "Throwable".  The fields "errorToken",

+   * "expectedTokenSequences", and "tokenImage" do not contain

+   * relevant information.  The JavaCC generated code does not use

+   * these constructors.

+   */

+

+  public ParseException() {

+    super();

+    specialConstructor = false;

+  }

+

+  public ParseException(String message) {

+    super(message);

+    specialConstructor = false;

+  }

+

+  /**

+   * This variable determines which constructor was used to create

+   * this object and thereby affects the semantics of the

+   * "getMessage" method (see below).

+   */

+  protected boolean specialConstructor;

+

+  /**

+   * This is the last token that has been consumed successfully.  If

+   * this object has been created due to a parse error, the token

+   * followng this token will (therefore) be the first error token.

+   */

+  public Token currentToken;

+

+  /**

+   * Each entry in this array is an array of integers.  Each array

+   * of integers represents a sequence of tokens (by their ordinal

+   * values) that is expected at this point of the parse.

+   */

+  public int[][] expectedTokenSequences;

+

+  /**

+   * This is a reference to the "tokenImage" array of the generated

+   * parser within which the parse error occurred.  This array is

+   * defined in the generated ...Constants interface.

+   */

+  public String[] tokenImage;

+

+  /**

+   * This method has the standard behavior when this object has been

+   * created using the standard constructors.  Otherwise, it uses

+   * "currentToken" and "expectedTokenSequences" to generate a parse

+   * error message and returns it.  If this object has been created

+   * due to a parse error, and you do not catch it (it gets thrown

+   * from the parser), then this method is called during the printing

+   * of the final stack trace, and hence the correct error message

+   * gets displayed.

+   */

+  public String getMessage() {

+    if (!specialConstructor) {

+      return super.getMessage();

+    }

+    String expected = "";

+    int maxSize = 0;

+    for (int i = 0; i < expectedTokenSequences.length; i++) {

+      if (maxSize < expectedTokenSequences[i].length) {

+        maxSize = expectedTokenSequences[i].length;

+      }

+      for (int j = 0; j < expectedTokenSequences[i].length; j++) {

+        expected += tokenImage[expectedTokenSequences[i][j]] + " ";

+      }

+      if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {

+        expected += "...";

+      }

+      expected += eol + "    ";

+    }

+    String retval = "Encountered \"";

+    Token tok = currentToken.next;

+    for (int i = 0; i < maxSize; i++) {

+      if (i != 0) retval += " ";

+      if (tok.kind == 0) {

+        retval += tokenImage[0];

+        break;

+      }

+      retval += add_escapes(tok.image);

+      tok = tok.next;

+    }

+    retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;

+    retval += "." + eol;

+    if (expectedTokenSequences.length == 1) {

+      retval += "Was expecting:" + eol + "    ";

+    } else {

+      retval += "Was expecting one of:" + eol + "    ";

+    }

+    retval += expected;

+    return retval;

+  }

+

+  /**

+   * The end of line string for this machine.

+   */

+  protected String eol = System.getProperty("line.separator", "\n");

+

+  /**

+   * Used to convert raw characters to their escaped version

+   * when these raw version cannot be used as part of an ASCII

+   * string literal.

+   */

+  protected String add_escapes(String str) {

+      StringBuffer retval = new StringBuffer();

+      char ch;

+      for (int i = 0; i < str.length(); i++) {

+        switch (str.charAt(i))

+        {

+           case 0 :

+              continue;

+           case '\b':

+              retval.append("\\b");

+              continue;

+           case '\t':

+              retval.append("\\t");

+              continue;

+           case '\n':

+              retval.append("\\n");

+              continue;

+           case '\f':

+              retval.append("\\f");

+              continue;

+           case '\r':

+              retval.append("\\r");

+              continue;

+           case '\"':

+              retval.append("\\\"");

+              continue;

+           case '\'':

+              retval.append("\\\'");

+              continue;

+           case '\\':

+              retval.append("\\\\");

+              continue;

+           default:

+              if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {

+                 String s = "0000" + Integer.toString(ch, 16);

+                 retval.append("\\u" + s.substring(s.length() - 4, s.length()));

+              } else {

+                 retval.append(ch);

+              }

+              continue;

+        }

+      }

+      return retval.toString();

+   }

+

+}


Added: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java?rev=227018&view=auto
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java (added)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java Tue Aug  2 07:43:20 2005
@@ -0,0 +1,310 @@
+/*

+ * Copyright 2005 The Apache Software Foundation.

+ *

+ * Licensed under the Apache License, Version 2.0 (the "License")

+ * you may not use this file except in compliance with the License.

+ * You may obtain a copy of the License at

+ *

+ *     http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ */

+

+package org.apache.commons.configuration.plist;

+

+import java.io.File;

+import java.io.PrintWriter;

+import java.io.Reader;

+import java.io.Writer;

+import java.net.URL;

+import java.util.ArrayList;

+import java.util.Iterator;

+import java.util.List;

+import java.util.Map;

+

+import org.apache.commons.codec.binary.Hex;

+import org.apache.commons.configuration.AbstractHierarchicalFileConfiguration;

+import org.apache.commons.configuration.Configuration;

+import org.apache.commons.configuration.ConfigurationException;

+import org.apache.commons.configuration.HierarchicalConfiguration;

+import org.apache.commons.configuration.MapConfiguration;

+import org.apache.commons.lang.StringUtils;

+

+/**

+ * NeXT / OpenStep style configuration.

+ * (http://developer.apple.com/documentation/Cocoa/Conceptual/PropertyLists/Concepts/OldStylePListsConcept.html)

+ *

+ * <p>Example:</p>

+ * <pre>

+ * {

+ *     foo = "bar";

+ *

+ *     array = ( value1, value2, value3 );

+ *

+ *     data = <4f3e0145ab>;

+ *

+ *     nested =

+ *     {

+ *         key1 = value1;

+ *         key2 = value;

+ *         nested =

+ *         {

+ *             foo = bar

+ *         }

+ *     }

+ * }

+ * </pre>

+ *

+ * @since 1.2

+ *

+ * @author Emmanuel Bourg

+ * @version $Revision$, $Date$

+ */

+public class PropertyListConfiguration extends AbstractHierarchicalFileConfiguration

+{

+    private static final int INDENT_SIZE = 4;

+

+    /**

+     * Creates an empty PropertyListConfiguration object which can be

+     * used to synthesize a new plist file by adding values and

+     * then saving().

+     */

+    public PropertyListConfiguration() { }

+

+    /**

+     * Creates and loads the property list from the specified file.

+     *

+     * @param fileName The name of the plist file to load.

+     * @throws ConfigurationException Error while loading the plist file

+     */

+    public PropertyListConfiguration(String fileName) throws ConfigurationException

+    {

+        super(fileName);

+    }

+

+    /**

+     * Creates and loads the property list from the specified file.

+     *

+     * @param file The plist file to load.

+     * @throws ConfigurationException Error while loading the plist file

+     */

+    public PropertyListConfiguration(File file) throws ConfigurationException

+    {

+        super(file);

+    }

+

+    /**

+     * Creates and loads the property list from the specified URL.

+     *

+     * @param url The location of the plist file to load.

+     * @throws ConfigurationException Error while loading the plist file

+     */

+    public PropertyListConfiguration(URL url) throws ConfigurationException

+    {

+        super(url);

+    }

+

+    public void load(Reader in) throws ConfigurationException

+    {

+        PropertyListParser parser = new PropertyListParser(in);

+        try

+        {

+

+            HierarchicalConfiguration config = parser.parse();

+            setRoot(config.getRoot());

+        }

+        catch (ParseException e)

+        {

+            throw new ConfigurationException(e);

+        }

+    }

+

+    public void save(Writer out) throws ConfigurationException

+    {

+        PrintWriter writer = new PrintWriter(out);

+        printNode(writer, 0, getRoot());

+        writer.flush();

+    }

+

+    /**

+     * Append a node to the writer, indented according to a specific level.

+     */

+    private void printNode(PrintWriter out, int indentLevel, Node node)

+    {

+        String padding = StringUtils.repeat(" ", indentLevel * INDENT_SIZE);

+

+        if (node.getName() != null)

+        {

+            out.print(padding + quoteString(node.getName()) + " = ");

+        }

+

+        // get all non trivial nodes

+        List children = new ArrayList(node.getChildren());

+        Iterator it = children.iterator();

+        while (it.hasNext())

+        {

+            Node child = (Node) it.next();

+            if (child.getValue() == null && (child.getChildren() == null || child.getChildren().isEmpty()))

+            {

+                it.remove();

+            }

+        }

+

+        if (!children.isEmpty())

+        {

+            // skip a line, except for the root dictionary

+            if (indentLevel > 0)

+            {

+                out.println();

+            }

+

+            out.println(padding + "{");

+

+            // display the children

+            it = children.iterator();

+            while (it.hasNext())

+            {

+                Node child = (Node) it.next();

+

+                printNode(out, indentLevel + 1, child);

+

+                // add a semi colon for elements that are not dictionaries

+                if (child.getValue() != null)

+                {

+                    out.println(";");

+                }

+

+                // skip a line after arrays and dictionaries

+                if (it.hasNext() && (child.getValue() == null || child.getValue() instanceof List))

+                {

+                    out.println();

+                }

+            }

+

+            out.print(padding + "}");

+

+            // line feed if the dictionary is not in an array

+            if (node.getParent() != null)

+            {

+                out.println();

+            }

+        }

+        else

+        {

+            // display the leaf value

+            Object value = node.getValue();

+            printValue(out, indentLevel, value);

+        }

+    }

+

+    /**

+     * Append a value to the writer, indented according to a specific level.

+     */

+    private void printValue(PrintWriter out, int indentLevel, Object value)

+    {

+        String padding = StringUtils.repeat(" ", indentLevel * INDENT_SIZE);

+

+        if (value instanceof List)

+        {

+            out.print("( ");

+            Iterator it = ((List) value).iterator();

+            while (it.hasNext())

+            {

+                printValue(out, indentLevel + 1, it.next());

+                if (it.hasNext())

+                {

+                    out.print(", ");

+                }

+            }

+            out.print(" )");

+        }

+        else if (value instanceof HierarchicalConfiguration)

+        {

+            printNode(out, indentLevel, ((HierarchicalConfiguration) value).getRoot());

+        }

+        else if (value instanceof Configuration)

+        {

+            // display a flat Configuration as a dictionary

+            out.println(padding + "{");

+

+            Configuration config = (Configuration) value;

+            Iterator it = config.getKeys();

+            while (it.hasNext())

+            {

+                String key = (String) it.next();

+                Node node = new Node(key);

+                node.setValue(config.getProperty(key));

+

+                printNode(out, indentLevel + 1, node);

+

+                if (it.hasNext())

+                {

+                    out.println();

+                }

+            }

+            out.println(padding + "}");

+        }

+        else if (value instanceof Map)

+        {

+            // display a Map as a dictionary

+            Map map = (Map) value;

+            printValue(out, indentLevel, new MapConfiguration(map));

+        }

+        else if (value instanceof byte[])

+        {

+            out.print("<" + new String(Hex.encodeHex((byte[]) value)) + ">");

+        }

+        else if (value != null)

+        {

+            out.print(quoteString(String.valueOf(value)));

+        }

+    }

+

+    /**

+     * Quote the specified string if necessary, that's if the string contains:

+     * <ul>

+     *   <li>a space character (' ', '\t', '\r', '\n')</li>

+     *   <li>a quote '"'</li>

+     *   <li>special characters in plist files ('(', ')', '{', '}', '=', ';', ',')</li>

+     * </ul>

+     * Quotes within the string are escaped.

+     *

+     * <p>Examples:</p>

+     * <ul>

+     *   <li>abcd -> abcd</li>

+     *   <li>ab cd -> "ab cd"</li>

+     *   <li>foo"bar -> "foo\"bar"</li>

+     *   <li>foo;bar -> "foo;bar"</li>

+     * </ul>

+     */

+    private String quoteString(String s)

+    {

+        if (s == null)

+        {

+            return null;

+        }

+

+        if (s.indexOf(' ') != -1

+                || s.indexOf('\t') != -1

+                || s.indexOf('\r') != -1

+                || s.indexOf('\n') != -1

+                || s.indexOf('"') != -1

+                || s.indexOf('(') != -1

+                || s.indexOf(')') != -1

+                || s.indexOf('{') != -1

+                || s.indexOf('}') != -1

+                || s.indexOf('=') != -1

+                || s.indexOf(',') != -1

+                || s.indexOf(';') != -1)

+        {

+            s = StringUtils.replace(s, "\"", "\\\"");

+            s = "\"" + s + "\"";

+        }

+

+        return s;

+    }

+}


Added: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.java?rev=227018&view=auto
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.java (added)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.java Tue Aug  2 07:43:20 2005
@@ -0,0 +1,461 @@
+/* Generated By:JavaCC: Do not edit this line. PropertyListParser.java */

+package org.apache.commons.configuration.plist;

+

+import java.util.List;

+import java.util.ArrayList;

+

+import org.apache.commons.configuration.HierarchicalConfiguration;

+import org.apache.commons.configuration.HierarchicalConfiguration.Node;

+

+import org.apache.commons.lang.StringUtils;

+import org.apache.commons.codec.binary.Hex;

+

+/**

+ * JavaCC based parser for the PropertyList format.

+ *

+ * @author Emmanuel Bourg

+ * @version $Revision$, $Date$

+ */

+class PropertyListParser implements PropertyListParserConstants

+{

+

+    /**

+     * Remove the quotes at the beginning and at the end of the specified String.

+     */

+    private String removeQuotes(String s)

+    {

+        if (s == null)

+        {

+            return null;

+        }

+

+        if (s.startsWith("\"") && s.endsWith("\"") && s.length() >= 2)

+        {

+            s = s.substring(1, s.length() - 1);

+        }

+

+        return s;

+    }

+

+    private String unescapeQuotes(String s)

+    {

+        return StringUtils.replace(s, "\\\"", "\"");

+    }

+

+    /**

+     * Remove the white spaces and the data delimiters from the specified

+     * string and parse it as a byte array.

+     */

+    private byte[] filterData(String s) throws ParseException

+    {

+        if (s == null)

+        {

+            return null;

+        }

+

+        // remove the delimiters

+        if (s.startsWith("<") && s.endsWith(">") && s.length() >= 2)

+        {

+            s = s.substring(1, s.length() - 1);

+        }

+

+        // remove the white spaces

+        s = StringUtils.replaceChars(s, " \t\n\r", "");

+

+        // add a leading 0 to ensure well formed bytes

+        if (s.length() % 2 != 0)

+        {

+            s = "0" + s;

+        }

+

+        // parse and return the bytes

+        try

+        {

+            return Hex.decodeHex(s.toCharArray());

+        }

+        catch (Exception e)

+        {

+            throw new ParseException(e.getMessage());

+        }

+    }

+

+    final public PropertyListConfiguration parse() throws ParseException

+    {

+        PropertyListConfiguration configuration = null;

+        configuration = Dictionary();

+        jj_consume_token(0);

+        {

+            if (true) return configuration;

+        }

+        throw new Error("Missing return statement in function");

+    }

+

+    final public PropertyListConfiguration Dictionary() throws ParseException

+    {

+        PropertyListConfiguration configuration = new PropertyListConfiguration();

+        List children = new ArrayList();

+        Node child = null;

+        jj_consume_token(DICT_BEGIN);

+        label_1:

+        while (true)

+        {

+            switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)

+            {

+                case STRING:

+                case QUOTED_STRING:

+                    ;

+                    break;

+                default:

+                    jj_la1[0] = jj_gen;

+                    break label_1;

+            }

+            child = Property();

+            if (child.getValue() instanceof HierarchicalConfiguration)

+            {

+                // prune & graft the nested configuration to the parent configuration

+                HierarchicalConfiguration conf = (HierarchicalConfiguration) child.getValue();

+                Node root = conf.getRoot();

+                root.setName(child.getName());

+                children.add(root);

+            }

+            else

+            {

+                children.add(child);

+            }

+        }

+        jj_consume_token(DICT_END);

+        for (int i = 0; i < children.size(); i++)

+        {

+            child = (Node) children.get(i);

+            configuration.getRoot().addChild(child);

+        }

+

+        {

+            if (true) return configuration;

+        }

+        throw new Error("Missing return statement in function");

+    }

+

+    final public Node Property() throws ParseException

+    {

+        String key = null;

+        Object value = null;

+        Node node = new Node();

+        key = String();

+        node.setName(key);

+        jj_consume_token(EQUAL);

+        value = Element();

+        node.setValue(value);

+        switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)

+        {

+            case DICT_SEPARATOR:

+                jj_consume_token(DICT_SEPARATOR);

+                break;

+            default:

+                jj_la1[1] = jj_gen;

+                ;

+        }

+        {

+            if (true) return node;

+        }

+        throw new Error("Missing return statement in function");

+    }

+

+    final public Object Element() throws ParseException

+    {

+        Object value = null;

+        switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)

+        {

+            case ARRAY_BEGIN:

+                value = Array();

+                {

+                    if (true) return value;

+                }

+                break;

+            case DICT_BEGIN:

+                value = Dictionary();

+                {

+                    if (true) return value;

+                }

+                break;

+            case STRING:

+            case QUOTED_STRING:

+                value = String();

+                {

+                    if (true) return value;

+                }

+                break;

+            case DATA:

+                value = Data();

+                {

+                    if (true) return value;

+                }

+                break;

+            default:

+                jj_la1[2] = jj_gen;

+                jj_consume_token(-1);

+                throw new ParseException();

+        }

+        throw new Error("Missing return statement in function");

+    }

+

+    final public List Array() throws ParseException

+    {

+        List list = new ArrayList();

+        Object element = null;

+        jj_consume_token(ARRAY_BEGIN);

+        switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)

+        {

+            case ARRAY_BEGIN:

+            case DICT_BEGIN:

+            case DATA:

+            case STRING:

+            case QUOTED_STRING:

+                element = Element();

+                list.add(element);

+                label_2:

+                while (true)

+                {

+                    switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)

+                    {

+                        case ARRAY_SEPARATOR:

+                            ;

+                            break;

+                        default:

+                            jj_la1[3] = jj_gen;

+                            break label_2;

+                    }

+                    jj_consume_token(ARRAY_SEPARATOR);

+                    element = Element();

+                    list.add(element);

+                }

+                break;

+            default:

+                jj_la1[4] = jj_gen;

+                ;

+        }

+        jj_consume_token(ARRAY_END);

+        {

+            if (true) return list;

+        }

+        throw new Error("Missing return statement in function");

+    }

+

+    final public String String() throws ParseException

+    {

+        Token token = null;

+        String value = null;

+        switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)

+        {

+            case QUOTED_STRING:

+                token = jj_consume_token(QUOTED_STRING);

+                {

+                    if (true) return unescapeQuotes(removeQuotes(token.image));

+                }

+                break;

+            case STRING:

+                token = jj_consume_token(STRING);

+                {

+                    if (true) return token.image;

+                }

+                break;

+            default:

+                jj_la1[5] = jj_gen;

+                jj_consume_token(-1);

+                throw new ParseException();

+        }

+        throw new Error("Missing return statement in function");

+    }

+

+    final public byte[] Data() throws ParseException

+    {

+        Token token;

+        token = jj_consume_token(DATA);

+        {

+            if (true) return filterData(token.image);

+        }

+        throw new Error("Missing return statement in function");

+    }

+

+    public PropertyListParserTokenManager token_source;

+    SimpleCharStream jj_input_stream;

+    public Token token, jj_nt;

+    private int jj_ntk;

+    private int jj_gen;

+    final private int[] jj_la1 = new int[6];

+    static private int[] jj_la1_0;

+

+    static

+    {

+        jj_la1_0();

+    }

+

+    private static void jj_la1_0()

+    {

+        jj_la1_0 = new int[]{0x180000, 0x400, 0x1c0120, 0x80, 0x1c0120, 0x180000, };

+    }

+

+    public PropertyListParser(java.io.InputStream stream)

+    {

+        jj_input_stream = new SimpleCharStream(stream, 1, 1);

+        token_source = new PropertyListParserTokenManager(jj_input_stream);

+        token = new Token();

+        jj_ntk = -1;

+        jj_gen = 0;

+        for (int i = 0; i < 6; i++) jj_la1[i] = -1;

+    }

+

+    public void ReInit(java.io.InputStream stream)

+    {

+        jj_input_stream.ReInit(stream, 1, 1);

+        token_source.ReInit(jj_input_stream);

+        token = new Token();

+        jj_ntk = -1;

+        jj_gen = 0;

+        for (int i = 0; i < 6; i++) jj_la1[i] = -1;

+    }

+

+    public PropertyListParser(java.io.Reader stream)

+    {

+        jj_input_stream = new SimpleCharStream(stream, 1, 1);

+        token_source = new PropertyListParserTokenManager(jj_input_stream);

+        token = new Token();

+        jj_ntk = -1;

+        jj_gen = 0;

+        for (int i = 0; i < 6; i++) jj_la1[i] = -1;

+    }

+

+    public void ReInit(java.io.Reader stream)

+    {

+        jj_input_stream.ReInit(stream, 1, 1);

+        token_source.ReInit(jj_input_stream);

+        token = new Token();

+        jj_ntk = -1;

+        jj_gen = 0;

+        for (int i = 0; i < 6; i++) jj_la1[i] = -1;

+    }

+

+    public PropertyListParser(PropertyListParserTokenManager tm)

+    {

+        token_source = tm;

+        token = new Token();

+        jj_ntk = -1;

+        jj_gen = 0;

+        for (int i = 0; i < 6; i++) jj_la1[i] = -1;

+    }

+

+    public void ReInit(PropertyListParserTokenManager tm)

+    {

+        token_source = tm;

+        token = new Token();

+        jj_ntk = -1;

+        jj_gen = 0;

+        for (int i = 0; i < 6; i++) jj_la1[i] = -1;

+    }

+

+    final private Token jj_consume_token(int kind) throws ParseException

+    {

+        Token oldToken;

+        if ((oldToken = token).next != null)

+            token = token.next;

+        else

+            token = token.next = token_source.getNextToken();

+        jj_ntk = -1;

+        if (token.kind == kind)

+        {

+            jj_gen++;

+            return token;

+        }

+        token = oldToken;

+        jj_kind = kind;

+        throw generateParseException();

+    }

+

+    final public Token getNextToken()

+    {

+        if (token.next != null)

+            token = token.next;

+        else

+            token = token.next = token_source.getNextToken();

+        jj_ntk = -1;

+        jj_gen++;

+        return token;

+    }

+

+    final public Token getToken(int index)

+    {

+        Token t = token;

+        for (int i = 0; i < index; i++)

+        {

+            if (t.next != null)

+                t = t.next;

+            else

+                t = t.next = token_source.getNextToken();

+        }

+        return t;

+    }

+

+    final private int jj_ntk()

+    {

+        if ((jj_nt = token.next) == null)

+            return (jj_ntk = (token.next = token_source.getNextToken()).kind);

+        else

+            return (jj_ntk = jj_nt.kind);

+    }

+

+    private java.util.Vector jj_expentries = new java.util.Vector();

+    private int[] jj_expentry;

+    private int jj_kind = -1;

+

+    public ParseException generateParseException()

+    {

+        jj_expentries.removeAllElements();

+        boolean[] la1tokens = new boolean[22];

+        for (int i = 0; i < 22; i++)

+        {

+            la1tokens[i] = false;

+        }

+        if (jj_kind >= 0)

+        {

+            la1tokens[jj_kind] = true;

+            jj_kind = -1;

+        }

+        for (int i = 0; i < 6; i++)

+        {

+            if (jj_la1[i] == jj_gen)

+            {

+                for (int j = 0; j < 32; j++)

+                {

+                    if ((jj_la1_0[i] & (1 << j)) != 0)

+                    {

+                        la1tokens[j] = true;

+                    }

+                }

+            }

+        }

+        for (int i = 0; i < 22; i++)

+        {

+            if (la1tokens[i])

+            {

+                jj_expentry = new int[1];

+                jj_expentry[0] = i;

+                jj_expentries.addElement(jj_expentry);

+            }

+        }

+        int[][] exptokseq = new int[jj_expentries.size()][];

+        for (int i = 0; i < jj_expentries.size(); i++)

+        {

+            exptokseq[i] = (int[]) jj_expentries.elementAt(i);

+        }

+        return new ParseException(token, exptokseq, tokenImage);

+    }

+

+    final public void enable_tracing()

+    {

+    }

+

+    final public void disable_tracing()

+    {

+    }

+

+}


Added: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.jj
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.jj?rev=227018&view=auto
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.jj (added)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.jj Tue Aug  2 07:43:20 2005
@@ -0,0 +1,255 @@
+/*

+ * Copyright 2005 The Apache Software Foundation.

+ *

+ * Licensed under the Apache License, Version 2.0 (the "License")

+ * you may not use this file except in compliance with the License.

+ * You may obtain a copy of the License at

+ *

+ *     http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ */

+

+options {

+    STATIC = false;

+}

+

+

+PARSER_BEGIN(PropertyListParser)

+

+package org.apache.commons.configuration.plist;

+

+import java.util.List;

+import java.util.ArrayList;

+

+import org.apache.commons.configuration.HierarchicalConfiguration;

+import org.apache.commons.configuration.HierarchicalConfiguration.Node;

+

+import org.apache.commons.lang.StringUtils;

+import org.apache.commons.codec.binary.Hex;

+

+/**

+ * JavaCC based parser for the PropertyList format.

+ *

+ * @author Emmanuel Bourg

+ * @version $Revision$, $Date$

+ */

+class PropertyListParser {

+

+    /**

+     * Remove the quotes at the beginning and at the end of the specified String.

+     */

+    private String removeQuotes(String s)

+    {

+        if (s == null)

+        {

+            return null;

+        }

+

+        if (s.startsWith("\"") && s.endsWith("\"") && s.length() >= 2)

+        {

+            s = s.substring(1, s.length() - 1);

+        }

+

+        return s;

+    }

+

+    private String unescapeQuotes(String s)

+    {

+        return StringUtils.replace(s, "\\\"", "\"");

+    }

+

+    /**

+     * Remove the white spaces and the data delimiters from the specified

+     * string and parse it as a byte array.

+     */

+    private byte[] filterData(String s) throws ParseException

+    {

+        if (s == null)

+        {

+            return null;

+        }

+

+        // remove the delimiters

+        if (s.startsWith("<") && s.endsWith(">") && s.length() >= 2)

+        {

+            s = s.substring(1, s.length() - 1);

+        }

+

+        // remove the white spaces

+        s = StringUtils.replaceChars(s, " \t\n\r", "");

+

+        // add a leading 0 to ensure well formed bytes

+        if (s.length() % 2 != 0)

+        {

+            s = "0" + s;

+        }

+

+        // parse and return the bytes

+        try

+        {

+            return Hex.decodeHex(s.toCharArray());

+        }

+        catch (Exception e)

+        {

+            throw new ParseException(e.getMessage());

+        }

+    }

+

+}

+

+PARSER_END(PropertyListParser)

+

+SKIP : { " " | "\t" | "\n" | "\r" }

+

+TOKEN : { <ARRAY_BEGIN     : "(" > }

+TOKEN : { <ARRAY_END       : ")" > }

+TOKEN : { <ARRAY_SEPARATOR : "," > }

+

+TOKEN : { <DICT_BEGIN     : "{" > }

+TOKEN : { <DICT_END       : "}" > }

+TOKEN : { <DICT_SEPARATOR : ";" > }

+TOKEN : { <EQUAL : "=" > }

+

+TOKEN : { <DATA_START : "<" > }

+TOKEN : { <DATA_END : ">" > }

+

+TOKEN : { < QUOTE : "\"" > }

+TOKEN : { < #LETTER : ~[" ", "\t", "\n", "\r", "(", ")", ",", "{", "}", ";", "=", "\""] > }

+TOKEN : { < #WHITE : " " | "\t" | "\n" | "\r" > }

+TOKEN : { < #HEXA : ["0"-"9", "a"-"f", "A"-"F"] > }

+TOKEN : { < DATA : <DATA_START> (<HEXA> | <WHITE>)* <DATA_END> > }

+TOKEN : { < STRING :  (<LETTER>)+ > }

+TOKEN : { < QUOTED_STRING :

+            <QUOTE>

+            (<LETTER> | <WHITE> | <ESCAPED_QUOTE> | <EQUAL>

+            | <ARRAY_BEGIN> | <ARRAY_END> | <ARRAY_SEPARATOR>

+            | <DICT_BEGIN> | <DICT_END> | <DICT_SEPARATOR>)* <QUOTE> > }

+TOKEN : { < ESCAPED_QUOTE : "\\\"" > }

+

+PropertyListConfiguration parse() :

+{

+    PropertyListConfiguration configuration = null;

+}

+{

+    configuration = Dictionary()

+    <EOF>

+    { return configuration; }

+}

+

+PropertyListConfiguration Dictionary() :

+{

+    PropertyListConfiguration configuration = new PropertyListConfiguration();

+    List children = new ArrayList();

+    Node child = null;

+}

+{

+    <DICT_BEGIN>

+    (

+        child = Property()

+        {

+            if (child.getValue() instanceof HierarchicalConfiguration)

+            {

+                // prune & graft the nested configuration to the parent configuration

+                HierarchicalConfiguration conf = (HierarchicalConfiguration) child.getValue();

+                Node root = conf.getRoot();

+                root.setName(child.getName());

+                children.add(root);

+            }

+            else

+            {

+                children.add(child);

+            }

+        }

+    )*

+    <DICT_END>

+    {

+        for (int i = 0; i < children.size(); i++)

+        {

+            child = (Node) children.get(i);

+            configuration.getRoot().addChild(child);

+        }

+

+        return configuration;

+    }

+}

+

+Node Property() :

+{

+    String key = null;

+    Object value = null;

+    Node node = new Node();

+}

+{

+    key = String()

+    { node.setName(key); }

+    <EQUAL>

+    value = Element()

+    { node.setValue(value); }

+    (<DICT_SEPARATOR>)?

+    { return node; }

+}

+

+Object Element() :

+{

+    Object value = null;

+}

+{

+    value = Array()

+    { return value; }

+    |

+    value = Dictionary()

+    { return value; }

+    |

+    value = String()

+    { return value; }

+    |

+    value = Data()

+    { return value; }

+}

+

+List Array() :

+{

+    List list = new ArrayList();

+    Object element = null;

+}

+{

+    <A
Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r227018 [1/2] - in /jakarta/commons/proper/configuration/trunk: ./ conf/ src/java/org/apache/commons/configuration/ src/java/org/apache/commons/configuration/plist/ src/test/org/apache/commons/configuration/plist/ xdocs/

Oliver Heger-2
The test case TestPropertyListConfiguration.testSave() fails for me in
line 195 for the value of the 'dictionary-array' property. I assume
ListAssert.assertEquals() is not able to compare two
PropertyListConfiguration objects in the passed in lists.

Could you please check this?

Oliver

[hidden email] wrote:

>Author: ebourg
>Date: Tue Aug  2 07:43:20 2005
>New Revision: 227018
>
>URL: http://svn.apache.org/viewcvs?rev=227018&view=rev
>Log:
>New configurations implementing the "property list" formats used in NeXT, OpenStep and Mac OS X
>
>Added:
>    jakarta/commons/proper/configuration/trunk/conf/PropertyList-1.0.dtd
>    jakarta/commons/proper/configuration/trunk/conf/test.plist
>    jakarta/commons/proper/configuration/trunk/conf/test.plist.xml
>    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractHierarchicalFileConfiguration.java
>    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/
>    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/ParseException.java
>    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
>    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.java
>    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.jj
>    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParserConstants.java
>    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParserTokenManager.java
>    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/SimpleCharStream.java
>    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/Token.java
>    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/TokenMgrError.java
>    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
>    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/
>    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java
>    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java
>Modified:
>    jakarta/commons/proper/configuration/trunk/maven.xml
>    jakarta/commons/proper/configuration/trunk/project.properties
>    jakarta/commons/proper/configuration/trunk/project.xml
>    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationFactory.java
>    jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
>
>Added: jakarta/commons/proper/configuration/trunk/conf/PropertyList-1.0.dtd
>  
>
<snip/>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r227018 [1/2] - in /jakarta/commons/proper/configuration/trunk: ./ conf/ src/java/org/apache/commons/configuration/ src/java/org/apache/commons/configuration/plist/ src/test/org/apache/commons/configuration/plist/ xdocs/

Emmanuel Bourg-2
Oliver Heger a �crit :

> The test case TestPropertyListConfiguration.testSave() fails for me in
> line 195 for the value of the 'dictionary-array' property. I assume
> ListAssert.assertEquals() is not able to compare two
> PropertyListConfiguration objects in the passed in lists.
>
> Could you please check this?

Sorry the commit was incomplete, this test assumes the configuration
defines its equals() methods. I added an equals() method in
AbstractConfiguration delegating to
StrictConfigurationComparator.compare() but I'm not sure it's worth
committing this. What do you think ? I'll fix the test if we rule out
this suggestion.

Emmanuel Bourg

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r227018 [1/2] - in /jakarta/commons/proper/configuration/trunk: ./ conf/ src/java/org/apache/commons/configuration/ src/java/org/apache/commons/configuration/plist/ src/test/org/apache/commons/configuration/plist/ xdocs/

Oliver Heger-2
Emmanuel Bourg wrote:

> Oliver Heger a �crit :
>
>> The test case TestPropertyListConfiguration.testSave() fails for me
>> in line 195 for the value of the 'dictionary-array' property. I
>> assume ListAssert.assertEquals() is not able to compare two
>> PropertyListConfiguration objects in the passed in lists.
>>
>> Could you please check this?
>
>
> Sorry the commit was incomplete, this test assumes the configuration
> defines its equals() methods. I added an equals() method in
> AbstractConfiguration delegating to
> StrictConfigurationComparator.compare() but I'm not sure it's worth
> committing this. What do you think ? I'll fix the test if we rule out
> this suggestion.
>
> Emmanuel Bourg

I am not too convinced about the value of an equals() method either.
Comparing two Configuration objects does not seem to be such a common
task. And if it is needed, the comparator class can be used directly. If
there was an equals() method, how would you implement hashCode()?

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r227018 [1/2] - in /jakarta/commons/proper/configuration/trunk: ./ conf/ src/java/org/apache/commons/configuration/ src/java/org/apache/commons/configuration/plist/ src/test/org/apache/commons/configuration/plist/ xdocs/

Oliver Heger-2
In reply to this post by Emmanuel Bourg-2
Emmanuel Bourg wrote:

> Oliver Heger a �crit :
>
>> The test case TestPropertyListConfiguration.testSave() fails for me
>> in line 195 for the value of the 'dictionary-array' property. I
>> assume ListAssert.assertEquals() is not able to compare two
>> PropertyListConfiguration objects in the passed in lists.
>>
>> Could you please check this?
>
>
> Sorry the commit was incomplete, this test assumes the configuration
> defines its equals() methods. I added an equals() method in
> AbstractConfiguration delegating to
> StrictConfigurationComparator.compare() but I'm not sure it's worth
> committing this. What do you think ? I'll fix the test if we rule out
> this suggestion.
>
> Emmanuel Bourg
>
I temporarily disabled the failing tests (by renaming the test methods)
to make the nightly builds run again. If you find the time, you can come
up with an appropriate solution.

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[configuration] Implementing equals & hashCode in AbstractConfiguration

Emmanuel Bourg-3
In reply to this post by Oliver Heger-2
Oliver Heger wrote:

>> Sorry the commit was incomplete, this test assumes the configuration
>> defines its equals() methods. I added an equals() method in
>> AbstractConfiguration delegating to
>> StrictConfigurationComparator.compare() but I'm not sure it's worth
>> committing this. What do you think ? I'll fix the test if we rule out
>> this suggestion.
>>
>> Emmanuel Bourg
>
> I am not too convinced about the value of an equals() method either.
> Comparing two Configuration objects does not seem to be such a common
> task. And if it is needed, the comparator class can be used directly. If
> there was an equals() method, how would you implement hashCode()?

hashCode() could be implemented as the sum of the hashCodes of the keys,
or as the number of properties in the configuration.

Emmanuel Bourg

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]