You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ra...@apache.org on 2008/12/23 21:04:45 UTC

svn commit: r729082 - in /commons/proper/digester/trunk: ./ src/java/org/apache/commons/digester/ src/java/org/apache/commons/digester/parser/ src/test/org/apache/commons/digester/

Author: rahul
Date: Tue Dec 23 12:04:44 2008
New Revision: 729082

URL: http://svn.apache.org/viewvc?rev=729082&view=rev
Log:
Add javax.xml.validation.Schema support to Digester class:
 - New 'schema' field for Digester class (protected -- matching digester style)
    o Sort imports and update class Javadoc
 - Deprecate legacy schema support, including:
    o schemaLanguage and schemaLocation fields and their getters and setters in Digester class
    o ParserFeatureSetterFactory class whose main purpose was legacy schema support
    o Parsers in org.apache.commons.digester.parser package used by ParserFeatureSetterFactory
 - Added new test cases that demonstrate javax.xml.validation.Schema validation
 - Updated release notes, package Javadoc

Added:
    commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13-01.xml   (with props)
    commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13-02.xml   (with props)
    commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13.xsd   (with props)
    commons/proper/digester/trunk/src/test/org/apache/commons/digester/XMLSchemaTestCase.java   (with props)
Modified:
    commons/proper/digester/trunk/RELEASE-NOTES.txt
    commons/proper/digester/trunk/pom.xml
    commons/proper/digester/trunk/src/java/org/apache/commons/digester/Digester.java
    commons/proper/digester/trunk/src/java/org/apache/commons/digester/ParserFeatureSetterFactory.java
    commons/proper/digester/trunk/src/java/org/apache/commons/digester/parser/GenericParser.java
    commons/proper/digester/trunk/src/java/org/apache/commons/digester/parser/XercesParser.java
    commons/proper/digester/trunk/src/java/org/apache/commons/digester/parser/package.html

Modified: commons/proper/digester/trunk/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/RELEASE-NOTES.txt?rev=729082&r1=729081&r2=729082&view=diff
==============================================================================
--- commons/proper/digester/trunk/RELEASE-NOTES.txt (original)
+++ commons/proper/digester/trunk/RELEASE-NOTES.txt Tue Dec 23 12:04:44 2008
@@ -16,12 +16,19 @@
 in detail before choosing to upgrade. There is no urgency for existing
 projects to upgrade; Digester 1.8 has proven to be a stable release.
 
-IMPORTANT NOTES (BREAKING CHANGES)
-===================================
+IMPORTANT NOTES
+================
+
+BREAKING CHANGES:
 
  * The minimum JDK requirement is now JDK 1.5. The provided binaries will not
    work on lower JDKs. The source requires JDK 1.5 to compile.
 
+OTHER CHANGES:
+
+ * The legacy schema support has been deprecated in favor of
+   javax.xml.validation.Schema support.
+
 Dependencies
 =============
 
@@ -36,7 +43,15 @@
 NEW FEATURES
 =============
 
- * XInclude awareness
+ * XML SCHEMA SUPPORT
+       Support for XML Schema validation using javax.xml.validation.Schema
+       has been added to Digester. See Digester class Javadoc, and
+       Digester#setSchema(javax.xml.validation.Schema) method.
+       This allows usage of W3C XML Schema, Relax NG and Schematron for
+       validation of XML documents.
+       The legacy schema support has been deprecated (details below).
+
+ * XINCLUDE AWARENESS
        The underlying SAXParser factory can now be easily configured to be
        XInclude aware. This allows for general purpose inclusion of XML or
        text documents, for example, and facilitates document modularity. For
@@ -60,5 +75,28 @@
 DEPRECATIONS
 ============
 
-None.
+ * org.apache.commons.digester.Digester#schemaLanguage and
+   org.apache.commons.digester.Digester#schemaLocation
+
+    Use org.apache.commons.digester.Digester#schema instead.
+
+ * org.apache.commons.digester.Digester#getSchemaLanguage(),
+   org.apache.commons.digester.Digester#setSchemaLanguage(String),
+   org.apache.commons.digester.Digester#getSchemaLocation(), and
+   org.apache.commons.digester.Digester#setSchemaLocation(String)
+
+    Use org.apache.commons.digester.Digester#getSchema() and
+    org.apache.commons.digester.Digester#setSchema(javax.xml.validation.Schema)
+    instead.
+
+ * org.apache.commons.digester.ParserFeatureSetterFactory
+
+    Switch to javax.xml.validation.Schema validation via Digester class
+    instead.
+
+ * org.apache.commons.digester.parsers package; classes
+   org.apache.commons.digester.parsers.GenericParser and
+   org.apache.commons.digester.parsers.XercesParser
 
+    Switch to javax.xml.validation.Schema validation via Digester class
+    instead.

Modified: commons/proper/digester/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/pom.xml?rev=729082&r1=729081&r2=729082&view=diff
==============================================================================
--- commons/proper/digester/trunk/pom.xml (original)
+++ commons/proper/digester/trunk/pom.xml Tue Dec 23 12:04:44 2008
@@ -211,6 +211,7 @@
         <filtering>false</filtering>
         <includes>
           <include>**/*.xml</include>
+          <include>**/*.xsd</include>
         </includes>
       </testResource>
     </testResources>

Modified: commons/proper/digester/trunk/src/java/org/apache/commons/digester/Digester.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/java/org/apache/commons/digester/Digester.java?rev=729082&r1=729081&r2=729082&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/java/org/apache/commons/digester/Digester.java (original)
+++ commons/proper/digester/trunk/src/java/org/apache/commons/digester/Digester.java Tue Dec 23 12:04:44 2008
@@ -25,9 +25,9 @@
 import java.io.InputStream;
 import java.io.Reader;
 import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
-import java.net.MalformedURLException;
 import java.util.ArrayList;
 import java.util.EmptyStackException;
 import java.util.HashMap;
@@ -39,11 +39,11 @@
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
+import javax.xml.validation.Schema;
 
+import org.apache.commons.collections.ArrayStack;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.commons.collections.ArrayStack;
-
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.EntityResolver;
@@ -63,9 +63,7 @@
 /**
  * <p>A <strong>Digester</strong> processes an XML input stream by matching a
  * series of element nesting patterns to execute Rules that have been added
- * prior to the start of parsing.  This package was inspired by the
- * <code>XmlMapper</code> class that was part of Tomcat 3.0 and 3.1,
- * but is organized somewhat differently.</p>
+ * prior to the start of parsing.</p>
  *
  * <p>See the <a href="package-summary.html#package_description">Digester
  * Developer Guide</a> for more information.</p>
@@ -86,9 +84,13 @@
  * call it if the Digester parse terminates due to an exception during a parse.
  * </p>
  *
- * <p><strong>IMPLEMENTATION NOTE</strong> - A bug in Xerces 2.0.2 prevents
- * the support of XML schema. You need Xerces 2.1/2.3 and up to make
- * this class working with XML schema</p>
+ * <p><strong>LEGACY IMPLEMENTATION NOTE</strong> - When using the legacy XML
+ * schema support (instead of using the {@link Schema} class), a bug in
+ * Xerces 2.0.2 prevents the support of XML schema. You need Xerces 2.1/2.3
+ * and up to make this class work with the legacy XML schema support.</p>
+ *
+ * <p>This package was inspired by the <code>XmlMapper</code> class that was
+ * part of Tomcat 3.0 and 3.1, but is organized somewhat differently.</p>
  */
 
 public class Digester extends DefaultHandler {
@@ -290,17 +292,27 @@
    /**
      * The XML schema language to use for validating an XML instance. By
      * default this value is set to <code>W3C_XML_SCHEMA</code>
+     *
+     * @deprecated Use {@link Schema} support instead.
      */
     protected String schemaLanguage = W3C_XML_SCHEMA;
     
         
     /**
      * The XML schema to use for validating an XML instance.
+     *
+     * @deprecated Use {@link Schema} support instead.
      */
     protected String schemaLocation = null;
     
     
     /**
+     * The XML schema to use for validating an XML instance.
+     */
+    protected Schema schema = null;
+
+
+    /**
      * The object stack being constructed.
      */
     protected ArrayStack stack = new ArrayStack();
@@ -518,6 +530,7 @@
             factory.setNamespaceAware(namespaceAware);
             factory.setXIncludeAware(xincludeAware);
             factory.setValidating(validating);
+            factory.setSchema(schema);
         }
         return (factory);
 
@@ -746,6 +759,10 @@
                 // we have to use parser-specific code for this. That code
                 // is hidden behind the ParserFeatureSetterFactory class.
 
+            	// The above has changed in JDK 1.5 and no longer true. The
+            	// functionality used in this block has now been deprecated.
+            	// We now use javax.xml.validation.Schema instead.
+
                 Properties properties = new Properties();
                 properties.put("SAXParserFactory", getFactory());
                 if (schemaLocation != null) {
@@ -865,6 +882,9 @@
 
     /**
      * Return the XML Schema URI used for validating an XML instance.
+     *
+     * @deprecated Use {@link Schema} for validation instead. 
+     * @see {@link #getXMLSchema()} and {@link #setXMLSchema(Schema)}
      */
     public String getSchema() {
 
@@ -901,6 +921,8 @@
      * parameter to the Digester constructor.
      *
      * @param schemaLocation a URI to the schema.
+     * @deprecated Use {@link Schema} for validation instead. 
+     * @see {@link #getXMLSchema()} and {@link #setXMLSchema(Schema)}
      */
     public void setSchema(String schemaLocation){
 
@@ -911,6 +933,9 @@
 
     /**
      * Return the XML Schema language used when parsing.
+     *
+     * @deprecated Use {@link Schema} for validation instead. 
+     * @see {@link #getXMLSchema()} and {@link #setXMLSchema(Schema)}
      */
     public String getSchemaLanguage() {
 
@@ -923,12 +948,38 @@
      * Set the XML Schema language used when parsing. By default, we use W3C.
      *
      * @param schemaLanguage a URI to the schema language.
+     * @deprecated Use {@link Schema} for validation instead. 
+     * @see {@link #getXMLSchema()} and {@link #setXMLSchema(Schema)}
      */
     public void setSchemaLanguage(String schemaLanguage){
 
         this.schemaLanguage = schemaLanguage;
 
     }   
+    
+
+    /**
+     * Return the XML Schema used when parsing.
+     *
+     * @return The {@link Schema} instance in use.
+     */
+    public Schema getXMLSchema() {
+
+        return (this.schema);
+
+    }
+
+
+    /**
+     * Set the XML Schema to be used when parsing.
+     *
+     * @param schema The {@link Schema} instance to use.
+     */
+    public void setXMLSchema(Schema schema){
+
+        this.schema = schema;
+
+    }
 
 
     /**

Modified: commons/proper/digester/trunk/src/java/org/apache/commons/digester/ParserFeatureSetterFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/java/org/apache/commons/digester/ParserFeatureSetterFactory.java?rev=729082&r1=729081&r2=729082&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/java/org/apache/commons/digester/ParserFeatureSetterFactory.java (original)
+++ commons/proper/digester/trunk/src/java/org/apache/commons/digester/ParserFeatureSetterFactory.java Tue Dec 23 12:04:44 2008
@@ -24,6 +24,7 @@
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
+import javax.xml.validation.Schema;
 
 import org.apache.commons.digester.parser.GenericParser;
 import org.apache.commons.digester.parser.XercesParser;
@@ -38,6 +39,10 @@
  * to be set.
  *
  * @since 1.6
+ * @deprecated Create an XMLParser instance yourself, configure validation
+ *             appropriately, and pass it as a parameter to the
+ *             {@link Digester} constructor, or use
+ *             {@link Digester#setXMLSchema(Schema)} for validation.
  */
 public class ParserFeatureSetterFactory {
 

Modified: commons/proper/digester/trunk/src/java/org/apache/commons/digester/parser/GenericParser.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/java/org/apache/commons/digester/parser/GenericParser.java?rev=729082&r1=729081&r2=729082&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/java/org/apache/commons/digester/parser/GenericParser.java (original)
+++ commons/proper/digester/trunk/src/java/org/apache/commons/digester/parser/GenericParser.java Tue Dec 23 12:04:44 2008
@@ -24,7 +24,9 @@
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
+import javax.xml.validation.Schema;
 
+import org.apache.commons.digester.Digester;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.xml.sax.SAXException;
@@ -34,6 +36,10 @@
  * Create a <code>SAXParser</code> configured to support XML Schema and DTD.
  *
  * @since 1.6
+ * @deprecated Create an XMLParser instance yourself, configure validation
+ *             appropriately, and pass it as a parameter to the
+ *             {@link Digester} constructor, or use
+ *             {@link Digester#setXMLSchema(Schema)} for validation.
  */
 
 public class GenericParser{

Modified: commons/proper/digester/trunk/src/java/org/apache/commons/digester/parser/XercesParser.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/java/org/apache/commons/digester/parser/XercesParser.java?rev=729082&r1=729081&r2=729082&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/java/org/apache/commons/digester/parser/XercesParser.java (original)
+++ commons/proper/digester/trunk/src/java/org/apache/commons/digester/parser/XercesParser.java Tue Dec 23 12:04:44 2008
@@ -25,7 +25,9 @@
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
+import javax.xml.validation.Schema;
 
+import org.apache.commons.digester.Digester;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.xml.sax.SAXException;
@@ -39,6 +41,10 @@
  * parser, some features/properties need to be set.
  *
  * @since 1.6
+ * @deprecated Create an XMLParser instance yourself, configure validation
+ *             appropriately, and pass it as a parameter to the
+ *             {@link Digester} constructor, or use
+ *             {@link Digester#setXMLSchema(Schema)} for validation.
  */
 
 public class XercesParser{

Modified: commons/proper/digester/trunk/src/java/org/apache/commons/digester/parser/package.html
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/java/org/apache/commons/digester/parser/package.html?rev=729082&r1=729081&r2=729082&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/java/org/apache/commons/digester/parser/package.html (original)
+++ commons/proper/digester/trunk/src/java/org/apache/commons/digester/parser/package.html Tue Dec 23 12:04:44 2008
@@ -20,6 +20,12 @@
 <title>Package Documentation for org.apache.commons.digester.parser Package</title>
 </head>
 <body bgcolor="white">
+<p>
+<b>DEPRECATED PACKAGE:</b><br>
+This package contains legacy schema support code used in the v1.x line of
+Digester releases. Starting v2.0, the recommended way to use schema
+validation is via the <code>javax.xml.validation.Schema</code> support.
+</p>
 Provides for parser recognition and parser dependent code.
 <br><br>
 <p>

Added: commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13-01.xml
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13-01.xml?rev=729082&view=auto
==============================================================================
--- commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13-01.xml (added)
+++ commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13-01.xml Tue Dec 23 12:04:44 2008
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+
+<employee xmlns="http://commons.apache.org/digester/tests">
+  <firstName>First Name</firstName>
+  <lastName>Last Name</lastName>
+  <address>
+    <type>home</type>
+    <city>Home City</city>
+    <state>HS</state>
+  </address>
+</employee>

Propchange: commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13-01.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13-01.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13-02.xml
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13-02.xml?rev=729082&view=auto
==============================================================================
--- commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13-02.xml (added)
+++ commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13-02.xml Tue Dec 23 12:04:44 2008
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+
+<employee xmlns="http://commons.apache.org/digester/tests">
+  <firstName badattribute="true">First Name</firstName>
+  <badelement/>
+  <lastName>Last Name</lastName>
+  <address>
+    <type>home</type>
+    <city>Home City</city>
+    <state>HS</state>
+  </address>
+</employee>

Propchange: commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13-02.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13-02.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13.xsd
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13.xsd?rev=729082&view=auto
==============================================================================
--- commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13.xsd (added)
+++ commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13.xsd Tue Dec 23 12:04:44 2008
@@ -0,0 +1,53 @@
+<?xml version="1.0"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+    xmlns:dt="http://commons.apache.org/digester/tests"
+    targetNamespace="http://commons.apache.org/digester/tests"
+    elementFormDefault="qualified">
+
+    <xsd:complexType name="dt.employee.type">
+        <xsd:sequence>
+            <xsd:element ref="dt:firstName" minOccurs="1" maxOccurs="1" />
+            <xsd:element ref="dt:lastName" minOccurs="1" maxOccurs="1" />
+            <xsd:element ref="dt:address" minOccurs="0" maxOccurs="unbounded" />
+        </xsd:sequence>
+    </xsd:complexType>
+
+    <xsd:element name="employee" type="dt:dt.employee.type" />
+
+    <xsd:element name="firstName" type="xsd:string" />
+    <xsd:element name="lastName" type="xsd:string" />
+
+    <xsd:complexType name="dt.address.type">
+        <xsd:sequence>
+            <xsd:element ref="dt:type" minOccurs="1" maxOccurs="1" />
+            <xsd:element ref="dt:city" minOccurs="1" maxOccurs="1" />
+            <xsd:element ref="dt:state" minOccurs="1" maxOccurs="1" />
+        </xsd:sequence>
+    </xsd:complexType>
+
+    <xsd:element name="address" type="dt:dt.address.type" />
+
+    <xsd:element name="type" type="xsd:string" />
+    <xsd:element name="city" type="xsd:string" />
+    <xsd:element name="state" type="xsd:string" />
+
+</xsd:schema>
+

Propchange: commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13.xsd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test13.xsd
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/digester/trunk/src/test/org/apache/commons/digester/XMLSchemaTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/test/org/apache/commons/digester/XMLSchemaTestCase.java?rev=729082&view=auto
==============================================================================
--- commons/proper/digester/trunk/src/test/org/apache/commons/digester/XMLSchemaTestCase.java (added)
+++ commons/proper/digester/trunk/src/test/org/apache/commons/digester/XMLSchemaTestCase.java Tue Dec 23 12:04:44 2008
@@ -0,0 +1,193 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.digester;
+
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.XMLConstants;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+
+/**
+ * <p>Tests for XInclude aware parsing.</p>
+ *
+ */
+public class XMLSchemaTestCase extends TestCase {
+
+
+    // ----------------------------------------------------- Instance Variables
+
+
+    /**
+     * The digester instance we will be processing.
+     */
+    protected Digester digester = null;
+
+
+    // ----------------------------------------------------------- Constructors
+
+
+    /**
+     * Construct a new instance of this test case.
+     *
+     * @param name Name of the test case
+     */
+    public XMLSchemaTestCase(String name) {
+
+        super(name);
+
+    }
+
+
+    // --------------------------------------------------- Overall Test Methods
+
+
+    /**
+     * Set up instance variables required by this test case.
+     */
+    public void setUp() throws SAXException {
+
+        digester = new Digester();
+
+        // Use the test schema
+    	digester.setNamespaceAware(true);
+    	Schema test13schema = SchemaFactory.
+    	    newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).
+    	    newSchema(this.getClass().getClassLoader().
+    	        getResource("org/apache/commons/digester/Test13.xsd"));
+    	digester.setXMLSchema(test13schema);
+
+    	// Configure the digester as required
+        digester.addObjectCreate("employee", Employee.class);
+        digester.addCallMethod("employee/firstName", "setFirstName", 0);
+        digester.addCallMethod("employee/lastName", "setLastName", 0);
+
+        digester.addObjectCreate("employee/address", Address.class);
+        digester.addCallMethod("employee/address/type", "setType", 0);
+        digester.addCallMethod("employee/address/city", "setCity", 0);
+        digester.addCallMethod("employee/address/state", "setState", 0);
+        digester.addSetNext("employee/address", "addAddress");
+
+    }
+
+
+    /**
+     * Return the tests included in this test suite.
+     */
+    public static Test suite() {
+
+        return (new TestSuite(XMLSchemaTestCase.class));
+
+    }
+
+
+    /**
+     * Tear down instance variables required by this test case.
+     */
+    public void tearDown() {
+
+        digester = null;
+
+    }
+
+
+
+    // ------------------------------------------------ Individual Test Methods
+
+
+    /**
+     * Test XML Schema validation.
+     */
+    public void testGoodDocument() throws SAXException, IOException {
+
+    	// Listen to validation errors
+    	TestErrorHandler teh = new TestErrorHandler();
+    	digester.setErrorHandler(teh);
+
+        // Parse our test input
+        Employee employee = (Employee) digester.parse(getInputStream("Test13-01.xml"));
+        assertNotNull("failed to parsed an employee", employee);
+        assertTrue("Test13-01 should not generate errors in Schema validation", teh.clean);
+
+        // Test document has been processed
+        Address ha = employee.getAddress("home");
+        assertNotNull(ha);
+        assertEquals("Home City", ha.getCity());
+        assertEquals("HS", ha.getState());
+
+    }
+
+    public void testBadDocument() throws SAXException, IOException {
+
+    	// Listen to validation errors
+    	TestErrorHandler teh = new TestErrorHandler();
+    	digester.setErrorHandler(teh);
+
+        // Parse our test input
+    	digester.parse(getInputStream("Test13-02.xml"));
+        assertFalse("Test13-02 should generate errors in Schema validation", teh.clean);
+
+    }
+
+    // ------------------------------------ Utility Support Methods and Classes
+
+
+    /**
+     * Return an appropriate InputStream for the specified test file (which
+     * must be inside our current package.
+     *
+     * @param name Name of the test file we want
+     *
+     * @exception IOException if an input/output error occurs
+     */
+    protected InputStream getInputStream(String name) throws IOException {
+
+        return (this.getClass().getResourceAsStream
+                ("/org/apache/commons/digester/" + name));
+
+    }
+
+    static final class TestErrorHandler implements ErrorHandler {
+    	public boolean clean = true;
+    	public TestErrorHandler() { }
+    	public void error(SAXParseException exception) {
+    		clean = false;
+    	}
+    	public void fatalError(SAXParseException exception) {
+    		clean = false;
+    	}
+    	public void warning(SAXParseException exception) {
+    		clean = false;
+    	}
+    }
+
+}
+

Propchange: commons/proper/digester/trunk/src/test/org/apache/commons/digester/XMLSchemaTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/digester/trunk/src/test/org/apache/commons/digester/XMLSchemaTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL