cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r439605 - in /cocoon/trunk: blocks/cocoon-hsqldb/cocoon-hsqldb-impl/src/main/resources/META-INF/properties/ core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ core/cocoon-core/src/main/java/org/apache/cocoon/core/contai...
Date Sat, 02 Sep 2006 15:01:31 GMT
Author: cziegeler
Date: Sat Sep  2 08:01:31 2006
New Revision: 439605

URL: http://svn.apache.org/viewvc?rev=439605&view=rev
Log:
Fix property handling
Fix logging behaviour
Clean up

Added:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ComponentContext.java
      - copied, changed from r439550, cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/util/ComponentContext.java
Removed:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/util/ComponentContext.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/util/SimpleSourceResolver.java
Modified:
    cocoon/trunk/blocks/cocoon-hsqldb/cocoon-hsqldb-impl/src/main/resources/META-INF/properties/hsqldb.properties
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AbstractSettingsBeanFactoryPostProcessor.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ConfigReader.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SubSettingsBeanFactoryPostProcessor.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonContextFactoryBean.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonUtils.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/osgi/OSGiSpringECMFactory.java

Modified: cocoon/trunk/blocks/cocoon-hsqldb/cocoon-hsqldb-impl/src/main/resources/META-INF/properties/hsqldb.properties
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-hsqldb/cocoon-hsqldb-impl/src/main/resources/META-INF/properties/hsqldb.properties?rev=439605&r1=439604&r2=439605&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-hsqldb/cocoon-hsqldb-impl/src/main/resources/META-INF/properties/hsqldb.properties
(original)
+++ cocoon/trunk/blocks/cocoon-hsqldb/cocoon-hsqldb-impl/src/main/resources/META-INF/properties/hsqldb.properties
Sat Sep  2 08:01:31 2006
@@ -12,4 +12,4 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 org.apache.cocoon.hsqldb.server.port=9002
-org.apache.cocoon.hsqldb.server.db.path=context://WEB-INF/db"
\ No newline at end of file
+org.apache.cocoon.hsqldb.server.db.path=context://WEB-INF/db
\ No newline at end of file

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AbstractSettingsBeanFactoryPostProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AbstractSettingsBeanFactoryPostProcessor.java?rev=439605&r1=439604&r2=439605&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AbstractSettingsBeanFactoryPostProcessor.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AbstractSettingsBeanFactoryPostProcessor.java
Sat Sep  2 08:01:31 2006
@@ -40,8 +40,11 @@
 import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
 import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
+import org.springframework.context.ResourceLoaderAware;
 import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
 import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.core.io.support.ResourcePatternResolver;
 import org.springframework.web.context.ServletContextAware;
 import org.springframework.web.context.support.ServletContextResourceLoader;
 
@@ -58,7 +61,7 @@
  */
 public abstract class AbstractSettingsBeanFactoryPostProcessor
     extends PropertyPlaceholderConfigurer
-    implements ServletContextAware, BeanFactoryPostProcessor, FactoryBean {
+    implements ServletContextAware, BeanFactoryPostProcessor, ResourceLoaderAware, FactoryBean
{
 
     /** Logger (we use the same logging mechanism as Spring!) */
     protected final Log logger = LogFactory.getLog(getClass());
@@ -69,6 +72,8 @@
 
     protected BeanFactory beanFactory;
 
+    protected ResourceLoader resourceLoader;
+
     /**
      * @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#setBeanFactory(org.springframework.beans.factory.BeanFactory)
      */
@@ -85,12 +90,30 @@
     }
 
     /**
+     * @see org.springframework.context.ResourceLoaderAware#setResourceLoader(org.springframework.core.io.ResourceLoader)
+     */
+    public void setResourceLoader(ResourceLoader loader) {
+        this.resourceLoader = loader;
+    }
+
+    /**
      * This method can be overwritten by subclasses to further initialize the settings
      */
     protected void doInit() {
         // nothing to do here
     }
 
+    protected ResourceLoader getResourceLoader() {
+        if ( this.resourceLoader != null ) {
+            return this.resourceLoader;
+        }
+        return new ServletContextResourceLoader(this.servletContext);
+    }
+
+    protected ResourcePatternResolver getResourceResolver() {
+        return new PathMatchingResourcePatternResolver(this.getResourceLoader());
+    }
+
     /**
      * Read all property files from the given directory and apply them to the settings.
      */
@@ -99,36 +122,45 @@
         if ( this.logger.isDebugEnabled() ) {
             this.logger.debug("Reading settings from directory: " + directoryName);
         }
-        final String pattern = directoryName + "/*.properties";
-        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(new
ServletContextResourceLoader(this.servletContext));
-        Resource[] resources = null;
-        try {
-            resources = resolver.getResources(pattern);
-        } catch (IOException ignore) {
-            this.logger.info("Unable to read properties from directory '" + directoryName
+ "' - Continuing initialization.", ignore);
-        }
-        if ( resources != null ) {
-            final List propertyUris = new ArrayList();
-            for(int i=0; i<resources.length; i++ ) {
-                propertyUris.add(resources[i]);
+        // check if directory exists
+        Resource directoryResource = this.getResourceLoader().getResource(directoryName);
+        if ( directoryResource.exists() ) {
+            final String pattern = directoryName + "/*.properties";
+
+            final ResourcePatternResolver resolver = this.getResourceResolver();
+            Resource[] resources = null;
+            try {
+                resources = resolver.getResources(pattern);
+            } catch (IOException ignore) {
+                this.logger.debug("Unable to read properties from directory '" + directoryName
+ "' - Continuing initialization.", ignore);
             }
-            // sort
-            Collections.sort(propertyUris, this.getResourceComparator());
-            // now process
-            final Iterator i = propertyUris.iterator();
-            while ( i.hasNext() ) {
-                Resource src = (Resource)i.next();
-                try {
-                    if ( this.logger.isDebugEnabled() ) {
-                        this.logger.debug("Reading settings from '" + src.getURL() + "'.");
+            if ( resources != null ) {
+                // we process the resources in alphabetical order, so we put
+                // them first into a list, sort them and then read the properties.
+                final List propertyUris = new ArrayList();
+                for(int i=0; i<resources.length; i++ ) {
+                    propertyUris.add(resources[i]);
+                }
+                // sort
+                Collections.sort(propertyUris, this.getResourceComparator());
+                // now process
+                final Iterator i = propertyUris.iterator();
+                while ( i.hasNext() ) {
+                    final Resource src = (Resource)i.next();
+                    try {
+                        if ( this.logger.isDebugEnabled() ) {
+                            this.logger.debug("Reading settings from '" + src.getURL() +
"'.");
+                        }
+                        final InputStream propsIS = src.getInputStream();
+                        properties.load(propsIS);
+                        propsIS.close();
+                    } catch (IOException ignore) {
+                        this.logger.info("Unable to read properties from file '" + src.getDescription()
+ "' - Continuing initialization.", ignore);
                     }
-                    final InputStream propsIS = src.getInputStream();
-                    properties.load(propsIS);
-                    propsIS.close();
-                } catch (IOException ignore) {
-                    this.logger.info("Unable to read properties from file '" + src.getDescription()
+ "' - Continuing initialization.", ignore);
                 }
             }
+        } else {
+            this.logger.debug("Directory '" + directoryName + "' does not exist - Continuing
initialization.");            
         }
     }
 
@@ -206,6 +238,12 @@
         if ( this.logger.isDebugEnabled() ) {
             this.logger.debug("===== Settings Start =====");
             this.logger.debug(this.settings.toString());
+            final List names = this.settings.getPropertyNames();
+            final Iterator i = names.iterator();
+            while ( i.hasNext() ) {
+                final String name = (String)i.next();
+                this.logger.debug("Property: " + name + "=" + this.settings.getProperty(name));
+            }
             this.logger.debug("===== Settings End =====");
         }
     }

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ConfigReader.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ConfigReader.java?rev=439605&r1=439604&r2=439605&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ConfigReader.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ConfigReader.java
Sat Sep  2 08:01:31 2006
@@ -35,7 +35,6 @@
 import org.apache.cocoon.core.container.spring.avalon.ComponentInfo;
 import org.apache.cocoon.core.container.spring.avalon.ConfigurationInfo;
 import org.apache.cocoon.core.container.util.ConfigurationBuilder;
-import org.apache.cocoon.core.container.util.SimpleSourceResolver;
 import org.apache.cocoon.util.WildcardMatcherHelper;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
@@ -68,13 +67,6 @@
     /** Is this the root context? */
     protected final boolean isRootContext;
 
-    public static ConfigurationInfo readConfiguration(String source, AvalonEnvironment env)
-    throws Exception {
-        final ConfigReader converter = new ConfigReader(env, null, null);
-        converter.convert(source);
-        return converter.configInfo;
-    }
-
     public static ConfigurationInfo readConfiguration(Configuration     config,
                                                       ConfigurationInfo parentInfo,
                                                       AvalonEnvironment env,
@@ -99,13 +91,7 @@
                          SourceResolver    resolver)
     throws Exception {
         this.isRootContext = parentInfo == null;
-        if ( resolver != null ) {
-            this.resolver = resolver;
-        } else {
-            this.resolver = new SimpleSourceResolver();
-            ((SimpleSourceResolver)this.resolver).enableLogging(env.logger);
-            ((SimpleSourceResolver)this.resolver).contextualize(env.context);
-        }
+        this.resolver = resolver;
         this.enableLogging(env.logger);
         this.environment = env;
 

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java?rev=439605&r1=439604&r2=439605&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java
Sat Sep  2 08:01:31 2006
@@ -157,7 +157,6 @@
         if ( !Arrays.asList(SettingsDefaults.RUNNING_MODES).contains(mode) ) {
             final String msg =
                 "Invalid running mode: " + mode + " - Use one of: " + Arrays.asList(SettingsDefaults.RUNNING_MODES);
-            servletContext.log(msg);
             throw new IllegalArgumentException(msg);
         }
         */
@@ -186,13 +185,14 @@
             final String fileName = homeDir + File.separator + ".cocoon" + File.separator
+ "settings.properties";
             final File testFile = new File(fileName);
             if ( testFile.exists() ) {
-                servletContext.log("Reading user settings from '" + fileName + "'");
+                if ( this.logger.isDebugEnabled() ) {
+                    this.logger.debug("Reading user settings from '" + fileName + "'");
+                }
                 try {
                     final FileInputStream fis = new FileInputStream(fileName);
                     properties.load(fis);
                 } catch (IOException ignore) {
-                    servletContext.log("Unable to read '" + fileName + "' - continuing with
initialization.");
-                    this.logger.debug("Unable to read '" + fileName + "' - continuing with
initialization.", ignore);
+                    this.logger.info("Unable to read '" + fileName + "' - continuing with
initialization.", ignore);
                 }
             }
         }
@@ -200,14 +200,15 @@
         String additionalPropertyFile = s.getProperty(Settings.PROPERTY_USER_SETTINGS, 
                                                       getSystemProperty(Settings.PROPERTY_USER_SETTINGS));
         if ( additionalPropertyFile != null ) {
-            servletContext.log("Reading user settings from '" + additionalPropertyFile +
"'");
+            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) {
-                servletContext.log("Unable to read '" + additionalPropertyFile + "' - continuing
with initialization.");
-                this.logger.debug("Unable to read '" + additionalPropertyFile + "' - continuing
with initialization.", ignore);
+                this.logger.info("Unable to read '" + additionalPropertyFile + "' - continuing
with initialization.", ignore);
             }
         }
         // check for property providers

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SubSettingsBeanFactoryPostProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SubSettingsBeanFactoryPostProcessor.java?rev=439605&r1=439604&r2=439605&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SubSettingsBeanFactoryPostProcessor.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SubSettingsBeanFactoryPostProcessor.java
Sat Sep  2 08:01:31 2006
@@ -104,7 +104,7 @@
         }
 
         // Next look for a custom property provider in the parent bean factory
-        if (parentBeanFactory != null && parentBeanFactory.containsBean(PropertyProvider.ROLE)
) {
+        if (parentBeanFactory.containsBean(PropertyProvider.ROLE) ) {
             try {
                 final PropertyProvider provider = (PropertyProvider)parentBeanFactory.getBean(PropertyProvider.ROLE);
                 final Properties providedProperties = provider.getProperties(s, mode, this.sitemapUri);

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonContextFactoryBean.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonContextFactoryBean.java?rev=439605&r1=439604&r2=439605&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonContextFactoryBean.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonContextFactoryBean.java
Sat Sep  2 08:01:31 2006
@@ -1,12 +1,12 @@
 /*
  * Copyright 2006 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.
@@ -23,12 +23,13 @@
 import org.apache.avalon.framework.context.DefaultContext;
 import org.apache.cocoon.Constants;
 import org.apache.cocoon.configuration.Settings;
-import org.apache.cocoon.core.container.util.ComponentContext;
 import org.apache.cocoon.environment.http.HttpContext;
 import org.springframework.beans.factory.FactoryBean;
 import org.springframework.web.context.ServletContextAware;
 
 /**
+ * This factory bean sets up the Avalon Context object.
+ * It is part of the Spring bridge for Avalon integration.
  *
  * @since 2.2
  * @version $Id$
@@ -42,6 +43,7 @@
     /** The settings. */
     protected Settings settings;
 
+    /** The Avalon context. */
     protected Context context;
 
     /**
@@ -57,6 +59,9 @@
      */
     protected void init()
     throws Exception {
+        if ( this.settings == null ) {
+            throw new IllegalArgumentException("Settings object is missing.");
+        }
         // create new Avalon context
         final DefaultContext appContext = new ComponentContext();
 
@@ -93,10 +98,10 @@
         return true;
     }
 
-    public Settings getSettings() {
-        return settings;
-    }
-
+    /**
+     * Inject the settings object.
+     * @param settings The settings.
+     */
     public void setSettings(Settings settings) {
         this.settings = settings;
     }

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonUtils.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonUtils.java?rev=439605&r1=439604&r2=439605&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonUtils.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonUtils.java
Sat Sep  2 08:01:31 2006
@@ -36,7 +36,7 @@
     throws ConfigurationException {
         final DefaultConfiguration root = new DefaultConfiguration(tree, true);
         convert(root, settings);
-        return tree;
+        return root;
     }
 
     protected static void convert(DefaultConfiguration config, Settings settings)

Copied: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ComponentContext.java
(from r439550, cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/util/ComponentContext.java)
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ComponentContext.java?p2=cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ComponentContext.java&p1=cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/util/ComponentContext.java&r1=439550&r2=439605&rev=439605&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/util/ComponentContext.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ComponentContext.java
Sat Sep  2 08:01:31 2006
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.cocoon.core.container.util;
+package org.apache.cocoon.core.container.spring.avalon;
 
 import java.util.Map;
 
@@ -37,25 +37,6 @@
     extends DefaultContext {
 
     protected static final String OBJECT_MODEL_KEY_PREFIX = ContextHelper.CONTEXT_OBJECT_MODEL
+ '.';
-
-    /**
-     * Create a Context with specified data and parent.
-     *
-     * @param contextData the context data
-     * @param parent the parent Context (may be null)
-     */
-    public ComponentContext(final Map contextData, final Context parent) {
-        super( contextData, parent );
-    }
-
-    /**
-     * Create a Context with specified data.
-     *
-     * @param contextData the context data
-     */
-    public ComponentContext(final Map contextData) {
-        super( contextData );
-    }
 
     /**
      * Create a Context with specified parent.

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/osgi/OSGiSpringECMFactory.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/osgi/OSGiSpringECMFactory.java?rev=439605&r1=439604&r2=439605&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/osgi/OSGiSpringECMFactory.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/osgi/OSGiSpringECMFactory.java
Sat Sep  2 08:01:31 2006
@@ -125,11 +125,11 @@
 		if (this.parentBeanfactory == null) {
             this.parentBeanfactory =  WebApplicationContextUtils.getWebApplicationContext(osgiServletContext);
         }
-		ConfigurationInfo springBeanConfiguration = ConfigReader.readConfiguration(configFile,
avalonEnvironment);
-		this.beanFactory = BeanFactoryUtil.createBeanFactory(avalonEnvironment, springBeanConfiguration,
-				null, this.parentBeanfactory, false);
-        this.beanFactory.addBeanPostProcessor(new ServiceRegistrationPostProcessor());
-        this.beanFactory.preInstantiateSingletons();
+		//ConfigurationInfo springBeanConfiguration = ConfigReader.readConfiguration(configFile,
avalonEnvironment);
+		//this.beanFactory = BeanFactoryUtil.createBeanFactory(avalonEnvironment, springBeanConfiguration,
+		//		null, this.parentBeanfactory, false);
+        //this.beanFactory.addBeanPostProcessor(new ServiceRegistrationPostProcessor());
+        //this.beanFactory.preInstantiateSingletons();
         // What is this for?
 		//Store store = (Store) beanFactory.getBean(Store.ROLE);
 		//this.logger.debug("Store: " + store);



Mime
View raw message