Coverage Report - org.seasar.cubby.action.Redirect
 
Classes in this File Line Coverage Branch Coverage Complexity
Redirect
100%
18/18
N/A
3
 
 1  
 package org.seasar.cubby.action;
 2  
 
 3  
 import javax.servlet.http.HttpServletRequest;
 4  
 import javax.servlet.http.HttpServletResponse;
 5  
 
 6  
 import org.seasar.cubby.controller.ActionContext;
 7  
 import org.seasar.cubby.util.CubbyUtils;
 8  
 import org.seasar.framework.log.Logger;
 9  
 import org.seasar.framework.util.StringUtil;
 10  
 
 11  
 /**
 12  
  * ?定されたパスにリ?イレクトす? {@link ActionResult} です??
 13  
  * <p>
 14  
  * アクションメソ?ド?戻り?としてこ?インスタンスを指定することで、指定されたパスにリ?イレクトします??
 15  
  * </p>
 16  
  * <p>
 17  
  * 使用?1 : リ?イレクト?を相対パスで??
 18  
  * 
 19  
  * <pre>
 20  
  * return new Redirect(&quot;list&quot;);
 21  
  * </pre>
 22  
  * 
 23  
  * </p>
 24  
  * <p>
 25  
  * 使用?2 : リ?イレクト?を絶対パスで??
 26  
  * 
 27  
  * <pre>
 28  
  * return new Redirect(&quot;/todo/list&quot;);
 29  
  * </pre>
 30  
  * 
 31  
  * </p>
 32  
  * 
 33  
  * @author baba
 34  
  */
 35  
 public class Redirect extends AbstractActionResult {
 36  
 
 37  1
         private static final Logger logger = Logger.getLogger(Redirect.class);
 38  
 
 39  
         private final String path;
 40  
 
 41  
         /**
 42  
          * インスタンスを生成します??
 43  
          * 
 44  
          * @param path
 45  
          *            リ?イレクト??パス
 46  
          */
 47  4
         public Redirect(final String path) {
 48  4
                 this.path = path;
 49  4
         }
 50  
 
 51  
         public void execute(final ActionContext context,
 52  
                         final HttpServletRequest request, final HttpServletResponse response)
 53  
                         throws Exception {
 54  
 
 55  
                 final String absolutePath;
 56  
                 final String contextPath;
 57  4
                 if ("/".equals(request.getContextPath())) {
 58  1
                         contextPath = "";
 59  1
                 } else {
 60  3
                         contextPath = request.getContextPath();
 61  
                 }
 62  4
                 if (this.path.startsWith("/")) {
 63  1
                         absolutePath = contextPath + this.path;
 64  1
                 } else {
 65  3
                         final String actionClassName = CubbyUtils
 66  
                                         .getActionClassName(context.getComponentDef()
 67  
                                                         .getComponentClass());
 68  3
                         if (StringUtil.isEmpty(actionClassName)) {
 69  
                                 absolutePath = contextPath + "/" + this.path;
 70  
                         } else {
 71  3
                                 absolutePath = contextPath + "/" + actionClassName + "/"
 72  
                                                 + this.path;
 73  
                         }
 74  
                 }
 75  4
                 if (logger.isDebugEnabled()) {
 76  4
                         logger.log("DCUB0003", new String[] { absolutePath });
 77  
                 }
 78  4
                 response.sendRedirect(absolutePath);
 79  4
         }
 80  
 
 81  
 }