You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2004/02/21 19:06:09 UTC
cvs commit: cocoon-2.2/src/java/org/apache/cocoon/environment ForwardRedirector.java
cziegeler 2004/02/21 10:06:09
Modified: src/java/org/apache/cocoon/environment/internal
EnvironmentHelper.java
src/java/org/apache/cocoon/environment
ForwardRedirector.java
Log:
Put redirector code at a better place
Revision Changes Path
1.12 +1 -65 cocoon-2.2/src/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java
Index: EnvironmentHelper.java
===================================================================
RCS file: /home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- EnvironmentHelper.java 20 Feb 2004 20:34:37 -0000 1.11
+++ EnvironmentHelper.java 21 Feb 2004 18:06:09 -0000 1.12
@@ -64,9 +64,6 @@
import org.apache.cocoon.Processor;
import org.apache.cocoon.components.source.SourceUtil;
import org.apache.cocoon.environment.Environment;
-import org.apache.cocoon.environment.ObjectModelHelper;
-import org.apache.cocoon.environment.Request;
-import org.apache.cocoon.environment.Session;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.xml.XMLConsumer;
import org.apache.excalibur.source.Source;
@@ -311,67 +308,6 @@
}
}
- public void redirect(Environment env,
- boolean sessionmode,
- String newURL)
- throws IOException {
- this.doRedirect(env, sessionmode, newURL, false, false);
- }
-
- public void globalRedirect(Environment env,
- boolean sessionmode,
- String newURL)
- throws IOException {
- this.doRedirect(env, sessionmode, newURL, false, true);
- }
-
- public void permanentRedirect(Environment env, boolean sessionmode, String newURL)
- throws IOException {
- this.doRedirect(env, sessionmode, newURL, true, false);
- }
-
- /**
- * Redirect the client to new URL with session mode
- */
- protected void doRedirect(Environment env,
- boolean sessionmode,
- String newURL,
- boolean permanent,
- boolean global)
- 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
- env.redirect(newURL, global, 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.17 +54 -8 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.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- ForwardRedirector.java 20 Feb 2004 18:57:15 -0000 1.16
+++ ForwardRedirector.java 21 Feb 2004 18:06:09 -0000 1.17
@@ -54,7 +54,6 @@
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.environment.internal.EnvironmentHelper;
/**
* A <code>Redirector</code> that handles forward redirects, i.e. internal
@@ -63,7 +62,9 @@
* @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
* @version CVS $Id$
*/
-public abstract class ForwardRedirector extends AbstractLogEnabled implements Redirector, PermanentRedirector {
+public abstract class ForwardRedirector
+extends AbstractLogEnabled
+implements Redirector, PermanentRedirector {
/**
* Was there a call to <code>redirect()</code> ?
@@ -73,6 +74,9 @@
/** The <code>Environment to use for redirection (either internal or external) */
protected Environment env;
+ /**
+ * Constructor
+ */
public ForwardRedirector(Environment env) {
this.env = env;
}
@@ -90,7 +94,7 @@
if (url.startsWith("cocoon:")) {
cocoonRedirect(url);
} else {
- EnvironmentHelper.getCurrentProcessor().getEnvironmentHelper().redirect(this.env, sessionMode, url);
+ this.doRedirect(sessionMode, url, false, false);
}
this.hasRedirected = true;
@@ -104,7 +108,7 @@
if (url.startsWith("cocoon:")) {
cocoonRedirect(url);
} else {
- EnvironmentHelper.getCurrentProcessor().getEnvironmentHelper().permanentRedirect(this.env, sessionMode, url);
+ this.doRedirect(sessionMode, url, true, false);
}
this.hasRedirected = true;
@@ -123,15 +127,15 @@
if (url.startsWith("cocoon:")) {
cocoonRedirect(url);
} else {
- EnvironmentHelper.getCurrentProcessor().getEnvironmentHelper().globalRedirect(this.env, sessionMode, url);
+ this.doRedirect(sessionMode, url, false, true);
}
this.hasRedirected = true;
}
protected abstract void cocoonRedirect(String uri) throws IOException, ProcessingException;;
- /**
- * Perform check on whether redirection has occured or not
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Redirector#hasRedirected()
*/
public boolean hasRedirected() {
return this.hasRedirected;
@@ -143,6 +147,48 @@
public void sendStatus(int sc) {
env.setStatus(sc);
this.hasRedirected = true;
+ }
+
+
+ /**
+ * Redirect the client to new URL with session mode
+ */
+ protected void doRedirect(boolean sessionmode,
+ String newURL,
+ boolean permanent,
+ boolean global)
+ throws IOException {
+ final Request request = ObjectModelHelper.getRequest(this.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
+ this.env.redirect(newURL, global, permanent);
}
}