cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r437365 - in /cocoon/trunk/core/cocoon-core/src/main: java/org/apache/cocoon/components/treeprocessor/sitemap/ java/org/apache/cocoon/core/container/spring/ resources/org/apache/cocoon/core/container/spring/
Date Sun, 27 Aug 2006 11:03:36 GMT
Author: cziegeler
Date: Sun Aug 27 04:03:35 2006
New Revision: 437365

URL: http://svn.apache.org/viewvc?rev=437365&view=rev
Log:
Allow own implementations for customizing settings
Start new implementation for per sitemap factories

Added:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SubSettingsBeanFactoryPostProcessor.java
  (with props)
Modified:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonNamespaceHandler.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/SettingsElementParser.java
    cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/cocoon.xsd

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java?rev=437365&r1=437364&r2=437365&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
Sun Aug 27 04:03:35 2006
@@ -15,8 +15,6 @@
  */
 package org.apache.cocoon.components.treeprocessor.sitemap;
 
-import java.io.IOException;
-import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonNamespaceHandler.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonNamespaceHandler.java?rev=437365&r1=437364&r2=437365&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonNamespaceHandler.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonNamespaceHandler.java
Sun Aug 27 04:03:35 2006
@@ -24,6 +24,8 @@
  * (in the namespace "http://org.apache.cocoon/core"):
  * "settings" : This sets up the Cocoon Settings object (by reading the property
  *              files located under /WEB-INF/cocoon/properties.
+ *              By specifying the attribute "processorClassName" an own implementation
+ *              can be used (this should be a subclass of the {@link SettingsBeanFactoryPostProcessor}).
  *
  * @version $Id$
  * @since 2.2

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=437365&r1=437364&r2=437365&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
Sun Aug 27 04:03:35 2006
@@ -78,20 +78,35 @@
         this.servletContext = sContext;
     }
 
+    /**
+     * Initialize this processor.
+     * Setup the settings object.
+     * @throws Exception
+     */
     public void init()
     throws Exception {
         this.settings = this.createSettings();
-        this.initSettingsFiles();
 
+        this.doInit();
+
+        this.initSettingsFiles();
         // settings can't be changed anymore
         this.settings.makeReadOnly();
 
         this.dumpSystemProperties();
+        this.dumpSettings();
         this.forceLoad();
         this.logger.info("Apache Cocoon " + Constants.VERSION + " is up and ready.");
     }
 
     /**
+     * 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 
@@ -165,18 +180,18 @@
      *    Default values for the core and each block - the order in which the files are read
is not guaranteed.
      * 2) context://WEB-INF/cocoon/properties/[RUNNING_MODE]/*.properties
      *    Default values for the running mode - the order in which the files are read is
not guaranteed.
-     * 4) Working directory from servlet context (if not already set)
-     * 5) Optional property file which is stored under ".cocoon/settings.properties" in the
user
+     * 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.
-     * 6) Additional property file specified by the "org.apache.cocoon.settings" property.
-     * 7) System properties
+     * 5) Additional property file specified by the "org.apache.cocoon.settings" property.
+     * 6) System properties
      *
      * This means that system properties (provided on startup of the web application) override
all
      * others etc.
      *
      * @return A new Settings object
      */
-    public MutableSettings createSettings() {
+    protected MutableSettings createSettings() {
         // get the running mode
         final String mode = getSystemProperty(Settings.PROPERTY_RUNNING_MODE, SettingsDefaults.DEFAULT_RUNNING_MODE);
         
@@ -189,7 +204,7 @@
         }
         */
         
-        servletContext.log("Running in mode: " + mode);
+        this.servletContext.log("Running in mode: " + mode);
 
         // create an empty settings objects
         final MutableSettings s = new MutableSettings(mode);
@@ -253,9 +268,9 @@
     /**
      * Read all property files from the given directory and apply them to the settings.
      */
-    public void readProperties(String          directoryName,
-                               Settings        s,
-                               Properties      properties) {
+    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;
@@ -271,7 +286,7 @@
                 propertyUris.add(resources[i]);
             }
             // sort
-            Collections.sort(propertyUris, getResourceComparator());
+            Collections.sort(propertyUris, this.getResourceComparator());
             // now process
             final Iterator i = propertyUris.iterator();
             while ( i.hasNext() ) {
@@ -292,7 +307,7 @@
     /**
      * Return a resource comparator
      */
-    public static Comparator getResourceComparator() {
+    protected Comparator getResourceComparator() {
         return new ResourceComparator();
     }
 
@@ -371,6 +386,17 @@
             } catch (SecurityException se) {
                 // Ignore Exceptions.
             }
+        }
+    }
+
+    /**
+     * 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 =====");
         }
     }
 

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsElementParser.java?rev=437365&r1=437364&r2=437365&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsElementParser.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsElementParser.java
Sun Aug 27 04:03:35 2006
@@ -23,7 +23,6 @@
 import org.springframework.beans.factory.config.BeanDefinition;
 import org.springframework.beans.factory.config.BeanDefinitionHolder;
 import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
-import org.springframework.beans.factory.support.BeanDefinitionRegistry;
 import org.springframework.beans.factory.support.RootBeanDefinition;
 import org.springframework.beans.factory.xml.BeanDefinitionParser;
 import org.springframework.beans.factory.xml.ParserContext;
@@ -31,6 +30,7 @@
 
 /**
  * Add a bean definition for the settings object to the bean factory.
+ *
  * @see CocoonNamespaceHandler
  * @see SettingsBeanFactoryPostProcessor
  * @version $Id$
@@ -41,30 +41,27 @@
     /** Logger (we use the same logging mechanism as Spring!) */
     protected final Log logger = LogFactory.getLog(getClass());
 
+    /** The name of the configuration attribute to use a different processor class. */
+    public static final String PROCESSOR_CLASS_NAME_ATTR = "processorClassName";
+
     /**
      * @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element,
org.springframework.beans.factory.xml.ParserContext)
      */
     public BeanDefinition parse(Element element, ParserContext parserContext) {
         this.logger.info("Initializing Apache Cocoon " + Constants.VERSION);
-        this.addComponent(SettingsBeanFactoryPostProcessor.class,
-                          Settings.ROLE,
-                          "init",
-                          parserContext.getRegistry());
-        return null;
-    }
-
-    protected void addComponent(Class  componentClass,
-                                String role,
-                                String initMethod,
-                                BeanDefinitionRegistry registry) {
-        RootBeanDefinition beanDef = new RootBeanDefinition();
-        beanDef.setBeanClass(componentClass);      
-        beanDef.setSingleton(true);
-        if ( initMethod != null ) {
-            beanDef.setInitMethodName(initMethod);
+        String componentClassName = SettingsBeanFactoryPostProcessor.class.getName();
+        if ( element.getAttribute(PROCESSOR_CLASS_NAME_ATTR) != null ) {
+            componentClassName = element.getAttribute(PROCESSOR_CLASS_NAME_ATTR);
         }
+        final RootBeanDefinition beanDef = new RootBeanDefinition();
+        beanDef.setBeanClassName(componentClassName);      
+        beanDef.setSingleton(true);
+        beanDef.setLazyInit(false);
+        beanDef.setInitMethodName("init");
         
-        BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDef, role);
-        BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
+        final BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDef, Settings.ROLE);
+        BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());
+
+        return null;
     }
 }

Added: 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=437365&view=auto
==============================================================================
--- 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/SubSettingsBeanFactoryPostProcessor.java
Sun Aug 27 04:03:35 2006
@@ -0,0 +1,184 @@
+/* 
+ * 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.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.
+ *
+ * @since 2.2
+ * @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());
+
+    protected ServletContext servletContext;
+
+    protected MutableSettings settings;
+
+    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;
+    }
+
+    /**
+     * Initialize this processor.
+     * Setup the settings object.
+     * @throws Exception
+     */
+    public void init()
+    throws Exception {
+        this.settings = this.createSettings();
+
+        this.doInit();
+
+        // settings can't be changed anymore
+        this.settings.makeReadOnly();
+
+    }
+
+    protected MutableSettings createSettings() {
+        MutableSettings s;
+        Settings parentSettings = null;
+        final Properties globalSitemapVariables = null;
+        if ( this.beanFactory != null && this.beanFactory instanceof HierarchicalBeanFactory
+             && ((HierarchicalBeanFactory)this.beanFactory).getParentBeanFactory()
!= null ) {
+            parentSettings = (Settings)((HierarchicalBeanFactory)this.beanFactory).getParentBeanFactory().getBean(Settings.ROLE);
+        }
+//        if ( componentConfig != null ) {
+//            final String propertyDir = componentConfig.getAttribute("property-dir", null);
+//            s = this.createSettings(parentSettings, propertyDir, useDefaultIncludes, factory.getCurrentBeanFactory(itsContext),
globalSitemapVariables);
+//        } else if ( globalSitemapVariables != null ) {
+            s = new MutableSettings(parentSettings);
+            PropertyHelper.replaceAll(globalSitemapVariables, parentSettings);
+            s.configure(globalSitemapVariables);
+//        }
+        // if no config we just add an empty settings
+        if ( s == null ) {
+            s = new MutableSettings(parentSettings);
+        }
+        return s;
+    }
+
+    /**
+     * 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) PROPERTYDIR/*.properties
+     *    Default values for the core and each block - the order in which the files are read
is not guaranteed.
+     * 2) PROPERTYDIR/[RUNNING_MODE]/*.properties
+     *    Default values for the running mode - the order in which the files are read is
not guaranteed.
+     * 3) Property providers (ToBeDocumented)
+     *
+     * @return A new Settings object
+     */
+    protected MutableSettings createSettings(Settings    parent,
+                                             String      directory,
+                                             boolean     useDefaultIncludes,
+                                             BeanFactory parentBeanFactory,
+                                             Properties  globalSitemapVariables) {
+        // get the running mode
+        final String mode = parent.getRunningMode();
+        // get properties
+        final Properties properties = new Properties();
+
+        // create an empty settings objects
+        final MutableSettings s = new MutableSettings(parent);
+
+        // read properties from default includes
+        if ( useDefaultIncludes ) {
+//            SettingsHelper.readProperties(SitemapLanguage.DEFAULT_CONFIG_PROPERTIES, s,
properties);
+            // read all properties from the mode dependent directory
+//            SettingsHelper.readProperties(SitemapLanguage.DEFAULT_CONFIG_PROPERTIES + '/'
+ mode, s, properties);    
+        }
+
+        if ( directory != null ) {
+            // now read all properties from the properties directory
+ //           SettingsHelper.readProperties(directory, s, properties);
+            // read all properties from the mode dependent directory
+ //           SettingsHelper.readProperties(directory + '/' + mode, s, properties);
+        }
+
+        if ( globalSitemapVariables != null ) {
+            properties.putAll(globalSitemapVariables);
+        }
+        PropertyHelper.replaceAll(properties, parent);
+        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;
+    }
+}

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

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

Modified: cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/cocoon.xsd
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/cocoon.xsd?rev=437365&r1=437364&r2=437365&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/cocoon.xsd
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/cocoon.xsd
Sun Aug 27 04:03:35 2006
@@ -20,5 +20,7 @@
 
     <xsd:element name="settings" type="tns:settingsType"/>
 
-    <xsd:complexType name="settingsType"/>
+    <xsd:complexType name="settingsType">
+    	<xsd:attribute name="processorClassName" type="xsd:string" use="optional"></xsd:attribute>
+    </xsd:complexType>
 </xsd:schema>



Mime
View raw message