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 ; 12 13 14 23 public class RedirectStep implements Step { 24 private String _uri; 25 26 public void setUri(String uri) { 27 _uri = uri; 28 } 29 30 33 public String getName() { 34 return ClassUtils.getShortClassName(getClass()); 35 } 36 37 40 public void execute(Result st) { 41 CocoonContext ctx = (CocoonContext) st.getContext(); 42 String link; 43 44 if (_uri == null) { 45 throw new IllegalStateException ("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 e) { 57 st.error(e); 58 } 59 } 60 } 61 | Popular Tags |