cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r489727 - in /cocoon/trunk/core/cocoon-core/src: main/java/org/apache/cocoon/components/modules/input/ main/java/org/apache/cocoon/components/treeprocessor/ main/java/org/apache/cocoon/core/container/spring/ main/java/org/apache/cocoon/core...
Date Fri, 22 Dec 2006 19:14:26 GMT
Author: cziegeler
Date: Fri Dec 22 11:14:25 2006
New Revision: 489727

URL: http://svn.apache.org/viewvc?view=rev&rev=489727
Log:
Correct request attributes handling

Removed:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonRequestAttributes.java
Modified:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SettingsInputModule.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/Container.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ServletContextFactoryBean.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java
    cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SettingsInputModule.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SettingsInputModule.java?view=diff&rev=489727&r1=489726&r2=489727
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SettingsInputModule.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/modules/input/SettingsInputModule.java
Fri Dec 22 11:14:25 2006
@@ -28,10 +28,7 @@
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.avalon.framework.thread.ThreadSafe;
 import org.apache.cocoon.configuration.Settings;
-import org.apache.cocoon.core.container.spring.CocoonRequestAttributes;
 import org.apache.cocoon.core.container.spring.Container;
-import org.apache.cocoon.environment.ObjectModelHelper;
-import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.processing.ProcessInfoProvider;
 import org.apache.commons.collections.IteratorUtils;
 
@@ -71,8 +68,7 @@
      */
     public Object getAttribute(String name, Configuration modeConf, Map objectModel)
     throws ConfigurationException {
-        final Request request = ObjectModelHelper.getRequest(this.infoProvider.getObjectModel());
-        final Container container = Container.getCurrentContainer(this.infoProvider.getServletContext(),
new CocoonRequestAttributes(request));
+        final Container container = Container.getCurrentContainer();
         final Settings settings = container.getSettings();
         return settings.getProperty(name);
     }

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java?view=diff&rev=489727&r1=489726&r2=489727
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
Fri Dec 22 11:14:25 2006
@@ -29,12 +29,10 @@
 import org.apache.cocoon.ProcessingException;
 import org.apache.cocoon.Processor;
 import org.apache.cocoon.components.source.impl.SitemapSourceInfo;
-import org.apache.cocoon.core.container.spring.CocoonRequestAttributes;
 import org.apache.cocoon.core.container.spring.Container;
 import org.apache.cocoon.core.container.spring.avalon.AvalonUtils;
 import org.apache.cocoon.environment.Environment;
 import org.apache.cocoon.environment.ForwardRedirector;
-import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Redirector;
 import org.apache.cocoon.environment.SourceResolver;
 import org.apache.cocoon.environment.internal.EnvironmentHelper;
@@ -211,7 +209,7 @@
         Thread.currentThread().setContextClassLoader(this.classLoader);
         Object handle = null;
         try {
-            handle = this.container.enteringContext(new CocoonRequestAttributes(ObjectModelHelper.getRequest(environment.getObjectModel())));
+            handle = this.container.enteringContext();
             // invoke listeners
             // only invoke if pipeline is not internally
             if ( !context.isBuildingPipelineOnly() ) {
@@ -245,7 +243,7 @@
 
         } finally {
             this.sitemapExecutor.leaveSitemap(this, environment.getObjectModel());
-            this.container.leavingContext(new CocoonRequestAttributes(ObjectModelHelper.getRequest(environment.getObjectModel())),
handle);
+            this.container.leavingContext(handle);
             // invoke listeners
             // only invoke if pipeline is not internally
             if ( !context.isBuildingPipelineOnly() ) {

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/Container.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/Container.java?view=diff&rev=489727&r1=489726&r2=489727
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/Container.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/Container.java
Fri Dec 22 11:14:25 2006
@@ -51,25 +51,24 @@
     protected static Container ROOT_CONTAINER;
 
     public static Container getCurrentContainer() {
-        final RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
-        return getCurrentContainer(null, attributes);
+        final RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
+        return getCurrentContainer(attributes);
     }
 
     /**
      * Return the current web application context.
-     * @param servletContext The servlet context.
      * @param attributes     The request attributes.
      * @return The web application context.
      */
-    public static Container getCurrentContainer(ServletContext servletContext,
-                                                RequestAttributes attributes) {
+    public static Container getCurrentContainer(RequestAttributes attributes) {
         if ( attributes != null ) {
             if (attributes.getAttribute(CONTAINER_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST)
!= null) {
                 return (Container) attributes
                         .getAttribute(CONTAINER_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
             }
         }
-        if ( ROOT_CONTAINER == null && servletContext != null ) {
+        if ( ROOT_CONTAINER == null ) {
+            final ServletContext servletContext = ServletContextFactoryBean.getServletContext();
             final WebApplicationContext parentContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
             ROOT_CONTAINER = new Container(parentContext, parentContext.getClassLoader());
         }
@@ -78,10 +77,10 @@
 
     /**
      * Notify about entering this context.
-     * @param attributes The request attributes.
      * @return A handle which should be passed to {@link #leavingContext(RequestAttributes,
Object)}.
      */
-    public Object enteringContext(RequestAttributes attributes) {
+    public Object enteringContext() {
+        final RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
         final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
         final Object oldContext = attributes.getAttribute(CONTAINER_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
         if ( oldContext != null ) {
@@ -99,10 +98,10 @@
 
     /**
      * Notify about leaving this context.
-     * @param attributes The request attributes.
      * @param handle     The returned handle from {@link #enteringContext(RequestAttributes)}.
      */
-    public void leavingContext(RequestAttributes attributes, Object handle) {
+    public void leavingContext(Object handle) {
+        final RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
         Thread.currentThread().setContextClassLoader((ClassLoader)handle);
         final Stack stack = (Stack)attributes.getAttribute(CONTAINER_STACK_REQUEST_ATTRIBUTE,
RequestAttributes.SCOPE_REQUEST);
         if ( stack == null ) {

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ServletContextFactoryBean.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ServletContextFactoryBean.java?view=diff&rev=489727&r1=489726&r2=489727
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ServletContextFactoryBean.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ServletContextFactoryBean.java
Fri Dec 22 11:14:25 2006
@@ -24,24 +24,33 @@
 /**
  * Simple Spring factory bean which provides the servlet context as a bean.
  * This avoids a dependence to Springs ServletContextAware interface.
+ *
  * @version $Id$
+ * @since 2.2
  */
 public class ServletContextFactoryBean implements FactoryBean, ServletContextAware {
 
-    protected ServletContext servletContext;
+    protected static ServletContext servletContext;
+
+    public static ServletContext getServletContext() {
+        if ( servletContext == null ) {
+            throw new RuntimeException("ServletContext in ServletContextFactoryBean is not
initialized yet. Check your configuration.");
+        }
+        return servletContext;
+    }
 
     /**
      * @see org.springframework.web.context.ServletContextAware#setServletContext(javax.servlet.ServletContext)
      */
     public void setServletContext(ServletContext context) {
-        this.servletContext = context;
+        servletContext = context;
     }
 
     /**
      * @see org.springframework.beans.factory.FactoryBean#getObject()
      */
     public Object getObject() throws Exception {
-        return this.servletContext;
+        return servletContext;
     }
 
     /**

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java?view=diff&rev=489727&r1=489726&r2=489727
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java
Fri Dec 22 11:14:25 2006
@@ -25,20 +25,14 @@
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.cocoon.classloader.ClassLoaderFactory;
 import org.apache.cocoon.classloader.reloading.Monitor;
-import org.apache.cocoon.classloader.reloading.ReloadingClassLoaderConfiguration;
 import org.apache.cocoon.configuration.Settings;
-import org.apache.cocoon.core.container.spring.CocoonRequestAttributes;
 import org.apache.cocoon.core.container.spring.CocoonWebApplicationContext;
 import org.apache.cocoon.core.container.spring.Container;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.processing.ProcessInfoProvider;
-import org.apache.excalibur.source.SourceResolver;
-import org.springframework.beans.factory.BeanFactory;
 import org.springframework.web.context.WebApplicationContext;
-import org.springframework.web.context.request.RequestAttributes;
 import org.springframework.web.context.support.WebApplicationContextUtils;
 
 
@@ -153,7 +147,6 @@
         final WebApplicationContext rootContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
         final ProcessInfoProvider infoProvider = (ProcessInfoProvider) rootContext.getBean(ProcessInfoProvider.ROLE);
         final Request request = ObjectModelHelper.getRequest(infoProvider.getObjectModel());
-        final SourceResolver sitemapResolver = (SourceResolver)rootContext.getBean(SourceResolver.ROLE);
         // let's determine our context url
         int pos = sitemapLocation.lastIndexOf('/');
         if ( sitemapLocation.lastIndexOf(File.separatorChar) > pos ) {
@@ -161,8 +154,7 @@
         }
         final String contextUrl = sitemapLocation.substring(0, pos + 1);
 
-        final RequestAttributes attr = new CocoonRequestAttributes(request);
-        final Container container = Container.getCurrentContainer(servletContext, attr);
+        final Container container = Container.getCurrentContainer();
         // for now we require that the parent container is a web application context (FIXME)
         if ( !(container.getBeanFactory() instanceof WebApplicationContext) ) {
             throw new Exception("Parent container is not a web application context: " + container.getBeanFactory());

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java?view=diff&rev=489727&r1=489726&r2=489727
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java
Fri Dec 22 11:14:25 2006
@@ -27,7 +27,6 @@
 import org.apache.avalon.framework.parameters.ParameterException;
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.cocoon.components.flow.FlowHelper;
-import org.apache.cocoon.core.container.spring.CocoonRequestAttributes;
 import org.apache.cocoon.core.container.spring.Container;
 import org.apache.commons.jxpath.DynamicPropertyHandler;
 import org.apache.commons.jxpath.JXPathBeanInfo;
@@ -129,7 +128,7 @@
             cocoon.put("parameters", new ParametersMap(parameters));
         }
 
-        final Container container = Container.getCurrentContainer(context, new CocoonRequestAttributes(request));
+        final Container container = Container.getCurrentContainer();
         cocoon.put("settings", container.getSettings());
 
         final Map map = new HashMap();

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java?view=diff&rev=489727&r1=489726&r2=489727
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java
Fri Dec 22 11:14:25 2006
@@ -30,13 +30,9 @@
 import org.apache.cocoon.ProcessingException;
 import org.apache.cocoon.Processor;
 import org.apache.cocoon.components.source.SourceUtil;
-import org.apache.cocoon.core.container.spring.CocoonRequestAttributes;
 import org.apache.cocoon.core.container.spring.Container;
 import org.apache.cocoon.core.container.spring.avalon.AvalonUtils;
-import org.apache.cocoon.environment.Context;
 import org.apache.cocoon.environment.Environment;
-import org.apache.cocoon.environment.ObjectModelHelper;
-import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.environment.SourceResolver;
 import org.apache.cocoon.xml.XMLConsumer;
 import org.apache.excalibur.source.Source;
@@ -396,10 +392,7 @@
     static public ServiceManager getSitemapServiceManager() {
         final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
         if ( stack != null && !stack.isEmpty()) {
-            final EnvironmentInfo info = stack.getCurrentInfo();
-            final Request request = ObjectModelHelper.getRequest(info.environment.getObjectModel());
-            final Context context = ObjectModelHelper.getContext(info.environment.getObjectModel());
-            final Container container = Container.getCurrentContainer(context, new CocoonRequestAttributes(request));
+            final Container container = Container.getCurrentContainer();
             return (ServiceManager)container.getBeanFactory().getBean(AvalonUtils.SERVICE_MANAGER_ROLE);
         }
         return null;

Modified: cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java?view=diff&rev=489727&r1=489726&r2=489727
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java
Fri Dec 22 11:14:25 2006
@@ -40,8 +40,8 @@
 import org.apache.cocoon.components.flow.FlowHelper;
 import org.apache.cocoon.components.flow.Interpreter;
 import org.apache.cocoon.components.source.SourceResolverAdapter;
-import org.apache.cocoon.core.container.spring.CocoonRequestAttributes;
 import org.apache.cocoon.core.container.spring.Container;
+import org.apache.cocoon.core.container.spring.ServletContextFactoryBean;
 import org.apache.cocoon.core.container.spring.avalon.ComponentInfo;
 import org.apache.cocoon.core.container.spring.avalon.ConfigurationInfo;
 import org.apache.cocoon.environment.ObjectModelHelper;
@@ -65,7 +65,6 @@
 import org.apache.excalibur.xml.sax.SAXParser;
 import org.custommonkey.xmlunit.Diff;
 import org.springframework.web.context.WebApplicationContext;
-import org.springframework.web.context.support.StaticWebApplicationContext;
 import org.w3c.dom.Document;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
@@ -127,7 +126,10 @@
         //bean factory to get consistent bean resolution behaviour
         WebApplicationContext staticWebApplicationContext = new MockWebApplicationContext(this.getBeanFactory(),
cont);
 		cont.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, staticWebApplicationContext);
-        Container container = Container.getCurrentContainer(cont, new CocoonRequestAttributes(request));
+        // now setup container stuff
+        ServletContextFactoryBean scfb = new ServletContextFactoryBean();
+        scfb.setServletContext(cont);
+        final Container container = Container.getCurrentContainer();
         request.setAttribute(Container.CONTAINER_REQUEST_ATTRIBUTE, container, Request.REQUEST_SCOPE);
         objectmodel.put(ObjectModelHelper.REQUEST_OBJECT, request);
 



Mime
View raw message