cziegeler 2003/10/30 04:20:45
Modified: src/java/org/apache/cocoon/environment Environment.java
ForwardRedirector.java EnvironmentHelper.java
AbstractEnvironment.java
src/java/org/apache/cocoon/components/treeprocessor
TreeProcessor.java DefaultTreeBuilder.java
src/java/org/apache/cocoon ProcessorWrapper.java Cocoon.java
Processor.java
src/java/org/apache/cocoon/environment/http
HttpEnvironment.java
src/java/org/apache/cocoon/environment/commandline
AbstractCommandLineEnvironment.java
Log:
Updating environment handling
Revision Changes Path
1.10 +2 -2
cocoon-2.2/src/java/org/apache/cocoon/environment/Environment.java
Index: Environment.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/Environment.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Environment.java 29 Oct 2003 18:58:06 -0000 1.9
+++ Environment.java 30 Oct 2003 12:20:45 -0000 1.10
@@ -93,7 +93,7 @@
/**
* Redirect to the given URL
*/
- void redirect(boolean sessionmode, String url) throws IOException;
+ void redirect(String url, boolean permanent) throws IOException;
/**
* Set the content type of the generated resource
1.11 +7 -7
cocoon-2.2/src/java/org/apache/cocoon/environment/ForwardRedirector.java
Index: ForwardRedirector.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/ForwardRedirector.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ForwardRedirector.java 29 Oct 2003 14:52:09 -0000 1.10
+++ ForwardRedirector.java 30 Oct 2003 12:20:45 -0000 1.11
@@ -64,7 +64,9 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
* @version CVS $Id$
*/
-public class ForwardRedirector extends AbstractLogEnabled implements
Redirector, PermanentRedirector {
+public class ForwardRedirector
+extends AbstractLogEnabled
+implements Redirector, PermanentRedirector {
/**
* Was there a call to <code>redirect()</code> ?
@@ -91,7 +93,7 @@
if (url.startsWith("cocoon:")) {
cocoonRedirect(url);
} else {
- this.env.redirect(sessionMode, url);
+
EnvironmentHelper.getCurrentProcessor().getEnvironmentHelper().redirect(this.env,
sessionMode, url);
}
this.hasRedirected = true;
@@ -104,10 +106,8 @@
if (url.startsWith("cocoon:")) {
cocoonRedirect(url);
- } else if (env instanceof PermanentRedirector) {
- ((PermanentRedirector)env).permanentRedirect(sessionMode, url);
} else {
- this.env.redirect(sessionMode, url);
+
EnvironmentHelper.getCurrentProcessor().getEnvironmentHelper().permanentRedirect(this.env,
sessionMode, url);
}
this.hasRedirected = true;
@@ -128,7 +128,7 @@
} else if (env instanceof EnvironmentWrapper) {
((EnvironmentWrapper)env).globalRedirect(sessionMode,url);
} else {
- this.env.redirect(sessionMode, url);
+
EnvironmentHelper.getCurrentProcessor().getEnvironmentHelper().redirect(this.env,
sessionMode, url);
}
this.hasRedirected = true;
}
1.8 +64 -3
cocoon-2.2/src/java/org/apache/cocoon/environment/EnvironmentHelper.java
Index: EnvironmentHelper.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/EnvironmentHelper.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- EnvironmentHelper.java 30 Oct 2003 11:30:12 -0000 1.7
+++ EnvironmentHelper.java 30 Oct 2003 12:20:45 -0000 1.8
@@ -81,6 +81,9 @@
* in the object model */
static final String PROCESS_KEY = EnvironmentHelper.class.getName();
+ /** The environment information */
+ static protected InheritableThreadLocal environmentStack = new
CloningInheritableThreadLocal();
+
/** The real source resolver */
protected org.apache.excalibur.source.SourceResolver resolver;
@@ -99,8 +102,6 @@
/** The last prefix, which is stripped off from the request uri */
protected String lastPrefix;
- /** The environment information */
- protected static InheritableThreadLocal environmentStack = new
CloningInheritableThreadLocal();
/**
* Constructor
@@ -111,6 +112,12 @@
this.rootContext = context;
}
+ public EnvironmentHelper(EnvironmentHelper parent) {
+ this.context = parent.context;
+ this.rootContext = parent.rootContext;
+ this.lastPrefix = parent.lastPrefix;
+ this.prefix = parent.prefix;
+ }
/* (non-Javadoc)
* @see
org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
@@ -279,6 +286,60 @@
}
}
+ public void redirect(Environment env,
+ boolean sessionmode,
+ String newURL)
+ throws IOException {
+ this.doRedirect(env, sessionmode, newURL, false);
+ }
+
+ public void permanentRedirect(Environment env, boolean sessionmode,
String newURL)
+ throws IOException {
+ this.doRedirect(env, sessionmode, newURL, true);
+ }
+
+ /**
+ * Redirect the client to new URL with session mode
+ */
+ protected void doRedirect(Environment env,
+ boolean sessionmode,
+ String newURL,
+ boolean permanent)
+ throws IOException {
+ final Request request =
ObjectModelHelper.getRequest(env.getObjectModel());
+ // check if session mode shall be activated
+ if (sessionmode) {
+
+ // The session
+ Session session = null;
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("redirect: entering session mode");
+ }
+ String s = request.getRequestedSessionId();
+ if (s != null) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Old session ID found in request, id =
" + s);
+ if ( request.isRequestedSessionIdValid() ) {
+ getLogger().debug("And this old session ID is
valid");
+ }
+ }
+ }
+ // get session from request, or create new session
+ session = request.getSession(true);
+ if (session == null) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("redirect session mode: unable to get
session object!");
+ }
+ }
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug ("redirect: session mode completed, id = "
+ session.getId() );
+ }
+ }
+ // redirect
+ final Response response =
ObjectModelHelper.getResponse(env.getObjectModel());
+ env.redirect(newURL, permanent);
+ }
+
/**
* This hook must be called by the sitemap each time a sitemap is entered
* This method should never raise an exception, except when the
1.22 +1 -10
cocoon-2.2/src/java/org/apache/cocoon/environment/AbstractEnvironment.java
Index: AbstractEnvironment.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/AbstractEnvironment.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- AbstractEnvironment.java 29 Oct 2003 18:58:06 -0000 1.21
+++ AbstractEnvironment.java 30 Oct 2003 12:20:45 -0000 1.22
@@ -138,15 +138,6 @@
}
/**
- * Redirect the client to a new URL
- */
- public abstract void redirect(boolean sessionmode, String newURL) throws
IOException;
-
- public void globalRedirect(boolean sessionmode, String newURL) throws
IOException {
- redirect(sessionmode, newURL);
- }
-
- /**
* Returns the request view
*/
public String getView() {
1.22 +10 -11
cocoon-2.2/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java
Index: TreeProcessor.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- TreeProcessor.java 30 Oct 2003 11:30:12 -0000 1.21
+++ TreeProcessor.java 30 Oct 2003 12:20:45 -0000 1.22
@@ -216,6 +216,9 @@
// that can be copied from the parent (see above)
TreeProcessor child = new TreeProcessor(this, manager, language);
child.source = new DelayedRefreshSourceWrapper(source,
lastModifiedDelay);
+ this.environmentHelper = new
EnvironmentHelper(parent.environmentHelper);
+ // TODO - Test if getURI() is correct
+ this.environmentHelper.changeContext(prefix, source.getURI());
return child;
}
@@ -227,8 +230,10 @@
this.manager = manager;
this.resolver =
(SourceResolver)this.manager.lookup(SourceResolver.ROLE);
try {
- this.environmentHelper = new EnvironmentHelper(
- (String)
this.context.get(Constants.CONTEXT_ROOT_URL));
+ if ( this.environmentHelper == null ) {
+ this.environmentHelper = new EnvironmentHelper(
+ (String)
this.context.get(Constants.CONTEXT_ROOT_URL));
+ }
ContainerUtil.enableLogging(this.environmentHelper,
this.getLogger());
ContainerUtil.service(this.environmentHelper, this.manager);
} catch (ContextException e) {
@@ -605,16 +610,10 @@
}
/* (non-Javadoc)
- * @see org.apache.cocoon.Processor#getSourceResolver()
- */
- public org.apache.cocoon.environment.SourceResolver getSourceResolver() {
- return this.environmentHelper;
- }
-
- /**
- * Return the environment helper
+ * @see org.apache.cocoon.Processor#getEnvironmentHelper()
*/
public EnvironmentHelper getEnvironmentHelper() {
return this.environmentHelper;
}
+
}
1.5 +1 -6
cocoon-2.2/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java
Index: DefaultTreeBuilder.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DefaultTreeBuilder.java 10 Sep 2003 17:43:02 -0000 1.4
+++ DefaultTreeBuilder.java 30 Oct 2003 12:20:45 -0000 1.5
@@ -50,10 +50,6 @@
*/
package org.apache.cocoon.components.treeprocessor;
-import org.apache.avalon.excalibur.component.DefaultRoleManager;
-import org.apache.avalon.excalibur.component.ExcaliburComponentSelector;
-import org.apache.avalon.excalibur.component.RoleManageable;
-import org.apache.avalon.excalibur.component.RoleManager;
import org.apache.avalon.excalibur.pool.Recyclable;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
@@ -70,7 +66,6 @@
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.components.ExtendedComponentSelector;
import org.apache.cocoon.components.LifecycleHelper;
import org.apache.cocoon.components.source.SourceUtil;
import
org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
1.7 +5 -5
cocoon-2.2/src/java/org/apache/cocoon/ProcessorWrapper.java
Index: ProcessorWrapper.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/ProcessorWrapper.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ProcessorWrapper.java 29 Oct 2003 18:58:06 -0000 1.6
+++ ProcessorWrapper.java 30 Oct 2003 12:20:45 -0000 1.7
@@ -57,7 +57,7 @@
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.components.pipeline.ProcessingPipeline;
import org.apache.cocoon.environment.Environment;
-import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.environment.EnvironmentHelper;
/**
* This class is a wrapper around the real processor (the
<code>Cocoon</code> class).
@@ -113,10 +113,10 @@
}
/* (non-Javadoc)
- * @see org.apache.cocoon.Processor#getSourceResolver()
+ * @see org.apache.cocoon.Processor#getEnvironmentHelper()
*/
- public SourceResolver getSourceResolver() {
- return this.processor.getSourceResolver();
+ public EnvironmentHelper getEnvironmentHelper() {
+ return this.processor.getEnvironmentHelper();
}
/* (non-Javadoc)
1.28 +3 -3 cocoon-2.2/src/java/org/apache/cocoon/Cocoon.java
Index: Cocoon.java
===================================================================
RCS file: /home/cvs/cocoon-2.2/src/java/org/apache/cocoon/Cocoon.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- Cocoon.java 29 Oct 2003 18:58:06 -0000 1.27
+++ Cocoon.java 30 Oct 2003 12:20:45 -0000 1.28
@@ -501,9 +501,9 @@
}
/* (non-Javadoc)
- * @see org.apache.cocoon.Processor#getSourceResolver()
+ * @see org.apache.cocoon.Processor#getEnvironmentHelper()
*/
- public org.apache.cocoon.environment.SourceResolver getSourceResolver() {
+ public EnvironmentHelper getEnvironmentHelper() {
return this.environmentHelper;
}
1.9 +4 -4 cocoon-2.2/src/java/org/apache/cocoon/Processor.java
Index: Processor.java
===================================================================
RCS file: /home/cvs/cocoon-2.2/src/java/org/apache/cocoon/Processor.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Processor.java 29 Oct 2003 18:58:06 -0000 1.8
+++ Processor.java 30 Oct 2003 12:20:45 -0000 1.9
@@ -55,7 +55,7 @@
import org.apache.avalon.framework.component.Component;
import org.apache.cocoon.components.pipeline.ProcessingPipeline;
import org.apache.cocoon.environment.Environment;
-import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.environment.EnvironmentHelper;
/**
*
@@ -103,11 +103,11 @@
Processor getRootProcessor();
/**
- * Get the Source Resolver for this processor
+ * Get the EnvironmentHelper for this processor
* EXPERIMENTAL
* @since 2.2
*/
- SourceResolver getSourceResolver();
+ EnvironmentHelper getEnvironmentHelper();
/**
* Get the context URI for this processor
1.14 +7 -37
cocoon-2.2/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java
Index: HttpEnvironment.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- HttpEnvironment.java 29 Oct 2003 18:58:06 -0000 1.13
+++ HttpEnvironment.java 30 Oct 2003 12:20:45 -0000 1.14
@@ -67,7 +67,7 @@
* @author ?
* @version CVS $Id$
*/
-public class HttpEnvironment extends AbstractEnvironment implements
Redirector, PermanentRedirector {
+public class HttpEnvironment extends AbstractEnvironment {
public static final String HTTP_REQUEST_OBJECT = "httprequest";
public static final String HTTP_RESPONSE_OBJECT= "httpresponse";
@@ -148,47 +148,16 @@
}
}
- public void redirect(boolean sessionmode, String newURL) throws
IOException {
- doRedirect(sessionmode, newURL, false);
- }
-
- public void permanentRedirect(boolean sessionmode, String newURL) throws
IOException {
- doRedirect(sessionmode, newURL, true);
+ public void redirect(String newURL, boolean permanent) throws
IOException {
+ doRedirect(newURL, permanent);
}
/**
- * Redirect the client to new URL with session mode
+ * Redirect the client to new URL
*/
- private void doRedirect(boolean sessionmode, String newURL, boolean
permanent) throws IOException {
+ private void doRedirect(String newURL, boolean permanent) throws
IOException {
this.hasRedirected = true;
- // check if session mode shall be activated
- if (sessionmode) {
- // The session
- Session session = null;
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("redirect: entering session mode");
- }
- String s = request.getRequestedSessionId();
- if (s != null) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Old session ID found in request, id =
" + s);
- if ( request.isRequestedSessionIdValid() ) {
- getLogger().debug("And this old session ID is
valid");
- }
- }
- }
- // get session from request, or create new session
- session = request.getSession(true);
- if (session == null) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("redirect session mode: unable to get
session object!");
- }
- }
- if (getLogger().isDebugEnabled()) {
- getLogger().debug ("redirect: session mode completed, id = "
+ session.getId() );
- }
- }
// redirect
String redirect = this.response.encodeRedirectURL(newURL);
@@ -207,6 +176,7 @@
if (getLogger().isDebugEnabled()) {
getLogger().debug("Sending redirect to '" + redirect + "'");
}
+
if (permanent) {
this.response.sendPermanentRedirect(redirect);
} else {
1.7 +4 -10
cocoon-2.2/src/java/org/apache/cocoon/environment/commandline/AbstractCommandLineEnvironment.java
Index: AbstractCommandLineEnvironment.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/commandline/AbstractCommandLineEnvironment.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AbstractCommandLineEnvironment.java 29 Oct 2003 18:58:06 -0000
1.6
+++ AbstractCommandLineEnvironment.java 30 Oct 2003 12:20:45 -0000
1.7
@@ -56,7 +56,6 @@
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.components.source.SourceUtil;
import org.apache.cocoon.environment.AbstractEnvironment;
-import org.apache.cocoon.environment.Redirector;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceException;
import org.xml.sax.SAXException;
@@ -75,8 +74,7 @@
*/
public abstract class AbstractCommandLineEnvironment
-extends AbstractEnvironment
-implements Redirector {
+extends AbstractEnvironment {
protected String contentType;
protected int contentLength;
@@ -96,16 +94,12 @@
}
/**
- * Redirect the client to a new URL
+ * Redirect to the given URL
*/
- public void redirect(boolean sessionmode, String newURL)
+ public void redirect(String newURL, boolean permanent)
throws IOException {
this.hasRedirected = true;
-
- if (sessionmode) {
- CommandLineSession.getSession(true);
- }
// fix all urls created with request.getScheme()+... etc.
if (newURL.startsWith("cli:/")) {