commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1425132 - in /commons/proper/digester/trunk: ./ core/src/main/java/org/apache/commons/digester3/ core/src/main/java/org/apache/commons/digester3/binder/ core/src/test/java/org/apache/commons/digester3/ core/src/test/resources/org/apache/co...
Date Fri, 21 Dec 2012 20:40:50 GMT
Author: simonetripodi
Date: Fri Dec 21 20:40:49 2012
New Revision: 1425132

URL: http://svn.apache.org/viewvc?rev=1425132&view=rev
Log:
[DIGESTER-173] No way to enable schema validation from DigesterLoader - patch provided by
Ivan Diana

Added:
    commons/proper/digester/trunk/core/src/test/java/org/apache/commons/digester3/DTDValidationTestCase.java
  (with props)
    commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/document-with-relative-dtd-error.xml
  (with props)
Modified:
    commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/Digester.java
    commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/binder/DigesterLoader.java
    commons/proper/digester/trunk/pom.xml
    commons/proper/digester/trunk/src/changes/changes.xml

Modified: commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/Digester.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/Digester.java?rev=1425132&r1=1425131&r2=1425132&view=diff
==============================================================================
--- commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/Digester.java
(original)
+++ commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/Digester.java
Fri Dec 21 20:40:49 2012
@@ -774,9 +774,14 @@ public class Digester
     }
 
     /**
-     * Set the validating parser flag. This must be called before <code>parse()</code>
is called the first time.
+     * Set the validating parser flag. This must be called before <code>parse()</code>
is called the first time. 
+     * By default the value of this is set to false.
+     * 
+     * It essentially just controls the DTD validation. To use modern schema languages use
the 
+     * {@link #setXMLSchema(Schema)} method to associate a schema to a parser.
      *
      * @param validating The new validating parser flag.
+     * @see javax.xml.parsers.SAXParserFactory#setValidating(boolean) for more detail.
      */
     public void setValidating( boolean validating )
     {

Modified: commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/binder/DigesterLoader.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/binder/DigesterLoader.java?rev=1425132&r1=1425131&r2=1425132&view=diff
==============================================================================
--- commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/binder/DigesterLoader.java
(original)
+++ commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/binder/DigesterLoader.java
Fri Dec 21 20:40:49 2012
@@ -47,6 +47,8 @@ import org.xml.sax.EntityResolver;
 import org.xml.sax.ErrorHandler;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
 import org.xml.sax.XMLReader;
 
 /**
@@ -270,10 +272,11 @@ public final class DigesterLoader
     }
 
     /**
-     * Set the validating parser flag.
+     * Set the {@code DOCTYPE} validation parser flag and should not be used when using schemas.
      *
      * @param validating The new validating parser flag.
      * @return This loader instance, useful to chain methods.
+     * @see javax.xml.parsers.SAXParserFactory#setValidating(boolean)
      */
     public DigesterLoader setValidating( boolean validating )
     {
@@ -282,7 +285,7 @@ public final class DigesterLoader
     }
 
     /**
-     * Return the validating parser flag.
+     * Return the {@code DOCTYPE} validation parser flag.
      *
      * @return true, if the validating parser flag is set, false otherwise
      */
@@ -304,6 +307,26 @@ public final class DigesterLoader
     }
 
     /**
+     * Sets a flag indicating whether the requested feature is supported by the underlying
implementation of
+     * <code>org.xml.sax.XMLReader</code>.
+     * 
+     * @see org.apache.commons.digester3.Digester#setFeature(String, boolean)
+     * @param feature Name of the feature to set the status for
+     * @param value The new value for this feature
+     * @return This loader instance, useful to chain methods.
+     * @exception ParserConfigurationException if a parser configuration error occurs
+     * @exception SAXNotRecognizedException if the property name is not recognized
+     * @exception SAXNotSupportedException if the property name is recognized but not supported
+     * @since 3.3
+     */
+    public DigesterLoader setFeature( String feature, boolean value )
+        throws SAXNotRecognizedException, SAXNotSupportedException, ParserConfigurationException
+    {
+        factory.setFeature(feature, value);
+        return this;
+    }
+
+    /**
      * <p>Register the specified DTD URL for the specified public identifier.
      * This must be called before the first call to <code>parse()</code>.
      * </p><p>

Added: commons/proper/digester/trunk/core/src/test/java/org/apache/commons/digester3/DTDValidationTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/core/src/test/java/org/apache/commons/digester3/DTDValidationTestCase.java?rev=1425132&view=auto
==============================================================================
--- commons/proper/digester/trunk/core/src/test/java/org/apache/commons/digester3/DTDValidationTestCase.java
(added)
+++ commons/proper/digester/trunk/core/src/test/java/org/apache/commons/digester3/DTDValidationTestCase.java
Fri Dec 21 20:40:49 2012
@@ -0,0 +1,113 @@
+/* 
+ * 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.digester3;
+
+import static org.apache.commons.digester3.binder.DigesterLoader.newLoader;
+
+import java.io.File;
+
+import org.apache.commons.digester3.binder.AbstractRulesModule;
+import org.junit.Test;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Tests for entity resolution and dtd validation
+ *
+ * @author <a href='http://commons.apache.org/'>Apache Commons Team</a>
+ */
+public class DTDValidationTestCase
+{
+
+    @Test( expected = SAXParseException.class )
+    public void testDigesterDTDError()
+        throws Exception
+    {
+        newLoader( new AbstractRulesModule() {
+
+            @Override
+            protected void configure()
+            {
+                // do nothing
+            }
+
+        } )
+        .setValidating( true )
+        .setErrorHandler( new ErrorHandler()
+        {
+
+            public void warning( SAXParseException e )
+                throws SAXException
+            {
+                throw e;
+            }
+
+            public void fatalError( SAXParseException e )
+                throws SAXException
+            {
+                throw e;
+            }
+
+            public void error( SAXParseException e )
+                throws SAXException
+            {
+                throw e;
+            }
+
+        } )
+        .newDigester()
+        .parse( new File( "src/test/resources/org/apache/commons/digester3/document-with-relative-dtd-error.xml"
) );
+    }
+
+    @Test
+    public void testDigesterNoDTDValidation()
+        throws Exception
+    {
+        newLoader( new AbstractRulesModule()
+        {
+
+            @Override
+            protected void configure()
+            {
+                // do nothing
+            }
+
+        } )
+        .setValidating( false )
+        .newDigester()
+        .parse( new File( "src/test/resources/org/apache/commons/digester3/document-with-relative-dtd-error.xml"
) );
+    }
+
+    @Test
+    public void testDigesterValidation()
+        throws Exception
+    {
+        newLoader( new AbstractRulesModule()
+        {
+            @Override
+            protected void configure()
+            {
+                // do nothing
+            }
+        } )
+        .setValidating( true )
+        .newDigester()
+        .parse( new File( "src/test/resources/org/apache/commons/digester3/document-with-relative-dtd.xml"
) );
+    }
+
+}

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

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

Propchange: commons/proper/digester/trunk/core/src/test/java/org/apache/commons/digester3/DTDValidationTestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/document-with-relative-dtd-error.xml
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/document-with-relative-dtd-error.xml?rev=1425132&view=auto
==============================================================================
--- commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/document-with-relative-dtd-error.xml
(added)
+++ commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/document-with-relative-dtd-error.xml
Fri Dec 21 20:40:49 2012
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<!DOCTYPE document SYSTEM "simple.dtd">
+<nodtdtag>
+Hello, world
+</nodtdtag>
\ No newline at end of file

Propchange: commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/document-with-relative-dtd-error.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/document-with-relative-dtd-error.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/document-with-relative-dtd-error.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: commons/proper/digester/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/pom.xml?rev=1425132&r1=1425131&r2=1425132&view=diff
==============================================================================
--- commons/proper/digester/trunk/pom.xml (original)
+++ commons/proper/digester/trunk/pom.xml Fri Dec 21 20:40:49 2012
@@ -157,6 +157,10 @@
       <name>Dirk Schaube</name>
       <email>Dirk dot Schaube at dwpbank dot de</email>
     </contributor>
+    <contributor>
+      <name>Ivan Diana</name>
+      <email>iwo dot diana at gmail dot com</email>
+    </contributor>
   </contributors>
 
   <scm>

Modified: commons/proper/digester/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/changes/changes.xml?rev=1425132&r1=1425131&r2=1425132&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/changes/changes.xml (original)
+++ commons/proper/digester/trunk/src/changes/changes.xml Fri Dec 21 20:40:49 2012
@@ -26,6 +26,9 @@
     <action dev="simonetripodi" type="fix" issue="DIGESTER-174" due-to="Andreas Sahlbach">
       Inner List Annotation has wrong @Target for most of the predefined annotation rules
     </action>
+    <action dev="simonetripodi" type="fix" issue="DIGESTER-173" due-to="Ivan Diana">
+      No way to enable schema validation from DigesterLoader
+    </action>
     <action dev="simonetripodi" type="fix" issue="DIGESTER-172" due-to="Ivan Diana">
       Even with custom ErrorHandler, SAX errors are still written to stderr
     </action>



Mime
View raw message