commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1127900 - /commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/xmlrules/IncludeRule.java
Date Thu, 26 May 2011 13:30:25 GMT
Author: simonetripodi
Date: Thu May 26 13:30:25 2011
New Revision: 1127900

URL: http://svn.apache.org/viewvc?rev=1127900&view=rev
Log:
include rule simplified, checking if a URL has been already visited is simpler

Modified:
    commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/xmlrules/IncludeRule.java

Modified: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/xmlrules/IncludeRule.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/xmlrules/IncludeRule.java?rev=1127900&r1=1127899&r2=1127900&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/xmlrules/IncludeRule.java
(original)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/xmlrules/IncludeRule.java
Thu May 26 13:30:25 2011
@@ -17,6 +17,7 @@
  */
 package org.apache.commons.digester3.xmlrules;
 
+import java.net.MalformedURLException;
 import java.net.URL;
 
 import org.apache.commons.digester3.Rule;
@@ -55,10 +56,10 @@ final class IncludeRule
         throws Exception
     {
         // The path attribute gives the URI to another digester rules xml file
-        final String fileName = attributes.getValue( "path" );
+        String fileName = attributes.getValue( "path" );
         if ( fileName != null && fileName.length() > 0 )
         {
-            FromXmlRulesModule fromXmlRulesModule = null;
+            final URL xmlRulesResource;
 
             if ( fileName.startsWith( CLASSPATH_URL_PREFIX ) )
             {
@@ -67,64 +68,44 @@ final class IncludeRule
                 {
                     path = path.substring( 1 );
                 }
-                final URL classPathResource = this.targetRulesBinder.getContextClassLoader().getResource(
path );
-                if ( classPathResource == null )
+                xmlRulesResource = this.targetRulesBinder.getContextClassLoader().getResource(
path );
+                if ( xmlRulesResource == null )
                 {
                     targetRulesBinder.addError( "Resource '%s' not found, please make sure
it is in the classpath",
                                                 path );
-                }
-                else
-                {
-                    fromXmlRulesModule = new FromXmlRulesModule()
-                    {
-
-                        @Override
-                        protected void loadRules()
-                        {
-                            loadXMLRules( classPathResource );
-                        }
-
-                    };
+                    return;
                 }
             }
             else
             {
                 try
                 {
-                    fromXmlRulesModule = new FromXmlRulesModule()
-                    {
-
-                        @Override
-                        protected void loadRules()
-                        {
-                            loadXMLRules( fileName );
-                        }
-
-                    };
+                    xmlRulesResource = new URL( fileName );
                 }
-                catch ( Exception e )
+                catch ( MalformedURLException e )
                 {
                     targetRulesBinder.addError( "An error occurred while inculing file from
'%s': %s", fileName,
                                                 e.getMessage() );
+                    return;
                 }
             }
 
-            if ( fromXmlRulesModule != null )
+            if ( memoryRulesBinder.getIncludedFiles().add( xmlRulesResource.toString() )
)
             {
-                boolean circularFileInclusionDetected = false;
-                for ( String systemId : fromXmlRulesModule.getSystemIds() )
+                install( new FromXmlRulesModule()
                 {
-                    if ( !memoryRulesBinder.getIncludedFiles().add( systemId ) )
+
+                    @Override
+                    protected void loadRules()
                     {
-                        targetRulesBinder.addError( "Circular file inclusion detected for
XML rules: %s", systemId );
-                        circularFileInclusionDetected = true;
+                        loadXMLRules( xmlRulesResource );
                     }
-                }
 
-                if ( !circularFileInclusionDetected )
-                {
-                    install( fromXmlRulesModule );
-                }
+                });
+            }
+            else
+            {
+                targetRulesBinder.addError( "Circular file inclusion detected for XML rules:
%s", xmlRulesResource );
             }
         }
 



Mime
View raw message