Author: cziegeler Date: Thu Mar 24 05:45:52 2005 New Revision: 158916 URL: http://svn.apache.org/viewcvs?view=rev&rev=158916 Log: Add constant and restore request attribute when sitemap is left
Modified: cocoon/blocks/spring-app/trunk/java/org/apache/cocoon/spring/SpringComponentLocator.java Modified: cocoon/blocks/spring-app/trunk/java/org/apache/cocoon/spring/SpringComponentLocator.java URL: http://svn.apache.org/viewcvs/cocoon/blocks/spring-app/trunk/java/org/apache/cocoon/spring/SpringComponentLocator.java?view=diff&r1=158915&r2=158916 ============================================================================== --- cocoon/blocks/spring-app/trunk/java/org/apache/cocoon/spring/SpringComponentLocator.java (original) +++ cocoon/blocks/spring-app/trunk/java/org/apache/cocoon/spring/SpringComponentLocator.java Thu Mar 24 05:45:52 2005 @@ -16,6 +16,7 @@ package org.apache.cocoon.spring; import java.util.Map; +import java.util.Stack; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; @@ -74,6 +75,8 @@ EnterSitemapEventListener, LeaveSitemapEventListener { + public static final String APPLICATION_CONTEXT_REQUEST_ATTRIBUTE = "application-context"; + protected Context context; protected ServletContext servletContext; protected EnvironmentHelper environmentHelper; @@ -253,7 +256,7 @@ protected ApplicationContext getParentContext() { final Map objectModel = ContextHelper.getObjectModel(this.context); final Request request = ObjectModelHelper.getRequest(objectModel); - ApplicationContext parentContext = (ApplicationContext)request.getAttribute("application-context"); + ApplicationContext parentContext = (ApplicationContext)request.getAttribute(APPLICATION_CONTEXT_REQUEST_ATTRIBUTE); if ( parentContext == null ) { // there is no parent sitemap with an application context @@ -269,15 +272,32 @@ */ public void enteredSitemap(EnterSitemapEvent event) { final Request request = ObjectModelHelper.getRequest(event.getEnvironment().getObjectModel()); - request.setAttribute("application-context", this.wac); + final Object oldContext = request.getAttribute(APPLICATION_CONTEXT_REQUEST_ATTRIBUTE); + if ( oldContext != null ) { + Stack stack = (Stack)request.getAttribute("ac-stack"); + if ( stack == null ) { + stack = new Stack(); + request.setAttribute("ac-stack", stack); + } + stack.push(oldContext); + } + request.setAttribute(APPLICATION_CONTEXT_REQUEST_ATTRIBUTE, this.wac); } /** * @see org.apache.cocoon.sitemap.LeaveSitemapEventListener#leftSitemap(org.apache.cocoon.sitemap.LeaveSitemapEvent) */ public void leftSitemap(LeaveSitemapEvent event) { - // TODO We have to restore the old value! final Request request = ObjectModelHelper.getRequest(event.getEnvironment().getObjectModel()); - request.removeAttribute("application-context"); + final Stack stack = (Stack)request.getAttribute("ac-stack"); + if ( stack == null ) { + request.removeAttribute(APPLICATION_CONTEXT_REQUEST_ATTRIBUTE); + } else { + final Object oldContext = stack.pop(); + request.setAttribute(APPLICATION_CONTEXT_REQUEST_ATTRIBUTE, oldContext); + if ( stack.size() == 0 ) { + request.removeAttribute("ac-stack"); + } + } } }