cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r491005 - in /cocoon/trunk/core: cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/ cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/ cocoon-spring/src/ma...
Date Fri, 29 Dec 2006 13:39:03 GMT
Author: cziegeler
Date: Fri Dec 29 05:39:03 2006
New Revision: 491005

URL: http://svn.apache.org/viewvc?view=rev&rev=491005
Log:
Use more general names and make own context implementation more reusable.

Added:
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/ChildXmlWebApplicationContext.java
      - copied, changed from r491002, cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java
Removed:
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java
Modified:
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/SitemapElementParser.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/SubSettingsBeanFactoryPostProcessor.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java
    cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/Constants.java

Copied: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/ChildXmlWebApplicationContext.java
(from r491002, cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java)
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/ChildXmlWebApplicationContext.java?view=diff&rev=491005&p1=cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java&r1=491002&p2=cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/ChildXmlWebApplicationContext.java&r2=491005
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/ChildXmlWebApplicationContext.java
Fri Dec 29 05:39:03 2006
@@ -28,9 +28,7 @@
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.core.io.Resource;
 import org.springframework.core.io.UrlResource;
-import org.springframework.util.ClassUtils;
 import org.springframework.util.ResourceUtils;
-import org.springframework.web.context.WebApplicationContext;
 import org.springframework.web.context.support.XmlWebApplicationContext;
 
 /**
@@ -40,34 +38,42 @@
  * @since 2.2
  * @version $Id$
  */
-public class CocoonWebApplicationContext extends XmlWebApplicationContext {
+public class ChildXmlWebApplicationContext extends XmlWebApplicationContext {
 
     /** The base url (already postfixed with a '/'). */
-    protected final String baseUrl;
-
-    /** The class loader for this context (or null). */
-    protected final ClassLoader classLoader;
+    protected String baseUrl;
 
     /** The bean definition for this context. */
-    protected final String beanDefinition;
+    protected String beanDefinition;
+
+    public ChildXmlWebApplicationContext() {
+        // nothing to do here
+    }
 
-    public CocoonWebApplicationContext(ClassLoader           classloader,
-                                       WebApplicationContext parent,
-                                       String                url,
-                                       String                rootDefinition) {
-        this.setParent(parent);
-        this.setClassLoader(classloader);
-        this.setServletContext(parent.getServletContext());
+    public ChildXmlWebApplicationContext(String url,
+                                       String rootDefinition) {
+        this.setBaseUrl(url);
+        this.setBeanDefinition(rootDefinition);
+    }
+
+    public String getBaseUrl() {
+        return this.baseUrl;
+    }
+
+    public void setBaseUrl(String url) {
         if ( url.endsWith("/") ) {
             this.baseUrl = url;
         } else {
             this.baseUrl = url + '/';
         }
-        this.classLoader = (classloader != null ? classloader : ClassUtils.getDefaultClassLoader());
-        //TODO : is there a cleaner way to set the new classLoader to the spring context?
-        Thread.currentThread().setContextClassLoader(this.classLoader);
-        this.beanDefinition = rootDefinition;
-        this.refresh();
+    }
+
+    public String getBeanDefinition() {
+        return beanDefinition;
+    }
+
+    public void setBeanDefinition(String beanDefinition) {
+        this.beanDefinition = beanDefinition;
     }
 
     /**
@@ -84,20 +90,22 @@
      * @see org.springframework.web.context.support.AbstractRefreshableWebApplicationContext#getResourceByPath(java.lang.String)
      */
     protected Resource getResourceByPath(String path) {
-        // only if the path does not start with a "/" and is not a url
-        // we assume it is relative
-        if ( path != null && !path.startsWith("/") && !ResourceUtils.isUrl(path)
) {
-            final String absoluteUrl = this.baseUrl + path;
-            if (absoluteUrl.startsWith(CLASSPATH_URL_PREFIX)) {
-                return new ClassPathResource(absoluteUrl.substring(CLASSPATH_URL_PREFIX.length()),
getClassLoader());
-            }
-            try {
-                // try URL
-                URL url = new URL(absoluteUrl);
-                return new UrlResource(url);
-            } catch (MalformedURLException ex) {
-                // no URL -> resolve resource path
-                return super.getResourceByPath(absoluteUrl);
+        if ( this.baseUrl != null ) {
+            // only if the path does not start with a "/" and is not a url
+            // we assume it is relative
+            if ( path != null && !path.startsWith("/") && !ResourceUtils.isUrl(path)
) {
+                final String absoluteUrl = this.baseUrl + path;
+                if (absoluteUrl.startsWith(CLASSPATH_URL_PREFIX)) {
+                    return new ClassPathResource(absoluteUrl.substring(CLASSPATH_URL_PREFIX.length()),
getClassLoader());
+                }
+                try {
+                    // try URL
+                    URL url = new URL(absoluteUrl);
+                    return new UrlResource(url);
+                } catch (MalformedURLException ex) {
+                    // no URL -> resolve resource path
+                    return super.getResourceByPath(absoluteUrl);
+                }
             }
         }
         return super.getResourceByPath(path);

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/SitemapElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/SitemapElementParser.java?view=diff&rev=491005&r1=491004&r2=491005
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/SitemapElementParser.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/SitemapElementParser.java
Fri Dec 29 05:39:03 2006
@@ -132,7 +132,7 @@
 
             // register a PropertyPlaceholderConfigurer
             if ( useDefaultIncludes ) {
-                this.registerPropertyOverrideConfigurer(parserContext, Constants.DEFAULT_SITEMAP_SPRING_CONFIGURATION_LOCATION);
+                this.registerPropertyOverrideConfigurer(parserContext, Constants.DEFAULT_CHILD_SPRING_CONFIGURATION_LOCATION);
             }
             
             RootBeanDefinition def =  this.createBeanDefinition(SubSettingsBeanFactoryPostProcessor.class.getName(),
@@ -152,8 +152,8 @@
             }
 
             if ( useDefaultIncludes ) {
-                this.handleBeanInclude(parserContext, null, Constants.DEFAULT_SITEMAP_SPRING_CONFIGURATION_LOCATION,
"*.xml", true);
-                this.handleBeanInclude(parserContext, null, Constants.DEFAULT_SITEMAP_SPRING_CONFIGURATION_LOCATION
+ "/" + runningMode, "*.xml", true);
+                this.handleBeanInclude(parserContext, null, Constants.DEFAULT_CHILD_SPRING_CONFIGURATION_LOCATION,
"*.xml", true);
+                this.handleBeanInclude(parserContext, null, Constants.DEFAULT_CHILD_SPRING_CONFIGURATION_LOCATION
+ "/" + runningMode, "*.xml", true);
             }
             // search for includes
             if ( componentsElement != null ) {

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/SubSettingsBeanFactoryPostProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/SubSettingsBeanFactoryPostProcessor.java?view=diff&rev=491005&r1=491004&r2=491005
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/SubSettingsBeanFactoryPostProcessor.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/SubSettingsBeanFactoryPostProcessor.java
Fri Dec 29 05:39:03 2006
@@ -107,9 +107,9 @@
 
         // read properties from default includes
         if ( this.useDefaultIncludes ) {
-            ResourceUtils.readProperties(Constants.DEFAULT_SITEMAP_PROPERTIES_LOCATION, properties,
this.getResourceLoader(), this.logger);
+            ResourceUtils.readProperties(Constants.DEFAULT_CHILD_PROPERTIES_LOCATION, properties,
this.getResourceLoader(), this.logger);
             // read all properties from the mode dependent directory
-            ResourceUtils.readProperties(Constants.DEFAULT_SITEMAP_PROPERTIES_LOCATION +
'/' + mode, properties, this.getResourceLoader(), this.logger);    
+            ResourceUtils.readProperties(Constants.DEFAULT_CHILD_PROPERTIES_LOCATION + '/'
+ mode, properties, this.getResourceLoader(), this.logger);    
         }
 
         if ( this.directories != null ) {

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java?view=diff&rev=491005&r1=491004&r2=491005
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java
Fri Dec 29 05:39:03 2006
@@ -27,7 +27,7 @@
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
 import org.apache.cocoon.classloader.reloading.Monitor;
 import org.apache.cocoon.configuration.Settings;
-import org.apache.cocoon.core.container.spring.CocoonWebApplicationContext;
+import org.apache.cocoon.core.container.spring.ChildXmlWebApplicationContext;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.processing.ProcessInfoProvider;
@@ -167,10 +167,16 @@
                                                    ((Settings)parentContext.getBean(Settings.ROLE)).getRunningMode());
         PARENT_CONTEXT.set(parentContext);
         try {
-            final CocoonWebApplicationContext context = new CocoonWebApplicationContext(classloader,
-                                                                                        parentContext,
-                                                                                        contextUrl,
+            final ChildXmlWebApplicationContext context = new ChildXmlWebApplicationContext(contextUrl,
                                                                                         definition);
+            context.setServletContext(servletContext);
+            if ( parentContext != null ) {
+                context.setParent(parentContext);
+            }
+            if ( classloader != null ) {
+                context.setClassLoader(classloader);
+            }
+            context.refresh();
             return context;
         } finally {
             PARENT_CONTEXT.set(null);

Modified: cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/Constants.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/Constants.java?view=diff&rev=491005&r1=491004&r2=491005
==============================================================================
--- cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/Constants.java
(original)
+++ cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/Constants.java
Fri Dec 29 05:39:03 2006
@@ -30,7 +30,7 @@
     public static final String DEFAULT_SPRING_CONFIGURATION_LOCATION = "classpath*:META-INF/cocoon/spring";
     public static final String DEFAULT_PROPERTIES_LOCATION = "classpath*:META-INF/cocoon/properties";
 
-    /** The default location of spring related per sitemap configuration files. */
-    public static final String DEFAULT_SITEMAP_SPRING_CONFIGURATION_LOCATION = "config/spring";
-    public static final String DEFAULT_SITEMAP_PROPERTIES_LOCATION = "config/properties";
+    /** The default location of spring related child configuration files. */
+    public static final String DEFAULT_CHILD_SPRING_CONFIGURATION_LOCATION = "config/spring";
+    public static final String DEFAULT_CHILD_PROPERTIES_LOCATION = "config/properties";
 }



Mime
View raw message