commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r526941 - in /jakarta/commons/proper/configuration/trunk: pom.xml project.xml src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java xdocs/changes.xml xdocs/dependencies.xml xdocs/index.xml
Date Mon, 09 Apr 2007 22:44:02 GMT
Author: ebourg
Date: Mon Apr  9 15:43:59 2007
New Revision: 526941

URL: http://svn.apache.org/viewvc?view=rev&rev=526941
Log:
Implemented the load() method of XMLPropertyListConfiguration in pure SAX, thus dropping the
dependency on Digester and BeanUtils for this class
Added the INIConfiguration on the main page
Updated my personal info

Modified:
    jakarta/commons/proper/configuration/trunk/pom.xml
    jakarta/commons/proper/configuration/trunk/project.xml
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
    jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
    jakarta/commons/proper/configuration/trunk/xdocs/dependencies.xml
    jakarta/commons/proper/configuration/trunk/xdocs/index.xml

Modified: jakarta/commons/proper/configuration/trunk/pom.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/pom.xml?view=diff&rev=526941&r1=526940&r2=526941
==============================================================================
--- jakarta/commons/proper/configuration/trunk/pom.xml (original)
+++ jakarta/commons/proper/configuration/trunk/pom.xml Mon Apr  9 15:43:59 2007
@@ -127,7 +127,9 @@
         <developer>
           <name>Emmanuel Bourg</name>
           <id>ebourg</id>
-          <email>smanux@lfjr.net</email>
+          <email>ebourg@apache.org</email>
+          <organization>Ariane Software</organization>
+          <timezone>+1</timezone>
           <roles>
             <role>Java Developer</role>
           </roles>
@@ -180,7 +182,7 @@
         <contributor>
           <name>Nicolas De Loof</name>
           <email>nicolas.deloof@gmail.com</email>
-          <organization>capgemini</organization>
+          <organization>Cap Gemini</organization>
         </contributor>
     </contributors>
 

Modified: jakarta/commons/proper/configuration/trunk/project.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/project.xml?view=diff&rev=526941&r1=526940&r2=526941
==============================================================================
--- jakarta/commons/proper/configuration/trunk/project.xml (original)
+++ jakarta/commons/proper/configuration/trunk/project.xml Mon Apr  9 15:43:59 2007
@@ -171,7 +171,9 @@
     <developer>
       <name>Emmanuel Bourg</name>
       <id>ebourg</id>
-      <email>smanux@lfjr.net</email>
+      <email>ebourg@apache.org</email>
+      <organization>Ariane Software</organization>
+      <timezone>+1</timezone>
     </developer>
 	
     <developer>
@@ -220,7 +222,7 @@
     <contributor>
       <name>Nicolas De Loof</name>
       <email>nicolas.deloof@gmail.com</email>
-      <organization>capgemini</organization>
+      <organization>Cap Gemini</organization>
     </contributor>
 
   </contributors>

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java?view=diff&rev=526941&r1=526940&r2=526941
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
Mon Apr  9 15:43:59 2007
@@ -32,6 +32,8 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
 
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.configuration.AbstractHierarchicalFileConfiguration;
@@ -39,15 +41,14 @@
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.configuration.MapConfiguration;
-import org.apache.commons.digester.AbstractObjectCreationFactory;
-import org.apache.commons.digester.Digester;
-import org.apache.commons.digester.ObjectCreateRule;
-import org.apache.commons.digester.SetNextRule;
 import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.commons.lang.StringUtils;
+
 import org.xml.sax.Attributes;
 import org.xml.sax.EntityResolver;
 import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
 
 /**
  * Mac OS X configuration file (http://www.apple.com/DTDs/PropertyList-1.0.dtd).
@@ -137,12 +138,12 @@
      * Creates a new instance of <code>XMLPropertyListConfiguration</code> and
      * copies the content of the specified configuration into this object.
      *
-     * @param c the configuration to copy
+     * @param configuration the configuration to copy
      * @since 1.4
      */
-    public XMLPropertyListConfiguration(HierarchicalConfiguration c)
+    public XMLPropertyListConfiguration(HierarchicalConfiguration configuration)
     {
-        super(c);
+        super(configuration);
     }
 
     /**
@@ -181,85 +182,26 @@
 
     public void load(Reader in) throws ConfigurationException
     {
-        // set up the digester
-        Digester digester = new Digester();
-
         // set up the DTD validation
-        digester.setEntityResolver(new EntityResolver()
+        EntityResolver resolver = new EntityResolver()
         {
             public InputSource resolveEntity(String publicId, String systemId)
             {
                 return new InputSource(getClass().getClassLoader().getResourceAsStream("PropertyList-1.0.dtd"));
             }
-        });
-        digester.setValidating(true);
-
-        // dictionary rules
-        digester.addRule("*/key", new ObjectCreateRule(PListNode.class)
-        {
-            public void end() throws Exception
-            {
-                // leave the node on the stack to set the value
-            }
-        });
-
-        digester.addCallMethod("*/key", "setName", 0);
-
-        digester.addRule("*/dict/string", new SetNextAndPopRule("addChild"));
-        digester.addRule("*/dict/data", new SetNextAndPopRule("addChild"));
-        digester.addRule("*/dict/integer", new SetNextAndPopRule("addChild"));
-        digester.addRule("*/dict/real", new SetNextAndPopRule("addChild"));
-        digester.addRule("*/dict/true", new SetNextAndPopRule("addChild"));
-        digester.addRule("*/dict/false", new SetNextAndPopRule("addChild"));
-        digester.addRule("*/dict/date", new SetNextAndPopRule("addChild"));
-        digester.addRule("*/dict/dict", new SetNextAndPopRule("addChild"));
-
-        digester.addCallMethod("*/dict/string", "addValue", 0);
-        digester.addCallMethod("*/dict/data", "addDataValue", 0);
-        digester.addCallMethod("*/dict/integer", "addIntegerValue", 0);
-        digester.addCallMethod("*/dict/real", "addRealValue", 0);
-        digester.addCallMethod("*/dict/true", "addTrueValue");
-        digester.addCallMethod("*/dict/false", "addFalseValue");
-        digester.addCallMethod("*/dict/date", "addDateValue", 0);
-
-        // rules for arrays
-        digester.addRule("*/dict/array", new SetNextAndPopRule("addChild"));
-        digester.addRule("*/dict/array", new ObjectCreateRule(ArrayNode.class));
-        digester.addSetNext("*/dict/array", "addList");
-
-        digester.addRule("*/array/array", new ObjectCreateRule(ArrayNode.class));
-        digester.addSetNext("*/array/array", "addList");
-
-        digester.addCallMethod("*/array/string", "addValue", 0);
-        digester.addCallMethod("*/array/data", "addDataValue", 0);
-        digester.addCallMethod("*/array/integer", "addIntegerValue", 0);
-        digester.addCallMethod("*/array/real", "addRealValue", 0);
-        digester.addCallMethod("*/array/true", "addTrueValue");
-        digester.addCallMethod("*/array/false", "addFalseValue");
-        digester.addCallMethod("*/array/date", "addDateValue", 0);
-
-        // rule for a dictionary in an array
-        digester.addFactoryCreate("*/array/dict", new AbstractObjectCreationFactory()
-        {
-            public Object createObject(Attributes attributes) throws Exception
-            {
-                // create the configuration
-                XMLPropertyListConfiguration config = new XMLPropertyListConfiguration();
-
-                // add it to the ArrayNode
-                ArrayNode node = (ArrayNode) getDigester().peek();
-                node.addValue(config);
-
-                // push the root on the stack
-                return config.getRoot();
-            }
-        });
+        };
 
         // parse the file
-        digester.push(getRoot());
+        XMLPropertyListHandler handler = new XMLPropertyListHandler(getRoot());
         try
         {
-            digester.parse(in);
+            SAXParserFactory factory = SAXParserFactory.newInstance();
+            factory.setValidating(true);
+
+            SAXParser parser = factory.newSAXParser();
+            parser.getXMLReader().setEntityResolver(resolver);
+            parser.getXMLReader().setContentHandler(handler);
+            parser.getXMLReader().parse(new InputSource(in));
         }
         catch (Exception e)
         {
@@ -267,25 +209,6 @@
         }
     }
 
-    /**
-     * Digester rule that sets the object on the stack to the n-1 object
-     * and remove both of them from the stack. This rule is used to remove
-     * the configuration node from the stack once its value has been parsed.
-     */
-    private class SetNextAndPopRule extends SetNextRule
-    {
-        public SetNextAndPopRule(String methodName)
-        {
-            super(methodName);
-        }
-
-        public void end(String namespace, String name) throws Exception
-        {
-            super.end(namespace, name);
-            digester.pop();
-        }
-    }
-
     public void save(Writer out) throws ConfigurationException
     {
         PrintWriter writer = new PrintWriter(out);
@@ -438,6 +361,148 @@
         }
     }
 
+    /**
+     * SAX Handler to build the configuration nodes while the document is being parsed.
+     */
+    private class XMLPropertyListHandler extends DefaultHandler
+    {
+        private StringBuffer buffer = new StringBuffer();
+
+        private List stack = new ArrayList();
+
+        public XMLPropertyListHandler(Node root)
+        {
+            push(root);
+        }
+
+        /**
+         * Return the node on the top of the stack.
+         */
+        private Node peek()
+        {
+            if (!stack.isEmpty())
+            {
+                return (Node) stack.get(stack.size() - 1);
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        /**
+         * Remove and return the node on the top of the stack.
+         */
+        private Node pop()
+        {
+            if (!stack.isEmpty())
+            {
+                return (Node) stack.remove(stack.size() - 1);
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        /**
+         * Put a node on the top of the stack.
+         */
+        private void push(Node node)
+        {
+            stack.add(node);
+        }
+
+        public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException
+        {
+            if ("array".equals(qName))
+            {
+                push(new ArrayNode());
+            }
+            else if ("dict".equals(qName))
+            {
+                if (peek() instanceof ArrayNode)
+                {
+                    // create the configuration
+                    XMLPropertyListConfiguration config = new XMLPropertyListConfiguration();
+
+                    // add it to the ArrayNode
+                    ArrayNode node = (ArrayNode) peek();
+                    node.addValue(config);
+
+                    // push the root on the stack
+                    push(config.getRoot());
+                }
+            }
+        }
+
+        public void endElement(String uri, String localName, String qName) throws SAXException
+        {
+            if ("key".equals(qName))
+            {
+                // create a new node, link it to its parent and push it on the stack
+                PListNode node = new PListNode();
+                node.setName(buffer.toString());
+                peek().addChild(node);
+                push(node);
+            }
+            else if ("dict".equals(qName))
+            {
+                // remove the root of the XMLPropertyListConfiguration previously pushed
on the stack
+                pop();
+            }
+            else
+            {
+                if ("string".equals(qName))
+                {
+                    ((PListNode) peek()).addValue(buffer.toString());
+                }
+                else if ("integer".equals(qName))
+                {
+                    ((PListNode) peek()).addIntegerValue(buffer.toString());
+                }
+                else if ("real".equals(qName))
+                {
+                    ((PListNode) peek()).addRealValue(buffer.toString());
+                }
+                else if ("true".equals(qName))
+                {
+                    ((PListNode) peek()).addTrueValue();
+                }
+                else if ("false".equals(qName))
+                {
+                    ((PListNode) peek()).addFalseValue();
+                }
+                else if ("data".equals(qName))
+                {
+                    ((PListNode) peek()).addDataValue(buffer.toString());
+                }
+                else if ("date".equals(qName))
+                {
+                    ((PListNode) peek()).addDateValue(buffer.toString());
+                }
+                else if ("array".equals(qName))
+                {
+                    ArrayNode array = (ArrayNode) pop();
+                    ((PListNode) peek()).addList(array);
+                }
+
+                // remove the plist node on the stack once the value has been parsed,
+                // array nodes remains on the stack for the next values in the list
+                if (!(peek() instanceof ArrayNode))
+                {
+                    pop();
+                }
+            }
+
+            buffer.setLength(0);
+        }
+
+        public void characters(char ch[], int start, int length) throws SAXException
+        {
+            buffer.append(ch, start, length);
+        }
+    }
 
     /**
      * Node extension with addXXX methods to parse the typed data passed by Digester.

Modified: jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/xdocs/changes.xml?view=diff&rev=526941&r1=526940&r2=526941
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Mon Apr  9 15:43:59 2007
@@ -24,6 +24,10 @@
   <body>
     <release version="1.5-SNAPSHOT" date="in SVN">
       <action dev="ebourg" type="update">
+        XMLPropertyListConfiguration no longer requires commons-digester and
+        commons-beanutils to work.
+      </action>
+      <action dev="ebourg" type="update">
         Fixed INIConfiguration to handle the quoted values and the lines
         containing a value and a comment.
       </action>

Modified: jakarta/commons/proper/configuration/trunk/xdocs/dependencies.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/xdocs/dependencies.xml?view=diff&rev=526941&r1=526940&r2=526941
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/dependencies.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/dependencies.xml Mon Apr  9 15:43:59
2007
@@ -58,14 +58,14 @@
                         <td>
                             commons-digester<br/>
                             commons-beanutils<br/>
-                            JDK 1.4 or xml-apis
+                            Java 1.4 or xml-apis
                         </td>
                     </tr>
                     <tr>
                         <td>DefaultConfigurationBuilder</td>
                         <td>
                             commons-beanutils<br/>
-                            JDK 1.4 or (xml-apis + xerces + xalan)
+                            Java 1.4 or (xml-apis + xerces + xalan)
                         </td>
                     </tr>
                     <tr>
@@ -87,10 +87,8 @@
                     <tr>
                         <td>XMLPropertyListConfiguration</td>
                         <td>
-                            commons-digester<br/>
-                            commons-beanutils<br/>
                             commons-codec<br/>
-                            JDK 1.4 or xml-apis
+                            Java 1.4 or xml-apis
                         </td>
                     </tr>
                     <tr>
@@ -155,7 +153,7 @@
                 </table>
                 </li>
                 <li>
-                  In JDK versions before 1.4 XML support is not integrated. To
+                  In Java versions before 1.4 XML support is not integrated. To
                   make use of components that require XML processing you need
                   to add a suitable replacement. We used 
                   <a href="http://xml.apache.org/xerces2-j/">Xerces 2.2.1</a>,

Modified: jakarta/commons/proper/configuration/trunk/xdocs/index.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/xdocs/index.xml?view=diff&rev=526941&r1=526940&r2=526941
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/index.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/index.xml Mon Apr  9 15:43:59 2007
@@ -46,6 +46,7 @@
         <ul>
           <li>Properties files</li>
           <li>XML documents</li>
+          <li>Windows INI files</li>
           <li>Property list files (.plist)</li>
           <li>JNDI</li>
           <li>JDBC Datasource</li>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message