1 16 package org.apache.cocoon.environment; 17 18 import java.io.IOException ; 19 20 import org.apache.avalon.framework.logger.AbstractLogEnabled; 21 import org.apache.cocoon.ProcessingException; 22 import org.apache.cocoon.environment.wrapper.EnvironmentWrapper; 23 import org.apache.cocoon.environment.wrapper.MutableEnvironmentFacade; 24 25 34 public abstract class ForwardRedirector extends AbstractLogEnabled implements Redirector, PermanentRedirector { 35 36 39 private boolean hasRedirected = false; 40 41 42 protected Environment env; 43 44 public ForwardRedirector(Environment env) { 45 this.env = env; 46 } 47 48 53 public void redirect(boolean sessionMode, String url) throws IOException , ProcessingException { 54 if (getLogger().isInfoEnabled()) { 55 getLogger().info("Redirecting to '" + url + "'"); 56 } 57 58 if (url.startsWith("cocoon:")) { 59 cocoonRedirect(url); 60 } else { 61 this.env.redirect(sessionMode, url); 62 } 63 64 this.hasRedirected = true; 65 } 66 67 public void permanentRedirect(boolean sessionMode, String url) throws IOException , ProcessingException { 68 if (getLogger().isInfoEnabled()) { 69 getLogger().info("Redirecting to '" + url + "'"); 70 } 71 72 if (url.startsWith("cocoon:")) { 73 cocoonRedirect(url); 74 } else if (env instanceof PermanentRedirector) { 75 ((PermanentRedirector)env).permanentRedirect(sessionMode, url); 76 } else { 77 this.env.redirect(sessionMode, url); 78 } 79 80 this.hasRedirected = true; 81 } 82 83 87 public void globalRedirect(boolean sessionMode, String url) throws IOException , ProcessingException { 88 if (getLogger().isInfoEnabled()) { 89 getLogger().info("Redirecting to '" + url + "'"); 90 } 91 92 if (url.startsWith("cocoon:")) { 94 cocoonRedirect(url); 95 } else if (env instanceof MutableEnvironmentFacade ) { 96 ((MutableEnvironmentFacade)env).getDelegate().globalRedirect(sessionMode, url); 97 } else if (env instanceof EnvironmentWrapper) { 98 ((EnvironmentWrapper)env).globalRedirect(sessionMode,url); 99 } else { 100 this.env.redirect(sessionMode, url); 101 } 102 this.hasRedirected = true; 103 } 104 105 protected abstract void cocoonRedirect(String uri) throws IOException , ProcessingException; 106 107 110 public boolean hasRedirected() { 111 return this.hasRedirected; 112 } 113 114 117 public void sendStatus(int sc) { 118 env.setStatus(sc); 119 this.hasRedirected = true; 120 } 121 } 122 | Popular Tags |