KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > state > cocoon > RedirectStep


1 package org.sapia.soto.state.cocoon;
2
3 import org.apache.cocoon.environment.http.HttpResponse;
4
5 import org.apache.commons.lang.ClassUtils;
6
7 import org.sapia.soto.state.Result;
8 import org.sapia.soto.state.Step;
9 import org.sapia.soto.util.Utils;
10
11 import java.io.IOException JavaDoc;
12
13
14 /**
15  * @author Yanick Duchesne
16  *
17  * <dl>
18  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2004 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
19  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
20  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
21  * </dl>
22  */

23 public class RedirectStep implements Step {
24   private String JavaDoc _uri;
25
26   public void setUri(String JavaDoc uri) {
27     _uri = uri;
28   }
29
30   /**
31    * @see org.sapia.soto.state.Step#getName()
32    */

33   public String JavaDoc getName() {
34     return ClassUtils.getShortClassName(getClass());
35   }
36
37   /**
38    * @see org.sapia.soto.state.Executable#execute(org.sapia.soto.state.Result)
39    */

40   public void execute(Result st) {
41     CocoonContext ctx = (CocoonContext) st.getContext();
42     String JavaDoc link;
43
44     if (_uri == null) {
45       throw new IllegalStateException JavaDoc("Redirect URI not specified");
46     } else if (Utils.hasScheme(_uri)) {
47       link = _uri;
48     } else {
49       link = "http://" + ctx.getRequest().getServerName() + ":" +
50         ctx.getRequest().getServerPort() + ctx.getRequest().getContextPath() +
51         '/' + _uri;
52     }
53
54     try {
55       ((HttpResponse) ctx.getResponse()).sendRedirect(link);
56     } catch (IOException JavaDoc e) {
57       st.error(e);
58     }
59   }
60 }
61
Popular Tags