[EMAIL PROTECTED] wrote:
Author: cziegeler
Date: Tue Aug 22 14:08:31 2006
New Revision: 433754

URL: http://svn.apache.org/viewvc?rev=433754&view=rev
Log:
Configure spring context listener for testing
Updates to the avalon configuration readers

Added:
    
cocoon/trunk/core/cocoon-webapp/src/main/webapp/WEB-INF/applicationContext.xml  
 (with props)
Modified:
    
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.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/avalon/ConfigReader.java
    cocoon/trunk/core/cocoon-webapp/src/main/webapp/WEB-INF/web.xml

Modified: 
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java
URL: 
http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java?rev=433754&r1=433753&r2=433754&view=diff
==============================================================================
--- 
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java
 (original)
+++ 
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java
 Tue Aug 22 14:08:31 2006
@@ -33,8 +33,6 @@
 import org.apache.avalon.framework.logger.Logger;
 import org.apache.cocoon.Constants;
 import org.apache.cocoon.components.ContextHelper;
-import org.apache.cocoon.components.source.SourceUtil;
-import org.apache.cocoon.components.source.impl.DelayedRefreshSourceWrapper;
 import org.apache.cocoon.configuration.PropertyProvider;
 import org.apache.cocoon.configuration.Settings;
 import org.apache.cocoon.configuration.impl.MutableSettings;
@@ -44,17 +42,13 @@
 import org.apache.cocoon.core.container.spring.ConfigReader;
 import org.apache.cocoon.core.container.spring.ConfigurationInfo;
 import org.apache.cocoon.core.container.util.ComponentContext;
-import org.apache.cocoon.core.container.util.ConfigurationBuilder;
 import org.apache.cocoon.core.container.util.SimpleSourceResolver;
 import org.apache.cocoon.util.ClassUtils;
 import org.apache.cocoon.util.location.Location;
 import org.apache.cocoon.util.location.LocationImpl;
 import org.apache.cocoon.util.location.LocationUtils;
-import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
-import org.apache.excalibur.source.impl.URLSource;
 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
-import org.xml.sax.InputSource;
/**
  * This is an utility class to create a new Cocoon instance.
@@ -349,25 +343,6 @@
     throws Exception {
         if (log.isInfoEnabled()) {
             log.info("Reading root configuration: " + 
settings.getConfiguration());
-        }
-
-        URLSource urlSource = new URLSource();
-        urlSource.init(new URL(settings.getConfiguration()), null);
-        final Source configurationFile = new 
DelayedRefreshSourceWrapper(urlSource,
-                settings.getReloadDelay("config"));
-        final InputSource is = SourceUtil.getInputSource(configurationFile);
-
-        final ConfigurationBuilder builder = new 
ConfigurationBuilder(settings);
-        final Configuration rootConfig = builder.build(is);
-
-        if (!"cocoon".equals(rootConfig.getName())) {
-            throw new ConfigurationException("Invalid configuration file\n" + 
rootConfig.toString());
-        }
-        if (log.isDebugEnabled()) {
-            log.debug("Configuration version: " + 
rootConfig.getAttribute("version"));
-        }
-        if 
(!Constants.CONF_VERSION.equals(rootConfig.getAttribute("version"))) {
-            throw new ConfigurationException("Invalid configuration schema version. Must be 
'" + Constants.CONF_VERSION + "'.");
         }
if (log.isInfoEnabled()) {

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=433754&r1=433753&r2=433754&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
 Tue Aug 22 14:08:31 2006
@@ -29,6 +29,7 @@
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.cocoon.Constants;
 import org.apache.cocoon.components.source.SourceUtil;
 import org.apache.cocoon.core.container.util.ConfigurationBuilder;
 import org.apache.cocoon.core.container.util.SimpleSourceResolver;
@@ -133,7 +134,16 @@
         try {
             final ConfigurationBuilder b = new 
ConfigurationBuilder(this.environment.settings);
             final Configuration config = 
b.build(SourceUtil.getInputSource(root));
- + // validate cocoon.xconf
+            if (!"cocoon".equals(config.getName())) {
+                throw new ConfigurationException("Invalid configuration 
file\n" + config.toString());
+            }
+            if (this.getLogger().isDebugEnabled()) {
+                this.getLogger().debug("Configuration version: " + 
config.getAttribute("version"));
+            }
+            if 
(!Constants.CONF_VERSION.equals(config.getAttribute("version"))) {
+                throw new ConfigurationException("Invalid configuration schema version. Must 
be '" + Constants.CONF_VERSION + "'.");
+            }
             this.convert(config, null, root.getURI());
} finally {

Modified: 
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigReader.java
URL: 
http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigReader.java?rev=433754&r1=433753&r2=433754&view=diff
==============================================================================
--- 
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigReader.java
 (original)
+++ 
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigReader.java
 Tue Aug 22 14:08:31 2006
@@ -27,7 +27,8 @@
import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.cocoon.core.container.spring.AvalonEnvironment;
+import org.apache.cocoon.Constants;
+import org.apache.cocoon.configuration.Settings;
 import org.apache.cocoon.core.container.spring.ComponentInfo;
 import org.apache.cocoon.core.container.spring.ConfigurationInfo;
 import org.apache.cocoon.core.container.util.ConfigurationBuilder;
@@ -56,40 +57,40 @@
     /** The configuration info. */
     protected final ConfigurationInfo configInfo;
- /** Avalon environment. */
-    protected final AvalonEnvironment environment;
+    /** Settings. */
+    protected final Settings settings;
/** All component configurations. */
     protected final List componentConfigs = new ArrayList();
- public static ConfigurationInfo readConfiguration(String source, AvalonEnvironment env)
+    public static ConfigurationInfo readConfiguration(String source, Settings 
settings)
     throws Exception {
-        final ConfigReader converter = new ConfigReader(env, null, null);
+        final ConfigReader converter = new ConfigReader(settings, null, null);
         converter.convert(source);
         return converter.configInfo;
     }
public static ConfigurationInfo readConfiguration(Configuration config,
                                                       ConfigurationInfo 
parentInfo,
-                                                      AvalonEnvironment env,
+                                                      Settings          
settings,
                                                       ResourceLoader    
resourceLoader)
     throws Exception {
-        return readConfiguration(config, null, parentInfo, env, 
resourceLoader);
+        return readConfiguration(config, null, parentInfo, settings, 
resourceLoader);
     }
 //         PathMatchingResourcePatternResolver resolver = new 
PathMatchingResourcePatternResolver(new 
ServletContextResourceLoader(this.servletContext));
public static ConfigurationInfo readConfiguration(Configuration rolesConfig,
                                                       Configuration     
componentConfig,
                                                       ConfigurationInfo 
parentInfo,
-                                                      AvalonEnvironment env,
+                                                      Settings          
settings,
                                                       ResourceLoader    
resourceLoader)
     throws Exception {
-        final ConfigReader converter = new ConfigReader(env, parentInfo, 
resourceLoader);
+        final ConfigReader converter = new ConfigReader(settings, parentInfo, 
resourceLoader);
         converter.convert(rolesConfig, componentConfig, null);
return converter.configInfo; } - private ConfigReader(AvalonEnvironment env,
+    private ConfigReader(Settings          settings,
                          ConfigurationInfo parentInfo,
                          ResourceLoader    resourceLoader)
     throws Exception {
@@ -98,7 +99,7 @@
         } else {
             this.resolver = new PathMatchingResourcePatternResolver();
         }
-        this.environment = env;
+        this.settings = settings;
// now add selectors from parent
         if ( parentInfo != null ) {
@@ -156,10 +157,23 @@
             this.logger.info("Reading Avalon configuration from " + 
relativePath);
         }
         Resource root = 
this.resolver.getResource(this.convertUrl(relativePath));
-        final ConfigurationBuilder b = new 
ConfigurationBuilder(this.environment.settings);
+        final ConfigurationBuilder b = new ConfigurationBuilder(this.settings);
final Configuration config = b.build(this.getInputSource(root)); - + // validate cocoon.xconf
+        if (!"cocoon".equals(config.getName())) {
+            throw new ConfigurationException("Invalid configuration file\n"
+                    + config.toString());
+        }
+        if (this.logger.isDebugEnabled()) {
+            this.logger.debug("Configuration version: "
+                    + config.getAttribute("version"));
+        }
+        if (!Constants.CONF_VERSION.equals(config.getAttribute("version"))) {
+            throw new ConfigurationException(
+                    "Invalid configuration schema version. Must be '"
+                            + Constants.CONF_VERSION + "'.");
+ } this.convert(config, null, root.getURL().toExternalForm());
     }
@@ -189,7 +203,7 @@
                     this.logger.info("Reading additional user roles: " + 
userRoles);
                 }
                 final Resource userRolesSource = 
this.resolver.getResource(this.getUrl(userRoles, rootUri));
-                final ConfigurationBuilder b = new 
ConfigurationBuilder(this.environment.settings);
+                final ConfigurationBuilder b = new 
ConfigurationBuilder(this.settings);
                 final Configuration userRolesConfig = 
b.build(this.getInputSource(userRolesSource));
                 this.parseConfiguration(userRolesConfig, 
userRolesSource.getURL().toExternalForm(), loadedConfigs);
             }
@@ -392,7 +406,7 @@
             // load it and store it in the read set
             Configuration includeConfig = null;
             try {
-                ConfigurationBuilder builder = new 
ConfigurationBuilder(this.environment.settings);
+                ConfigurationBuilder builder = new 
ConfigurationBuilder(this.settings);
                 includeConfig = builder.build(src.getInputStream(), uri);
             } catch (Exception e) {
                 throw new ConfigurationException("Cannot load '" + uri + "' at 
" + includeStatement.getLocation(), e);

Added: 
cocoon/trunk/core/cocoon-webapp/src/main/webapp/WEB-INF/applicationContext.xml
URL: 
http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-webapp/src/main/webapp/WEB-INF/applicationContext.xml?rev=433754&view=auto
==============================================================================
--- 
cocoon/trunk/core/cocoon-webapp/src/main/webapp/WEB-INF/applicationContext.xml 
(added)
+++ 
cocoon/trunk/core/cocoon-webapp/src/main/webapp/WEB-INF/applicationContext.xml 
Tue Aug 22 14:08:31 2006
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<!-- @version $Id$ -->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns:util="http://www.springframework.org/schema/util";
+       xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd 
http://www.springframework.org/schema/util 
http://www.springframework.org/schema/util/spring-util.xsd";>
+
+  <!-- The following bean definitions will be replaced later on with
+       the use of the new namespace handling in spring:
+       <cocoon:settings/>
+       <cocoon:avalon-logger/>
+       <cocoon:avalon-support config="/WEB-INF/cocoon/cocoon.xconf"/>
+        -->
+  <bean id="org.apache.cocoon.configuration.Settings"
+        
class="org.apache.cocoon.core.container.spring.SettingsBeanFactoryPostProcessor"
+        singleton="true" init-method="init"/>
+
+  <bean id="org.apache.avalon.framework.logger.Logger"
+        
class="org.apache.cocoon.core.container.spring.avalon.AvalonLoggerFactoryBean"
+        singleton="true" init-method="init">
+      <property name="settings"><ref 
bean="org.apache.cocoon.configuration.Settings"/></property>
+  </bean>
+
+  <bean id="org.apache.avalon.framework.context.Context"
+        
class="org.apache.cocoon.core.container.spring.avalon.AvalonContextFactoryBean"
+        singleton="true" init-method="init">
+      <property name="settings"><ref 
bean="org.apache.cocoon.configuration.Settings"/></property>
+  </bean>
+</beans>

Two questions:

1. Does it mean that soon I will be able to do:
public class StartUp extends AbstractTransactionalSpringContextTests {
        public StartUp() {
                setPopulateProtectedVariables( true );
        }

        @Override
        protected String[] getConfigLocations() {
                return new String[]{
                   "META-INF/spring/applicationContext-common.xml",
                   "META-INF/spring/applicationContext-services.xml",
                   "META-INF/spring/applicationContext-acegi.xml",
                   "WEB-INF/applicationContext.xml" };
        }

        public void testStart() {
                // and have cocoon up and running here in test case?
        }
}

2. Could we put the file into some jar (cocoon-core.jar)? If this is put into cocoon-webapp/WEB-INF/applicationContext.xml every user has to sync it once a while after creating a webapp from older version of archetype.

--
Leszek Gawron, IT Manager                          MobileBox sp. z o.o.
+48 (61) 855 06 67                              http://www.mobilebox.pl
mobile: +48 (501) 720 812                       fax: +48 (61) 853 29 65

Reply via email to