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 2006/08/28 22:16:50 UTC

svn commit: r437810 - /cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/

Author: cziegeler
Date: Mon Aug 28 13:16:45 2006
New Revision: 437810

URL: http://svn.apache.org/viewvc?rev=437810&view=rev
Log:
Create abstract base class

Added:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AbstractSettingsBeanFactoryPostProcessor.java   (with props)
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java   (with props)
Modified:
    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

Added: 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=437810&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AbstractSettingsBeanFactoryPostProcessor.java (added)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AbstractSettingsBeanFactoryPostProcessor.java Mon Aug 28 13:16:45 2006
@@ -0,0 +1,254 @@
+/* 
+ * 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.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.core.container.spring;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import javax.servlet.ServletContext;
+
+import org.apache.cocoon.configuration.Settings;
+import org.apache.cocoon.configuration.impl.MutableSettings;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanDefinitionStoreException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.BeanDefinitionVisitor;
+import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.web.context.ServletContextAware;
+import org.springframework.web.context.support.ServletContextResourceLoader;
+
+/**
+ * This is a bean factory post processor which handles all the settings stuff
+ * for Cocoon. It reads in all properties files and replaces references to
+ * them in the spring configuration files.
+ * In addition this bean acts as a factory bean providing the settings object.
+ * @see SettingsBeanFactoryPostProcessor
+ * @see SubSettingsBeanFactoryPostProcessor
+ *
+ * @since 2.2
+ * @version $Id$
+ */
+public abstract class AbstractSettingsBeanFactoryPostProcessor
+    extends PropertyPlaceholderConfigurer
+    implements ServletContextAware, BeanFactoryPostProcessor, FactoryBean {
+
+    /** Logger (we use the same logging mechanism as Spring!) */
+    protected final Log logger = LogFactory.getLog(getClass());
+
+    protected ServletContext servletContext;
+
+    protected MutableSettings settings;
+
+    protected BeanFactory beanFactory;
+
+    /**
+     * @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#setBeanFactory(org.springframework.beans.factory.BeanFactory)
+     */
+    public void setBeanFactory(BeanFactory factory) {
+        super.setBeanFactory(factory);
+        this.beanFactory = factory;
+    }
+
+    /**
+     * @see org.springframework.web.context.ServletContextAware#setServletContext(javax.servlet.ServletContext)
+     */
+    public void setServletContext(ServletContext sContext) {
+        this.servletContext = sContext;
+    }
+
+    /**
+     * This method can be overwritten by subclasses to further initialize the settings
+     */
+    protected void doInit() {
+        // nothing to do here
+    }
+
+    /**
+     * Read all property files from the given directory and apply them to the settings.
+     */
+    protected void readProperties(String          directoryName,
+                                  Properties      properties) {
+        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.servletContext.log("Unable to read properties from directory '" + directoryName + "' - Continuing initialization.");
+            this.logger.debug("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]);
+            }
+            // sort
+            Collections.sort(propertyUris, this.getResourceComparator());
+            // now process
+            final Iterator i = propertyUris.iterator();
+            while ( i.hasNext() ) {
+                Resource src = (Resource)i.next();
+                try {
+                    final InputStream propsIS = src.getInputStream();
+                    this.servletContext.log("Reading settings from '" + src.getURL() + "'.");
+                    properties.load(propsIS);
+                    propsIS.close();
+                } catch (IOException ignore) {
+                    this.servletContext.log("Unable to read properties from file '" + src.getDescription() + "' - Continuing initialization.");
+                    this.logger.debug("Unable to read properties from file '" + src.getDescription() + "' - Continuing initialization.", ignore);
+                }
+            }
+        }
+    }
+
+    /**
+     * Return a resource comparator
+     */
+    protected Comparator getResourceComparator() {
+        return new ResourceComparator();
+    }
+
+    protected String getSystemProperty(String key) {
+        return this.getSystemProperty(key, null);
+    }
+
+    protected String getSystemProperty(String key, String defaultValue) {
+        try {
+            return System.getProperty(key, defaultValue);
+        } catch (SecurityException se) {
+            // we ignore this
+            return defaultValue;
+        }
+    }
+
+    protected final static class ResourceComparator implements Comparator {
+
+        /**
+         * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+         */
+        public int compare(Object o1, Object o2) {
+            if ( !(o1 instanceof Resource) || !(o2 instanceof Resource)) {
+                return 0;
+            }
+            return ((Resource)o1).getFilename().compareTo(((Resource)o2).getFilename());
+        }
+    }
+
+    /**
+     * @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#processProperties(org.springframework.beans.factory.config.ConfigurableListableBeanFactory, java.util.Properties)
+     */
+    protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
+                                     Properties props)
+    throws BeansException {
+        final BeanDefinitionVisitor visitor = new CocoonSettingsResolvingBeanDefinitionVisitor(this.settings);
+        String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
+        for (int i = 0; i < beanNames.length; i++) {
+            BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(beanNames[i]);
+            try {
+                visitor.visitBeanDefinition(bd);
+            } catch (BeanDefinitionStoreException ex) {
+                throw new BeanDefinitionStoreException(bd
+                        .getResourceDescription(), beanNames[i], ex
+                        .getMessage());
+            }
+        }
+    }
+
+    protected class CocoonSettingsResolvingBeanDefinitionVisitor
+        extends BeanDefinitionVisitor {
+
+        protected final Properties props;
+
+        public CocoonSettingsResolvingBeanDefinitionVisitor(Settings settings) {
+            this.props = new SettingsProperties(settings);
+        }
+
+        protected String resolveStringValue(String strVal) {
+            return parseStringValue(strVal, this.props, null);
+        }
+    }
+
+    /**
+     * Dump the settings object
+     */
+    protected void dumpSettings() {
+        if ( this.logger.isDebugEnabled() ) {
+            this.logger.debug("===== Settings Start =====");
+            this.logger.debug(this.settings.toString());
+            this.logger.debug("===== Settings End =====");
+        }
+    }
+
+    protected static class SettingsProperties extends Properties {
+
+        protected final Settings settings;
+
+        public SettingsProperties(Settings s) {
+            this.settings = s;
+        }
+
+        /**
+         * @see java.util.Properties#getProperty(java.lang.String, java.lang.String)
+         */
+        public String getProperty(String key, String defaultValue) {
+            return this.settings.getProperty(key, defaultValue);
+        }
+
+        /**
+         * @see java.util.Properties#getProperty(java.lang.String)
+         */
+        public String getProperty(String key) {
+            return this.settings.getProperty(key);
+        }
+        
+    }
+
+    /**
+     * @see org.springframework.beans.factory.FactoryBean#getObject()
+     */
+    public Object getObject() throws Exception {
+        return this.settings;
+    }
+
+    /**
+     * @see org.springframework.beans.factory.FactoryBean#getObjectType()
+     */
+    public Class getObjectType() {
+        return Settings.class;
+    }
+
+    /**
+     * @see org.springframework.beans.factory.FactoryBean#isSingleton()
+     */
+    public boolean isSingleton() {
+        return true;
+    }
+}

Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AbstractSettingsBeanFactoryPostProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/AbstractSettingsBeanFactoryPostProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java?rev=437810&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java (added)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java Mon Aug 28 13:16:45 2006
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.core.container.spring;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.core.io.Resource;
+import org.springframework.web.context.support.XmlWebApplicationContext;
+
+/**
+ * Own implementation of a {@link XmlWebApplicationContext} which is configured with
+ * a base url specifying the root directory for this web application context.
+ *
+ * @since 2.2
+ * @version $Id$
+ */
+public class CocoonWebApplicationContext extends XmlWebApplicationContext {
+
+    protected String baseUrl;
+
+    public CocoonWebApplicationContext(ApplicationContext parent, String url) {
+        this.setParent(parent);
+        this.baseUrl = url;
+    }
+
+    /**
+     * @see org.springframework.web.context.support.AbstractRefreshableWebApplicationContext#getResourceByPath(java.lang.String)
+     */
+    protected Resource getResourceByPath(String path) {
+        // TODO
+        return super.getResourceByPath(path);
+    }
+}

Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java
------------------------------------------------------------------------------
    svn:keywords = Id

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=437810&r1=437809&r2=437810&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 Mon Aug 28 13:16:45 2006
@@ -19,17 +19,10 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
 import java.util.Enumeration;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Properties;
 
-import javax.servlet.ServletContext;
-
 import org.apache.cocoon.Constants;
 import org.apache.cocoon.configuration.PropertyProvider;
 import org.apache.cocoon.configuration.Settings;
@@ -37,21 +30,6 @@
 import org.apache.cocoon.configuration.impl.MutableSettings;
 import org.apache.cocoon.configuration.impl.PropertyHelper;
 import org.apache.cocoon.util.ClassUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.BeanDefinitionStoreException;
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.FactoryBean;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.config.BeanDefinitionVisitor;
-import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
-import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
-import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.web.context.ServletContextAware;
-import org.springframework.web.context.support.ServletContextResourceLoader;
 
 /**
  * This is a bean factory post processor which handles all the settings stuff
@@ -63,32 +41,7 @@
  * @version $Id$
  */
 public class SettingsBeanFactoryPostProcessor
-    extends PropertyPlaceholderConfigurer
-    implements ServletContextAware, BeanFactoryPostProcessor, FactoryBean {
-
-    /** Logger (we use the same logging mechanism as Spring!) */
-    protected final Log logger = LogFactory.getLog(getClass());
-
-    protected ServletContext servletContext;
-
-    protected MutableSettings settings;
-
-    protected BeanFactory beanFactory;
-
-    /**
-     * @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#setBeanFactory(org.springframework.beans.factory.BeanFactory)
-     */
-    public void setBeanFactory(BeanFactory factory) {
-        super.setBeanFactory(factory);
-        this.beanFactory = factory;
-    }
-
-    /**
-     * @see org.springframework.web.context.ServletContextAware#setServletContext(javax.servlet.ServletContext)
-     */
-    public void setServletContext(ServletContext sContext) {
-        this.servletContext = sContext;
-    }
+    extends AbstractSettingsBeanFactoryPostProcessor {
 
     /**
      * Initialize this processor.
@@ -112,13 +65,6 @@
     }
 
     /**
-     * This method can be overwritten by subclasses to further initialize the settings
-     */
-    protected void doInit() {
-        // nothing to do here
-    }
-
-    /**
      * Init work, upload and cache directory
      * @param settings 
      * @param log 
@@ -225,9 +171,9 @@
         final Properties properties = new Properties();
 
         // now read all properties from the properties directory
-        readProperties("/WEB-INF/cocoon/properties", s, properties);
+        readProperties("/WEB-INF/cocoon/properties", properties);
         // read all properties from the mode dependent directory
-        readProperties("/WEB-INF/cocoon/properties/" + mode, s, properties);
+        readProperties("/WEB-INF/cocoon/properties/" + mode, properties);
 
         // fill from the servlet context
         if ( s.getWorkDirectory() == null ) {
@@ -293,111 +239,6 @@
     }
 
     /**
-     * Read all property files from the given directory and apply them to the settings.
-     */
-    protected void readProperties(String          directoryName,
-                                  Settings        s,
-                                  Properties      properties) {
-        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.servletContext.log("Unable to read properties from directory '" + directoryName + "' - Continuing initialization.");
-            this.logger.debug("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]);
-            }
-            // sort
-            Collections.sort(propertyUris, this.getResourceComparator());
-            // now process
-            final Iterator i = propertyUris.iterator();
-            while ( i.hasNext() ) {
-                Resource src = (Resource)i.next();
-                try {
-                    final InputStream propsIS = src.getInputStream();
-                    this.servletContext.log("Reading settings from '" + src.getURL() + "'.");
-                    properties.load(propsIS);
-                    propsIS.close();
-                } catch (IOException ignore) {
-                    this.servletContext.log("Unable to read properties from file '" + src.getDescription() + "' - Continuing initialization.");
-                    this.logger.debug("Unable to read properties from file '" + src.getDescription() + "' - Continuing initialization.", ignore);
-                }
-            }
-        }
-    }
-
-    /**
-     * Return a resource comparator
-     */
-    protected Comparator getResourceComparator() {
-        return new ResourceComparator();
-    }
-
-    protected static String getSystemProperty(String key) {
-        return getSystemProperty(key, null);
-    }
-
-    protected static String getSystemProperty(String key, String defaultValue) {
-        try {
-            return System.getProperty(key, defaultValue);
-        } catch (SecurityException se) {
-            // we ignore this
-            return defaultValue;
-        }
-    }
-
-    protected final static class ResourceComparator implements Comparator {
-
-        /**
-         * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
-         */
-        public int compare(Object o1, Object o2) {
-            if ( !(o1 instanceof Resource) || !(o2 instanceof Resource)) {
-                return 0;
-            }
-            return ((Resource)o1).getFilename().compareTo(((Resource)o2).getFilename());
-        }
-    }
-
-    /**
-     * @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#processProperties(org.springframework.beans.factory.config.ConfigurableListableBeanFactory, java.util.Properties)
-     */
-    protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
-                                     Properties props)
-    throws BeansException {
-        final BeanDefinitionVisitor visitor = new CocoonSettingsResolvingBeanDefinitionVisitor(this.settings);
-        String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
-        for (int i = 0; i < beanNames.length; i++) {
-            BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(beanNames[i]);
-            try {
-                visitor.visitBeanDefinition(bd);
-            } catch (BeanDefinitionStoreException ex) {
-                throw new BeanDefinitionStoreException(bd
-                        .getResourceDescription(), beanNames[i], ex
-                        .getMessage());
-            }
-        }
-    }
-
-    protected class CocoonSettingsResolvingBeanDefinitionVisitor
-        extends BeanDefinitionVisitor {
-
-        protected final Properties props;
-
-        public CocoonSettingsResolvingBeanDefinitionVisitor(Settings settings) {
-            this.props = new SettingsProperties(settings);
-        }
-
-        protected String resolveStringValue(String strVal) {
-            return parseStringValue(strVal, this.props, null);
-        }
-    }
-    /**
      * Dump System Properties.
      */
     protected void dumpSystemProperties() {
@@ -417,17 +258,6 @@
     }
 
     /**
-     * Dump the settings object
-     */
-    protected void dumpSettings() {
-        if ( this.logger.isDebugEnabled() ) {
-            this.logger.debug("===== Settings Start =====");
-            this.logger.debug(this.settings.toString());
-            this.logger.debug("===== Settings End =====");
-        }
-    }
-
-    /**
      * Handle the <code>load-class</code> settings. This overcomes
      * limits in many classpath issues. One of the more notorious
      * ones is a bug in WebSphere that does not load the URL handler
@@ -455,50 +285,5 @@
                 // Do not throw an exception, because it is not a fatal error.
             }
         }
-    }
-
-    protected static class SettingsProperties extends Properties {
-
-        protected final Settings settings;
-
-        public SettingsProperties(Settings s) {
-            this.settings = s;
-        }
-
-        /**
-         * @see java.util.Properties#getProperty(java.lang.String, java.lang.String)
-         */
-        public String getProperty(String key, String defaultValue) {
-            return this.settings.getProperty(key, defaultValue);
-        }
-
-        /**
-         * @see java.util.Properties#getProperty(java.lang.String)
-         */
-        public String getProperty(String key) {
-            return this.settings.getProperty(key);
-        }
-        
-    }
-
-    /**
-     * @see org.springframework.beans.factory.FactoryBean#getObject()
-     */
-    public Object getObject() throws Exception {
-        return this.settings;
-    }
-
-    /**
-     * @see org.springframework.beans.factory.FactoryBean#getObjectType()
-     */
-    public Class getObjectType() {
-        return Settings.class;
-    }
-
-    /**
-     * @see org.springframework.beans.factory.FactoryBean#isSingleton()
-     */
-    public boolean isSingleton() {
-        return true;
     }
 }

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=437810&r1=437809&r2=437810&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 Mon Aug 28 13:16:45 2006
@@ -18,19 +18,11 @@
 
 import java.util.Properties;
 
-import javax.servlet.ServletContext;
-
 import org.apache.cocoon.configuration.Settings;
 import org.apache.cocoon.configuration.impl.MutableSettings;
 import org.apache.cocoon.configuration.impl.PropertyHelper;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.FactoryBean;
 import org.springframework.beans.factory.HierarchicalBeanFactory;
-import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
-import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
-import org.springframework.web.context.ServletContextAware;
 
 /**
  * This is a bean factory post processor which sets up a child settings object.
@@ -39,32 +31,13 @@
  * @version $Id$
  */
 public class SubSettingsBeanFactoryPostProcessor
-    extends PropertyPlaceholderConfigurer
-    implements ServletContextAware, BeanFactoryPostProcessor, FactoryBean {
-
-    /** Logger (we use the same logging mechanism as Spring!) */
-    protected final Log logger = LogFactory.getLog(getClass());
+    extends AbstractSettingsBeanFactoryPostProcessor {
 
-    protected ServletContext servletContext;
+    private static final String DEFAULT_CONFIG_PROPERTIES = "config/properties";
 
-    protected MutableSettings settings;
+    private static final String DEFAULT_CONFIG_XCONF  = "config/xconf";
 
-    protected BeanFactory beanFactory;
-
-    /**
-     * @see org.springframework.web.context.ServletContextAware#setServletContext(javax.servlet.ServletContext)
-     */
-    public void setServletContext(ServletContext sContext) {
-        this.servletContext = sContext;
-    }
-
-    /**
-     * @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#setBeanFactory(org.springframework.beans.factory.BeanFactory)
-     */
-    public void setBeanFactory(BeanFactory factory) {
-        super.setBeanFactory(factory);
-        this.beanFactory = factory;
-    }
+    private static final String DEFAULT_CONFIG_SPRING = "config/spring";
 
     /**
      * Initialize this processor.
@@ -133,16 +106,16 @@
 
         // read properties from default includes
         if ( useDefaultIncludes ) {
-//            SettingsHelper.readProperties(SitemapLanguage.DEFAULT_CONFIG_PROPERTIES, s, properties);
+            this.readProperties(DEFAULT_CONFIG_PROPERTIES, properties);
             // read all properties from the mode dependent directory
-//            SettingsHelper.readProperties(SitemapLanguage.DEFAULT_CONFIG_PROPERTIES + '/' + mode, s, properties);    
+            this.readProperties(DEFAULT_CONFIG_PROPERTIES + '/' + mode, properties);    
         }
 
         if ( directory != null ) {
             // now read all properties from the properties directory
- //           SettingsHelper.readProperties(directory, s, properties);
+            this.readProperties(directory, properties);
             // read all properties from the mode dependent directory
- //           SettingsHelper.readProperties(directory + '/' + mode, s, properties);
+            this.readProperties(directory + '/' + mode, properties);
         }
 
         if ( globalSitemapVariables != null ) {
@@ -152,33 +125,5 @@
         s.configure(properties);
 
         return s;
-    }
-
-    /**
-     * This method can be overwritten by subclasses to further initialize the settings
-     */
-    protected void doInit() {
-        // nothing to do here
-    }
-
-    /**
-     * @see org.springframework.beans.factory.FactoryBean#getObject()
-     */
-    public Object getObject() throws Exception {
-        return this.settings;
-    }
-
-    /**
-     * @see org.springframework.beans.factory.FactoryBean#getObjectType()
-     */
-    public Class getObjectType() {
-        return Settings.class;
-    }
-
-    /**
-     * @see org.springframework.beans.factory.FactoryBean#isSingleton()
-     */
-    public boolean isSingleton() {
-        return true;
     }
 }