commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1382109 - in /commons/proper/digester/trunk: core/src/main/java/org/apache/commons/digester3/xmlrules/ core/src/test/java/org/apache/commons/digester3/xmlrules/ core/src/test/resources/org/apache/commons/digester3/xmlrules/ src/changes/
Date Fri, 07 Sep 2012 18:19:17 GMT
Author: simonetripodi
Date: Fri Sep  7 18:19:16 2012
New Revision: 1382109

URL: http://svn.apache.org/viewvc?rev=1382109&view=rev
Log:
[DIGESTER-167] Groundless 'Circular file inclusion detected' exception when including rules
XML file - patch submitted by Eugene Fedotov

Modified:
    commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/xmlrules/IncludeRule.java
    commons/proper/digester/trunk/core/src/test/java/org/apache/commons/digester3/xmlrules/IncludeTest.java
    commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/xmlrules/testCircularRules.xml
    commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/xmlrules/testrulesinclude.xml
    commons/proper/digester/trunk/src/changes/changes.xml

Modified: commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/xmlrules/IncludeRule.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/xmlrules/IncludeRule.java?rev=1382109&r1=1382108&r2=1382109&view=diff
==============================================================================
--- commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/xmlrules/IncludeRule.java
(original)
+++ commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/xmlrules/IncludeRule.java
Fri Sep  7 18:19:16 2012
@@ -21,6 +21,7 @@ package org.apache.commons.digester3.xml
 
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.Set;
 
 import org.apache.commons.digester3.Rule;
 import org.apache.commons.digester3.binder.RulesBinder;
@@ -92,18 +93,27 @@ final class IncludeRule
                 }
             }
 
-            if ( memoryRulesBinder.getIncludedFiles().add( xmlRulesResource.toString() )
)
+            Set<String> includedFiles = memoryRulesBinder.getIncludedFiles();
+            String xmlRulesResourceString = xmlRulesResource.toString();
+            if ( includedFiles.add( xmlRulesResourceString ) )
             {
-                install( new FromXmlRulesModule()
+                try
                 {
-
-                    @Override
-                    protected void loadRules()
+                    install( new FromXmlRulesModule()
                     {
-                        loadXMLRules( xmlRulesResource );
-                    }
 
-                } );
+                        @Override
+                        protected void loadRules()
+                        {
+                            loadXMLRules( xmlRulesResource );
+                        }
+
+                    } );
+                }
+                finally
+                {
+                    includedFiles.remove( xmlRulesResourceString );
+                }
             }
             else
             {

Modified: commons/proper/digester/trunk/core/src/test/java/org/apache/commons/digester3/xmlrules/IncludeTest.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/core/src/test/java/org/apache/commons/digester3/xmlrules/IncludeTest.java?rev=1382109&r1=1382108&r2=1382109&view=diff
==============================================================================
--- commons/proper/digester/trunk/core/src/test/java/org/apache/commons/digester3/xmlrules/IncludeTest.java
(original)
+++ commons/proper/digester/trunk/core/src/test/java/org/apache/commons/digester3/xmlrules/IncludeTest.java
Fri Sep  7 18:19:16 2012
@@ -19,7 +19,6 @@
 package org.apache.commons.digester3.xmlrules;
 
 import static org.apache.commons.digester3.binder.DigesterLoader.newLoader;
-
 import static org.junit.Assert.assertEquals;
 
 import java.io.StringReader;
@@ -52,7 +51,7 @@ public class IncludeTest
                 public void body( String namespace, String name, String text )
                     throws Exception
                 {
-                    ArrayList<String> stringList = getDigester().peek();
+                    List<String> stringList = getDigester().peek();
                     stringList.add( text );
                 }
 
@@ -66,6 +65,8 @@ public class IncludeTest
         throws Exception
     {
         final String rulesXml = "<?xml version='1.0'?>"
+                + "<!DOCTYPE digester-rules PUBLIC \"-//Apache Commons //DTD digester-rules
XML V1.0//EN\" "
+                + "\"http://commons.apache.org/digester/dtds/digester-rules-3.0.dtd\">"
                 + "<digester-rules>"
                 + " <pattern value='root/foo'>"
                 + "   <include class='org.apache.commons.digester3.xmlrules.IncludeTest$TestDigesterRulesModule'
/>"
@@ -84,7 +85,7 @@ public class IncludeTest
                 loadXMLRulesFromText( rulesXml );
             }
 
-        }).newDigester();
+        } ).newDigester();
         digester.push( list );
         digester.parse( new StringReader( xml ) );
 
@@ -92,6 +93,40 @@ public class IncludeTest
         assertEquals( "Entry value", "short", list.get( 0 ) );
     }
 
+    @Test
+    public void testUrlInclude()
+        throws Exception
+    {
+        final String rulesXml = "<?xml version='1.0'?>"
+                + "<!DOCTYPE digester-rules PUBLIC \"-//Apache Commons //DTD digester-rules
XML V1.0//EN\" "
+                + "\"http://commons.apache.org/digester/dtds/digester-rules-3.0.dtd\">"
+                + "<digester-rules>"
+                + " <pattern value='root/foo1'>"
+                + "   <include url='classpath:org/apache/commons/digester3/xmlrules/testrulesinclude.xml'
/>"
+                + " </pattern>"
+                + " <pattern value='root/foo2'>"
+                + "   <include url='classpath:org/apache/commons/digester3/xmlrules/testrulesinclude.xml'
/>"
+                + " </pattern>"
+                + "</digester-rules>";
+
+        String xml = "<?xml version='1.0' ?><root><foo1><bar><foo
value='foo1'/></bar></foo1><foo2><bar><foo value='foo2'/></bar></foo2></root>";
+
+        List<String> list = new ArrayList<String>();
+        Digester digester = newLoader( new FromXmlRulesModule()
+        {
+
+            @Override
+            protected void loadRules()
+            {
+                loadXMLRulesFromText( rulesXml );
+            }
+
+        }).newDigester();
+        digester.push( list );
+        digester.parse( new StringReader( xml ) );
+        assertEquals( "[foo1, foo2]", list.toString() );
+    }
+
     /**
      * Validates that circular includes are detected and result in an exception
      */

Modified: commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/xmlrules/testCircularRules.xml
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/xmlrules/testCircularRules.xml?rev=1382109&r1=1382108&r2=1382109&view=diff
==============================================================================
--- commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/xmlrules/testCircularRules.xml
(original)
+++ commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/xmlrules/testCircularRules.xml
Fri Sep  7 18:19:16 2012
@@ -19,7 +19,7 @@
 <!-- Rules to test the DigesterLoader's circular include detection. 
      Attempting to create a digester with these rules should result
      in an exception. -->
-
+<!DOCTYPE digester-rules PUBLIC "-//Apache Commons //DTD digester-rules XML V1.0//EN"
"http://commons.apache.org/digester/dtds/digester-rules-3.0.dtd">
 <digester-rules>
   <pattern value="root/foo">
     <object-create-rule classname="org.apache.commons.digester3.xmlrules.ObjectTestImpl"
/>

Modified: commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/xmlrules/testrulesinclude.xml
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/xmlrules/testrulesinclude.xml?rev=1382109&r1=1382108&r2=1382109&view=diff
==============================================================================
--- commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/xmlrules/testrulesinclude.xml
(original)
+++ commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/xmlrules/testrulesinclude.xml
Fri Sep  7 18:19:16 2012
@@ -15,6 +15,7 @@
  See the License for the specific language governing permissions and
  limitations under the License.
 -->
+<!DOCTYPE digester-rules PUBLIC "-//Apache Commons //DTD digester-rules XML V1.0//EN"
"http://commons.apache.org/digester/dtds/digester-rules-3.0.dtd">
 <digester-rules>
   <pattern value="bar">
     <pattern value="foo">

Modified: commons/proper/digester/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/changes/changes.xml?rev=1382109&r1=1382108&r2=1382109&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/changes/changes.xml (original)
+++ commons/proper/digester/trunk/src/changes/changes.xml Fri Sep  7 18:19:16 2012
@@ -26,6 +26,9 @@
     <action dev="simonetripodi" type="fix" issue="DIGESTER-169" due-to="Eugene Fedotov">
       Problem when including rules XML file with "classpath:" URL prefix
     </action>
+    <action dev="simonetripodi" type="fix" issue="DIGESTER-167" due-to="Eugene Fedotov">
+      Groundless "Circular file inclusion detected" exception when including rules XML file
+    </action>
     <action dev="simonetripodi" type="fix" issue="DIGESTER-165" due-to="Dirk Schaube">
       BinderClassLoader does not override getResource
     </action>



Mime
View raw message