cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r149417 - in cocoon/trunk/src: blocks/portal/java/org/apache/cocoon/portlet/ core/java/org/apache/cocoon/configuration/ core/java/org/apache/cocoon/core/ core/java/org/apache/cocoon/core/container/ core/java/org/apache/cocoon/core/container/util/ core/test/org/apache/cocoon/core/container/util/ java/org/apache/cocoon/ java/org/apache/cocoon/bean/ java/org/apache/cocoon/components/ java/org/apache/cocoon/components/container/ java/org/apache/cocoon/servlet/
Date Tue, 01 Feb 2005 17:01:48 GMT
Author: cziegeler
Date: Tue Feb  1 09:01:45 2005
New Revision: 149417

URL: http://svn.apache.org/viewcvs?view=rev&rev=149417
Log:
Finish properties handling

Modified:
    cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java
    cocoon/trunk/src/core/java/org/apache/cocoon/configuration/ConfigurationBuilder.java
    cocoon/trunk/src/core/java/org/apache/cocoon/configuration/Settings.java
    cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java
    cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentEnvironment.java
    cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CoreServiceManager.java
    cocoon/trunk/src/core/java/org/apache/cocoon/core/container/util/PropertyHelper.java
    cocoon/trunk/src/core/test/org/apache/cocoon/core/container/util/PropertyHelperTestCase.java
    cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java
    cocoon/trunk/src/java/org/apache/cocoon/bean/CocoonWrapper.java
    cocoon/trunk/src/java/org/apache/cocoon/components/ContextHelper.java
    cocoon/trunk/src/java/org/apache/cocoon/components/container/LoggingHelper.java
    cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java

Modified: cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java?view=diff&r1=149416&r2=149417
==============================================================================
--- cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java (original)
+++ cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java Tue Feb
 1 09:01:45 2005
@@ -35,6 +35,8 @@
 import org.apache.cocoon.components.notification.DefaultNotifyingBuilder;
 import org.apache.cocoon.components.notification.Notifier;
 import org.apache.cocoon.components.notification.Notifying;
+import org.apache.cocoon.configuration.Settings;
+import org.apache.cocoon.core.Core;
 import org.apache.cocoon.environment.Environment;
 import org.apache.cocoon.environment.portlet.PortletContext;
 import org.apache.cocoon.environment.portlet.PortletEnvironment;
@@ -287,6 +289,8 @@
 
         this.portletContext = conf.getPortletContext();
         this.appContext.put(Constants.CONTEXT_ENVIRONMENT_CONTEXT, new PortletContext(this.portletContext));
+        // FIXME - add settings
+        appContext.put(Core.CONTEXT_SETTINGS, new Settings());
         this.portletContextPath = this.portletContext.getRealPath("/");
 
         // first init the work-directory for the logger.

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/configuration/ConfigurationBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/configuration/ConfigurationBuilder.java?view=diff&r1=149416&r2=149417
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/configuration/ConfigurationBuilder.java (original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/configuration/ConfigurationBuilder.java Tue
Feb  1 09:01:45 2005
@@ -94,11 +94,13 @@
     private Configuration configuration;
     private Locator locator;
     private final NamespaceSupport namespaceSupport = new NamespaceSupport();
-
+    private final Settings settings;
+    
     /**
      * Create a Configuration Builder
      */
-    public ConfigurationBuilder() {
+    public ConfigurationBuilder(Settings s) {
+        this.settings = s;
         try {
             final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
 
@@ -272,7 +274,7 @@
             } else {
                 finishedValue = accumulatedValue.trim();
             }
-            finishedConfiguration.setValue( PropertyHelper.replace(finishedValue) );
+            finishedConfiguration.setValue( PropertyHelper.replace(finishedValue, this.settings)
);
         } else {
             final String trimmedValue = accumulatedValue.trim();
             if( trimmedValue.length() > 0 ) {
@@ -367,7 +369,7 @@
         for( int i = 0; i < attributesSize; i++ ) {
             final String name = componentAttr.getQName( i );
             final String value = componentAttr.getValue( i );
-            configuration.setAttribute( name, PropertyHelper.replace(value) );
+            configuration.setAttribute( name, PropertyHelper.replace(value, this.settings)
);
         }
     }
 

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/configuration/Settings.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/configuration/Settings.java?view=diff&r1=149416&r2=149417
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/configuration/Settings.java (original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/configuration/Settings.java Tue Feb  1 09:01:45
2005
@@ -57,6 +57,11 @@
     public static final boolean MANAGE_EXCEPTIONS = true;
 
     /**
+     * The list of properties used to configure Cocoon
+     */
+    protected List properties = new ArrayList();
+
+    /**
      * This parameter tells Cocoon to set the thread's context classloader to
      * its own classloader. If you experience strange classloader issues,
      * try setting this parameter to "true".
@@ -252,7 +257,7 @@
                     key = key.substring("org.apache.cocoon.".length());
                     final String value = current.getValue().toString();
 
-                    if ( key.equals("init.classloader") ) { 
+                    if ( key.equals("init.classloader") ) {
                         this.initClassloader = BooleanUtils.toBoolean(value);
                     } else if ( key.equals("configuration") ) {
                         this.configuration = value;
@@ -300,6 +305,7 @@
                     // TODO - force property, load classes, extra class path
                 }
             }
+            this.properties.add(props);
         }
     }
     
@@ -673,5 +679,75 @@
                "- Log4J Configuration: " + this.log4jConfiguration + "\n" +
                "- Override Loglevel: " + this.overrideLogLevel + "\n";
 
+    }
+
+    public String getProperty(String name) {
+        return this.getProperty(name, null);
+    }
+
+    public String getProperty(String key, String defaultValue) {
+        if ( key == null ) {
+            return defaultValue;
+        }
+        String value = null;
+        if ( key.startsWith("org.apache.cocoon.") ) {
+            final String sKey = key.substring("org.apache.cocoon.".length());
+            if ( sKey.equals("init.classloader") ) {
+                value = String.valueOf(this.initClassloader);
+            } else if ( sKey.equals("configuration") ) {
+                value = this.configuration;
+            } else if ( sKey.equals("logging.configuration") ) {
+                value = this.loggingConfiguration;
+            } else if ( sKey.equals("logging.logger.access") ) {
+                value = this.accessLogger;
+            } else if ( sKey.equals("logging.logger.cocoon") ) {
+                value = this.cocoonLogger;
+            } else if ( sKey.equals("logging.bootstrap.level") ) {
+                value = this.bootstrapLogLevel;
+            } else if ( sKey.equals("logging.manager.class") ) {
+                value = this.loggerClassName;
+            } else if ( sKey.equals("logging.log4j.configuration") ) {
+                value = this.log4jConfiguration;
+            } else if ( sKey.equals("allow.reload") ) {
+                value = String.valueOf(this.allowReload);
+            } else if ( sKey.equals("uploads.enable") ) {
+                value = String.valueOf(this.enableUploads);
+            } else if ( sKey.equals("uploads.directory") ) {
+                value = this.uploadDirectory = value;
+            } else if ( sKey.equals("uploads.autosave") ) {
+                value = String.valueOf(this.autosaveUploads);
+            } else if ( sKey.equals("uploads.overwrite") ) {
+                value = this.overwriteUploads;
+            } else if ( sKey.equals("uploads.maxsize") ) {
+                value = String.valueOf(this.maxUploadSize);
+            } else if ( sKey.equals("cache.directory") ) {
+                value = this.cacheDirectory;
+            } else if ( sKey.equals("work.directory") ) {
+                value = this.workDirectory;
+            } else if ( sKey.equals("parentservicemanager") ) {
+                value = this.parentServiceManagerClassName;
+            } else if ( sKey.equals("showtime") ) {
+                value = String.valueOf(this.showTime);
+            } else if ( sKey.equals("hideshowtime") ) {
+                value = String.valueOf(this.hideShowTime);
+            } else if ( sKey.equals("manageexceptions") ) {
+                value = String.valueOf(this.manageExceptions);
+            } else if ( sKey.equals("formencoding") ) {
+                value = this.formEncoding;
+            } else if ( sKey.equals("override.loglevel") ) {
+                value = this.overrideLogLevel;
+            }
+        }
+
+        int i = 0;
+        while ( i < this.properties.size() && value == null ) {
+            final Properties p = (Properties)this.properties.get(i);
+            value = p.getProperty(key);
+            i++;
+        }
+        if ( value == null ) {
+            value = defaultValue;
+        }
+        return value;
     }
 }

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java?view=diff&r1=149416&r2=149417
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java (original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java Tue Feb  1 09:01:45 2005
@@ -20,13 +20,21 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.avalon.framework.CascadingRuntimeException;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.cocoon.configuration.Settings;
+
 /**
  * The Core
  * 
- * @version SVN $Id:$
+ * @version SVN $Id$
  */
 public class Core {
 
+    /** Application <code>Context</code> Key for the settings @since 2.2 */
+    public static final String CONTEXT_SETTINGS = "settings";
+
     private static final ThreadLocal cleanup = new InheritableThreadLocal();
     
     public static void addCleanupTask(CleanupTask task) {
@@ -49,8 +57,25 @@
             l.clear();
         }
     }
+    
     public static interface CleanupTask {
         
         void invoke();
     }
+    
+    /**
+     * Return the current response
+     * @param context The component context
+     * @return The response
+     * @since 2.2
+     */
+    public static final Settings getSettings(Context context) {
+        // the settings object is always present
+        try {
+            return (Settings)context.get(CONTEXT_SETTINGS);
+        } catch (ContextException ce) {
+            throw new CascadingRuntimeException("Unable to get the settings object from the
context.", ce);
+        }
+    }
+    
 }

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentEnvironment.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentEnvironment.java?view=diff&r1=149416&r2=149417
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentEnvironment.java
(original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentEnvironment.java
Tue Feb  1 09:01:45 2005
@@ -25,6 +25,8 @@
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.cocoon.components.ComponentInfo;
 import org.apache.cocoon.configuration.ConfigurationBuilder;
+import org.apache.cocoon.configuration.Settings;
+import org.apache.cocoon.core.Core;
 
 /**
  * The component enviromnent contains all objects necessary to create
@@ -71,7 +73,8 @@
         ComponentInfo ci = null;
         final InputStream is = this.classLoader.getResourceAsStream(bu.toString());
         if ( is != null ) {
-            final ConfigurationBuilder cb = new ConfigurationBuilder();
+            final Settings settings = Core.getSettings(this.context);
+            final ConfigurationBuilder cb = new ConfigurationBuilder(settings);
             final Configuration conf = cb.build(is);
             ci = new ComponentInfo();
             ci.fill(conf);

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CoreServiceManager.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CoreServiceManager.java?view=diff&r1=149416&r2=149417
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CoreServiceManager.java (original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CoreServiceManager.java Tue
Feb  1 09:01:45 2005
@@ -44,6 +44,8 @@
 import org.apache.avalon.framework.thread.ThreadSafe;
 import org.apache.cocoon.components.ComponentInfo;
 import org.apache.cocoon.configuration.ConfigurationBuilder;
+import org.apache.cocoon.configuration.Settings;
+import org.apache.cocoon.core.Core;
 import org.apache.cocoon.core.container.handler.AbstractComponentHandler;
 import org.apache.cocoon.core.container.handler.AliasComponentHandler;
 import org.apache.cocoon.core.container.handler.ComponentHandler;
@@ -715,7 +717,8 @@
                 // load it and store it in the read set
                 Configuration includeConfig = null;
                 try {
-                    ConfigurationBuilder builder = new ConfigurationBuilder();
+                    final Settings settings = Core.getSettings(context);
+                    ConfigurationBuilder builder = new ConfigurationBuilder(settings);
                     includeConfig = builder.build(src.getInputStream(), uri);
                 } catch (ConfigurationException ce) {
                     throw ce;

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/util/PropertyHelper.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/core/container/util/PropertyHelper.java?view=diff&r1=149416&r2=149417
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/util/PropertyHelper.java (original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/util/PropertyHelper.java Tue
Feb  1 09:01:45 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.cocoon.core.container.util;
 
+import org.apache.cocoon.configuration.Settings;
+
 /**
  * Helper class for replacing property references with the value of the
  * property
@@ -24,11 +26,11 @@
  */
 public class PropertyHelper {
 
-    /**
+        /**
      * Replace all property references in the string with the current value
      * and return it.
      */
-    public static String replace(String value) {
+    public static String replace(String value, Settings settings) {
         // quick test for null or no references
         if ( value == null || value.indexOf("${") == -1 ) {
             return value;
@@ -64,7 +66,7 @@
                     prev = value.length();
                 } else {
                     final String propertyName = value.substring(pos + 2, endName);
-                    String propertyValue = getProperty(propertyName);
+                    String propertyValue = getProperty(propertyName, settings);
                     // compatibility fallback - if the value is null, just readd token
                     if (propertyValue == null) {
                         buffer.append("${");
@@ -85,7 +87,14 @@
         return buffer.toString();
     }
 
-    static String getProperty(String name) {
-        return System.getProperty(name);    
+    static String getProperty(String name, Settings settings) {
+        String value = null;
+        if ( settings != null ) {
+            value = settings.getProperty(name);
+        }
+        if ( value == null ) {
+            value = System.getProperty(name);
+        }
+        return value;
     }
 }

Modified: cocoon/trunk/src/core/test/org/apache/cocoon/core/container/util/PropertyHelperTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/test/org/apache/cocoon/core/container/util/PropertyHelperTestCase.java?view=diff&r1=149416&r2=149417
==============================================================================
--- cocoon/trunk/src/core/test/org/apache/cocoon/core/container/util/PropertyHelperTestCase.java
(original)
+++ cocoon/trunk/src/core/test/org/apache/cocoon/core/container/util/PropertyHelperTestCase.java
Tue Feb  1 09:01:45 2005
@@ -31,11 +31,11 @@
         final String testC = "and this is the } end token";
         final String testD = "${this.does.not.exists}";
         // some tests for not! replacing
-        assertEquals(PropertyHelper.replace(testA), testA);
-        assertEquals(PropertyHelper.replace(testB), testB);
-        assertEquals(PropertyHelper.replace(testC), testC);
-        assertEquals(PropertyHelper.replace(testD), testD);
+        assertEquals(PropertyHelper.replace(testA, null), testA);
+        assertEquals(PropertyHelper.replace(testB, null), testB);
+        assertEquals(PropertyHelper.replace(testC, null), testC);
+        assertEquals(PropertyHelper.replace(testD, null), testD);
         // and finally we have something to replace
-        assertEquals(PropertyHelper.replace("${java.home}"), System.getProperty("java.home"));
+        assertEquals(PropertyHelper.replace("${java.home}", null), System.getProperty("java.home"));
     }
 }

Modified: cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java?view=diff&r1=149416&r2=149417
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java Tue Feb  1 09:01:45 2005
@@ -42,6 +42,8 @@
 import org.apache.cocoon.components.source.SourceUtil;
 import org.apache.cocoon.components.source.impl.DelayedRefreshSourceWrapper;
 import org.apache.cocoon.configuration.ConfigurationBuilder;
+import org.apache.cocoon.configuration.Settings;
+import org.apache.cocoon.core.Core;
 import org.apache.cocoon.core.container.RoleManager;
 import org.apache.cocoon.environment.Environment;
 import org.apache.cocoon.environment.ObjectModelHelper;
@@ -251,7 +253,8 @@
     private void configure() throws Exception {
         InputSource is = SourceUtil.getInputSource(this.configurationFile);
 
-        ConfigurationBuilder builder = new ConfigurationBuilder();
+        final Settings settings = Core.getSettings(context);
+        ConfigurationBuilder builder = new ConfigurationBuilder(settings);
         Configuration conf = builder.build(is);
 
         if (getLogger().isDebugEnabled()) {

Modified: cocoon/trunk/src/java/org/apache/cocoon/bean/CocoonWrapper.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/bean/CocoonWrapper.java?view=diff&r1=149416&r2=149417
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/bean/CocoonWrapper.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/bean/CocoonWrapper.java Tue Feb  1 09:01:45 2005
@@ -43,6 +43,8 @@
 import org.apache.cocoon.Constants;
 import org.apache.cocoon.ProcessingException;
 import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.configuration.Settings;
+import org.apache.cocoon.core.Core;
 import org.apache.cocoon.environment.Environment;
 import org.apache.cocoon.environment.commandline.CommandLineContext;
 import org.apache.cocoon.environment.commandline.FileSavingEnvironment;
@@ -158,6 +160,8 @@
             appContext.put(Constants.CONTEXT_CONFIG_URL, conf.toURL());
             appContext.put(Constants.CONTEXT_DEFAULT_ENCODING, "ISO-8859-1");
             appContext.put(ContextHelper.CONTEXT_ROOT_URL, this.context.toURL().toExternalForm());
+            // FIXME - add settings
+            appContext.put(Core.CONTEXT_SETTINGS, new Settings());
 
             loadClasses(classList);
 

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/ContextHelper.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/ContextHelper.java?view=diff&r1=149416&r2=149417
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/ContextHelper.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/ContextHelper.java Tue Feb  1 09:01:45
2005
@@ -112,4 +112,5 @@
             throw new CascadingRuntimeException("Unable to get the service manager from the
context.", ce);
         }        
     }
+
 }

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/container/LoggingHelper.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/container/LoggingHelper.java?view=diff&r1=149416&r2=149417
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/container/LoggingHelper.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/container/LoggingHelper.java Tue Feb
 1 09:01:45 2005
@@ -114,7 +114,7 @@
                 Source source = null;
                 try {
                     source = resolver.resolveURI(logkitConfig);
-                    final ConfigurationBuilder builder = new ConfigurationBuilder();
+                    final ConfigurationBuilder builder = new ConfigurationBuilder(settings);
                     final Configuration conf = builder.build(source.getInputStream());
                     final DefaultConfiguration categories = (DefaultConfiguration)conf.getChild("categories");
                     final DefaultConfiguration targets = (DefaultConfiguration)conf.getChild("targets");

Modified: cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java?view=diff&r1=149416&r2=149417
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java Tue Feb  1 09:01:45
2005
@@ -59,6 +59,7 @@
 import org.apache.cocoon.components.notification.Notifier;
 import org.apache.cocoon.components.notification.Notifying;
 import org.apache.cocoon.configuration.Settings;
+import org.apache.cocoon.core.Core;
 import org.apache.cocoon.environment.Environment;
 import org.apache.cocoon.environment.http.HttpContext;
 import org.apache.cocoon.environment.http.HttpEnvironment;
@@ -230,6 +231,7 @@
 
         // initialize settings
         this.settings = this.getSettings();
+        this.appContext.put(Core.CONTEXT_SETTINGS, this.settings);
         
         if (this.settings.isInitClassloader()) {
             // Force context classloader so that JAXP can work correctly
@@ -427,6 +429,7 @@
             try {
                 Thread.currentThread().setContextClassLoader(this.classLoader);
             } catch (Exception e) {
+                // ignore this
             }
         }
 



Mime
View raw message