You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2005/10/10 14:02:36 UTC
svn commit: r312628 - in /cocoon/trunk/src: java/org/apache/cocoon/core/
java/org/apache/cocoon/generation/ webapp/WEB-INF/properties/
webapp/WEB-INF/properties/dev/
Author: cziegeler
Date: Mon Oct 10 05:02:29 2005
New Revision: 312628
URL: http://svn.apache.org/viewcvs?rev=312628&view=rev
Log:
Add support for running modes
Added:
cocoon/trunk/src/webapp/WEB-INF/properties/
cocoon/trunk/src/webapp/WEB-INF/properties/dev/
cocoon/trunk/src/webapp/WEB-INF/properties/dev/core.properties (with props)
Modified:
cocoon/trunk/src/java/org/apache/cocoon/core/BaseSettings.java
cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java
cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java
Modified: cocoon/trunk/src/java/org/apache/cocoon/core/BaseSettings.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/BaseSettings.java?rev=312628&r1=312627&r2=312628&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/BaseSettings.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/BaseSettings.java Mon Oct 10 05:02:29 2005
@@ -32,8 +32,14 @@
/** Default value for {@link #isManageExceptions()}. */
boolean MANAGE_EXCEPTIONS = true;
- /** Name of the property specifying a user properties file */
+ /** Name of the property specifying a custom user properties file. */
String PROPERTY_USER_SETTINGS = "org.apache.cocoon.settings";
+
+ /** Name of the property specifying the running mode. */
+ String PROPERTY_RUNNING_MODE = "org.apache.cocoon.mode";
+
+ /** The default running mode. */
+ String DEFAULT_RUNNING_MODE = "dev";
/**
* This parameter allows to set system properties
Modified: cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java?rev=312628&r1=312627&r2=312628&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java Mon Oct 10 05:02:29 2005
@@ -330,29 +330,44 @@
/**
* Get the settings for Cocoon.
+ * This method reads several property files and merges the result. If there
+ * is more than one definition for a property, the last one wins.
+ * The property files are read in the following order:
+ * 1) context://WEB-INF/cocoon-settings.properties
+ * These are the default values.
+ * 2) context://WEB-INF/properties/*.properties
+ * Default values for each block - the order in which the files are read is not guaranteed.
+ * 3) context://WEB-INF/properties/[RUNNING_MODE]/*.properties
+ * Default values for the running mode - the order in which the files are read is not guaranteed.
+ * 4) Property providers (ToBeDocumented)
+ * 5) The environment (CLI, Servlet etc.) adds own properties (e.g. from web.xml)
+ * 6) Additional property file specified by the "org.apache.cocoon.settings" system property.
+ * 7) System properties
+ *
* @return A new Settings object
*/
protected MutableSettings createSettings() {
+ // get the running mode
+ final String mode = System.getProperty(Settings.PROPERTY_RUNNING_MODE, Settings.DEFAULT_RUNNING_MODE);
+ this.env.log("Running in mode: " + mode);
+
// create an empty settings objects
final MutableSettings s = new MutableSettings();
// we need our own resolver
final SourceResolver resolver = this.createSourceResolver(new LoggerWrapper(this.env));
- String additionalPropertyFile = System.getProperty(Settings.PROPERTY_USER_SETTINGS);
-
// read cocoon-settings.properties - if available
Source source = null;
try {
source = resolver.resolveURI("context://WEB-INF/cocoon-settings.properties");
if ( source.exists() ) {
final InputStream propsIS = source.getInputStream();
- env.log("Reading settings from '" + source.getURI() + "'");
+ this.env.log("Reading settings from '" + source.getURI() + "'");
final Properties p = new Properties();
p.load(propsIS);
propsIS.close();
s.fill(p);
- additionalPropertyFile = p.getProperty(Settings.PROPERTY_USER_SETTINGS, additionalPropertyFile);
}
} catch (IOException ignore) {
env.log("Unable to read 'WEB-INF/cocoon-settings.properties'.", ignore);
@@ -362,30 +377,9 @@
}
// now read all properties from the properties directory
- Source directory = null;
- try {
- directory = resolver.resolveURI("context://WEB-INF/properties", null, CONTEXT_PARAMETERS);
- if (directory.exists() && directory instanceof TraversableSource) {
- final Iterator c = ((TraversableSource) directory).getChildren().iterator();
- while (c.hasNext()) {
- final Source src = (Source) c.next();
- if ( src.getURI().endsWith(".properties") ) {
- final InputStream propsIS = src.getInputStream();
- env.log("Reading settings from '" + src.getURI() + "'.");
- final Properties p = new Properties();
- p.load(propsIS);
- propsIS.close();
- s.fill(p);
- additionalPropertyFile = p.getProperty(Settings.PROPERTY_USER_SETTINGS, additionalPropertyFile);
- }
- }
- }
- } catch (IOException ignore) {
- env.log("Unable to read from directory 'WEB-INF/properties'.", ignore);
- env.log("Continuing initialization.");
- } finally {
- resolver.release(directory);
- }
+ this.readProperties("context://WEB-INF/properties", s, resolver);
+ // read all properties from the mode dependent directory
+ this.readProperties("context://WEB-INF/properties/" + mode, s, resolver);
// Next look for custom property providers
Iterator i = s.getPropertyProviders().iterator();
@@ -403,6 +397,8 @@
env.configure(s);
// read additional properties file
+ final String additionalPropertyFile = s.getProperty(Settings.PROPERTY_USER_SETTINGS,
+ System.getProperty(Settings.PROPERTY_USER_SETTINGS));
if ( additionalPropertyFile != null ) {
env.log("Reading user settings from '" + additionalPropertyFile + "'");
final Properties p = new Properties();
@@ -419,6 +415,37 @@
s.fill(System.getProperties());
return s;
+ }
+
+ /**
+ * Read all property files from the given directory and apply them to the settings.
+ */
+ protected void readProperties(String directoryName,
+ MutableSettings s,
+ SourceResolver resolver) {
+ Source directory = null;
+ try {
+ directory = resolver.resolveURI(directoryName, null, CONTEXT_PARAMETERS);
+ if (directory.exists() && directory instanceof TraversableSource) {
+ final Iterator c = ((TraversableSource) directory).getChildren().iterator();
+ while (c.hasNext()) {
+ final Source src = (Source) c.next();
+ if ( src.getURI().endsWith(".properties") ) {
+ final InputStream propsIS = src.getInputStream();
+ env.log("Reading settings from '" + src.getURI() + "'.");
+ final Properties p = new Properties();
+ p.load(propsIS);
+ propsIS.close();
+ s.fill(p);
+ }
+ }
+ }
+ } catch (IOException ignore) {
+ env.log("Unable to read from directory 'WEB-INF/properties'.", ignore);
+ env.log("Continuing initialization.");
+ } finally {
+ resolver.release(directory);
+ }
}
/**
Modified: cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java?rev=312628&r1=312627&r2=312628&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java Mon Oct 10 05:02:29 2005
@@ -475,6 +475,8 @@
final Settings s = core.getSettings();
this.startGroup("Base Settings");
+ this.addValue("Running mode", s.getProperty(Settings.PROPERTY_RUNNING_MODE,
+ Settings.DEFAULT_RUNNING_MODE));
this.addValue(Settings.KEY_CONFIGURATION, s.getConfiguration());
this.addMultilineValue(Settings.KEY_EXTRA_CLASSPATHS, s.getExtraClasspaths());
this.addMultilineValue(Settings.KEY_LOAD_CLASSES, s.getLoadClasses());
Added: cocoon/trunk/src/webapp/WEB-INF/properties/dev/core.properties
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/webapp/WEB-INF/properties/dev/core.properties?rev=312628&view=auto
==============================================================================
--- cocoon/trunk/src/webapp/WEB-INF/properties/dev/core.properties (added)
+++ cocoon/trunk/src/webapp/WEB-INF/properties/dev/core.properties Mon Oct 10 05:02:29 2005
@@ -0,0 +1,16 @@
+# Copyright 1999-2005 The Apache Software Foundation
+#
+# Licensed 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.
+#
+# Turn on lazy loading
+org.apache.cocoon.core.LazyMode=true
\ No newline at end of file
Propchange: cocoon/trunk/src/webapp/WEB-INF/properties/dev/core.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/src/webapp/WEB-INF/properties/dev/core.properties
------------------------------------------------------------------------------
svn:keywords = Id