Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 77043 invoked from network); 9 Apr 2007 22:44:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 9 Apr 2007 22:44:27 -0000 Received: (qmail 68638 invoked by uid 500); 9 Apr 2007 22:44:32 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 68173 invoked by uid 500); 9 Apr 2007 22:44:30 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 68158 invoked by uid 500); 9 Apr 2007 22:44:30 -0000 Received: (qmail 68155 invoked by uid 99); 9 Apr 2007 22:44:30 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Apr 2007 15:44:30 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Apr 2007 15:44:23 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 1088F1A9838; Mon, 9 Apr 2007 15:44:03 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commons-cvs@jakarta.apache.org From: ebourg@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070409224403.1088F1A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ Emmanuel Bourg ebourg - smanux@lfjr.net + ebourg@apache.org + Ariane Software + +1 Java Developer @@ -180,7 +182,7 @@ Nicolas De Loof nicolas.deloof@gmail.com - capgemini + Cap Gemini 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 @@ Emmanuel Bourg ebourg - smanux@lfjr.net + ebourg@apache.org + Ariane Software + +1 @@ -220,7 +222,7 @@ Nicolas De Loof nicolas.deloof@gmail.com - capgemini + Cap Gemini 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 XMLPropertyListConfiguration 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 @@ + XMLPropertyListConfiguration no longer requires commons-digester and + commons-beanutils to work. + + Fixed INIConfiguration to handle the quoted values and the lines containing a value and a comment. 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 @@ commons-digester
commons-beanutils
- JDK 1.4 or xml-apis + Java 1.4 or xml-apis DefaultConfigurationBuilder commons-beanutils
- JDK 1.4 or (xml-apis + xerces + xalan) + Java 1.4 or (xml-apis + xerces + xalan) @@ -87,10 +87,8 @@ XMLPropertyListConfiguration - commons-digester
- commons-beanutils
commons-codec
- JDK 1.4 or xml-apis + Java 1.4 or xml-apis @@ -155,7 +153,7 @@
  • - 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 Xerces 2.2.1, 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 @@
    • Properties files
    • XML documents
    • +
    • Windows INI files
    • Property list files (.plist)
    • JNDI
    • JDBC Datasource
    • --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org