Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 69B0C6BFA for ; Thu, 26 May 2011 13:30:47 +0000 (UTC) Received: (qmail 81470 invoked by uid 500); 26 May 2011 13:30:47 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 81414 invoked by uid 500); 26 May 2011 13:30:47 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 81407 invoked by uid 99); 26 May 2011 13:30:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 May 2011 13:30:47 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 May 2011 13:30:46 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 061642388A90; Thu, 26 May 2011 13:30:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@commons.apache.org From: simonetripodi@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110526133026.061642388A90@eris.apache.org> 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 ); } }