Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 89614 invoked from network); 25 Dec 2006 20:06:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 25 Dec 2006 20:06:18 -0000 Received: (qmail 70292 invoked by uid 500); 25 Dec 2006 20:06:25 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 70235 invoked by uid 500); 25 Dec 2006 20:06:25 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 70224 invoked by uid 99); 25 Dec 2006 20:06:25 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Dec 2006 12:06:25 -0800 X-ASF-Spam-Status: No, hits=-8.6 required=10.0 tests=ALL_TRUSTED,INFO_TLD,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Dec 2006 12:06:17 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id BBA801A981A; Mon, 25 Dec 2006 12:05:25 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r490164 - in /cocoon/trunk/core: cocoon-configuration/cocoon-configuration-api/src/main/java/org/apache/cocoon/configuration/ cocoon-spring/src/main/java/org/apache/cocoon/core/container/spring/ Date: Mon, 25 Dec 2006 20:05:25 -0000 To: cvs@cocoon.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061225200525.BBA801A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: cziegeler Date: Mon Dec 25 12:05:24 2006 New Revision: 490164 URL: http://svn.apache.org/viewvc?view=rev&rev=490164 Log: Load properties from WEB-INF/classes after properties from jars If additional property specifies a directory, load all properties from this directory Modified: cocoon/trunk/core/cocoon-configuration/cocoon-configuration-api/src/main/java/org/apache/cocoon/configuration/PropertyProvider.java cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/core/container/spring/ResourceUtils.java cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java Modified: cocoon/trunk/core/cocoon-configuration/cocoon-configuration-api/src/main/java/org/apache/cocoon/configuration/PropertyProvider.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-configuration-api/src/main/java/org/apache/cocoon/configuration/PropertyProvider.java?view=diff&rev=490164&r1=490163&r2=490164 ============================================================================== --- cocoon/trunk/core/cocoon-configuration/cocoon-configuration-api/src/main/java/org/apache/cocoon/configuration/PropertyProvider.java (original) +++ cocoon/trunk/core/cocoon-configuration/cocoon-configuration-api/src/main/java/org/apache/cocoon/configuration/PropertyProvider.java Mon Dec 25 12:05:24 2006 @@ -31,7 +31,19 @@ */ public interface PropertyProvider { + /** + * The bean must be registered with this name. + */ String ROLE = PropertyProvider.class.getName(); + /** + * Provide the properties. + * + * @param settings The already loaded settings. + * @param runningMode The current running mode. + * @param path A path specifying the application context the settings are applied to. + * A path of null indicates the root application context. + * @return The additional properties. + */ Properties getProperties(Settings settings, String runningMode, String path); } Modified: cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/core/container/spring/ResourceUtils.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/core/container/spring/ResourceUtils.java?view=diff&rev=490164&r1=490163&r2=490164 ============================================================================== --- cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/core/container/spring/ResourceUtils.java (original) +++ cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/core/container/spring/ResourceUtils.java Mon Dec 25 12:05:24 2006 @@ -33,12 +33,12 @@ import org.springframework.web.context.support.ServletContextResourcePatternResolver; /** - * Utility class for Spring resource handling + * Utility class for Spring resource handling. * * @version $Id$ * @since 2.2 */ -public class ResourceUtils { +public abstract class ResourceUtils { /** * Get the uri of a resource. This method corrects the uri in the case of @@ -148,14 +148,24 @@ } /** - * Return a resource comparator + * Return a resource comparator. + * This comparator compares the file name of two resources. + * In addition all resources contained in a directory named + * WEB-INF/classes/cocoon are sorted (in alphabetical) order + * after all other files. */ public static Comparator getResourceComparator() { return new ResourceComparator(); } + /** + * Class implementing a simple resource comparator as described + * here: {@link ResourceUtils#getResourceComparator}. + */ protected final static class ResourceComparator implements Comparator { + protected static final String WEB_INF_CLASSES_META_INF_COCOON = "/WEB-INF/classes/META-INF/cocoon/"; + /** * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ @@ -163,6 +173,24 @@ if (!(o1 instanceof Resource) || !(o2 instanceof Resource)) { return 0; } + try { + String name1 = ((Resource)o1).getURL().toExternalForm(); + String name2 = ((Resource)o2).getURL().toExternalForm(); + // replace '\' with '/' + name1.replace('\\', '/'); + name2.replace('\\', '/'); + boolean webInfClasses1 = name1.indexOf(ResourceComparator.WEB_INF_CLASSES_META_INF_COCOON) != -1; + boolean webInfClasses2 = name2.indexOf(ResourceComparator.WEB_INF_CLASSES_META_INF_COCOON) != -1; + if ( !webInfClasses1 && webInfClasses2 ) { + return -1; + } + if ( webInfClasses1 && !webInfClasses2 ) { + return +1; + } + } catch (IOException io) { + // ignore + } + // default behaviour: return ((Resource) o1).getFilename().compareTo(((Resource) o2).getFilename()); } } Modified: cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java?view=diff&rev=490164&r1=490163&r2=490164 ============================================================================== --- cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java (original) +++ cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java Mon Dec 25 12:05:24 2006 @@ -128,13 +128,20 @@ * The property files are read in the following order: * 1) classpath*:/META-INF/cocoon/properties/*.properties * Default values for the core and each block - the files are read in alphabetical order. + * Actually the files are read in two chunks, the first one containing all property files + * from jar files, and the second one containing all property files from WEB-INF/classes. * 2) classpath*:/META-INF/cocoon/properties/[RUNNING_MODE]/*.properties * Default values for the core and each block for a specific running mode - the files are * read in alphabetical order. + * Actually the files are read in two chunks, the first one containing all property files + * from jar files, and the second one containing all property files from WEB-INF/classes. * 3) Working directory from servlet context (if not already set) * 4) Optional property file which is stored under ".cocoon/settings.properties" in the user * directory. - * 5) Additional property file specified by the "org.apache.cocoon.settings" property. + * 5) Additional property file specified by the "org.apache.cocoon.settings" property. If the + * property defines a directory, all property files from this directory are read in alphabetical + * order and all files from a sub directory with the name of the current running mode + * are read in alphabetical order as well. * 6) Property provider (if configured in the bean factory) * 7) System properties * @@ -146,7 +153,7 @@ protected MutableSettings createSettings() { // get the running mode final String mode = RunningModeHelper.determineRunningMode( this.runningMode ); - + /* if ( !Arrays.asList(SettingsDefaults.RUNNING_MODES).contains(mode) ) { final String msg = @@ -199,12 +206,27 @@ if ( this.logger.isDebugEnabled() ) { this.logger.debug("Reading user settings from '" + additionalPropertyFile + "'"); } - try { - final FileInputStream fis = new FileInputStream(additionalPropertyFile); - properties.load(fis); - fis.close(); - } catch (IOException ignore) { - this.logger.info("Unable to read '" + additionalPropertyFile + "' - continuing with initialization.", ignore); + final File additionalFile = new File(additionalPropertyFile); + if ( additionalFile.exists() ) { + if ( additionalFile.isDirectory() ) { + // read from directory + ResourceUtils.readProperties(additionalFile.getAbsolutePath(), + properties, this.getResourceLoader(), this.logger); + // read all properties from the mode dependent directory + ResourceUtils.readProperties(additionalFile.getAbsolutePath() + File.separatorChar + mode, + properties, this.getResourceLoader(), this.logger); + } else { + // read the file + try { + final FileInputStream fis = new FileInputStream(additionalFile); + properties.load(fis); + fis.close(); + } catch (IOException ignore) { + this.logger.info("Unable to read '" + additionalPropertyFile + "' - continuing with initialization.", ignore); + } + } + } else { + this.logger.info("Additional settings file '" + additionalPropertyFile + "' does not exist - continuing with initialization."); } } // check for property providers