Coverage Report - org.seasar.cubby.action.Forward
 
Classes in this File Line Coverage Branch Coverage Complexity
Forward
100%
22/22
N/A
0
 
 1  
 package org.seasar.cubby.action;
 2  
 
 3  
 import java.io.IOException;
 4  
 
 5  
 import javax.servlet.RequestDispatcher;
 6  
 import javax.servlet.ServletException;
 7  
 import javax.servlet.http.HttpServletRequest;
 8  
 import javax.servlet.http.HttpServletResponse;
 9  
 
 10  
 import org.seasar.cubby.controller.ActionContext;
 11  
 import org.seasar.cubby.util.CubbyUtils;
 12  
 import org.seasar.framework.log.Logger;
 13  
 import org.seasar.framework.util.StringUtil;
 14  
 
 15  
 /**
 16  
  * ?定されたパスにフォワードす? {@link ActionResult} です??
 17  
  * <p>
 18  
  * アクションメソ?ド?戻り?としてこ?インスタンスを指定することで、指定されたパスにフォワードします??
 19  
  * </p>
 20  
  * <p>
 21  
  * 使用?1 : フォワード?を相対パスで??
 22  
  * 
 23  
  * <pre>
 24  
  * return new Forward(&quot;list.jsp&quot;);
 25  
  * </pre>
 26  
  * 
 27  
  * </p>
 28  
  * <p>
 29  
  * 使用?2 : フォワード?を絶対パスで??
 30  
  * 
 31  
  * <pre>
 32  
  * return new Forward(&quot;/todo/list.jsp&quot;);
 33  
  * </pre>
 34  
  * 
 35  
  * </p>
 36  
  * 
 37  
  * @author baba
 38  
  */
 39  
 public class Forward extends AbstractActionResult {
 40  
 
 41  1
         private static final Logger logger = Logger.getLogger(Forward.class);
 42  
 
 43  
         private final String path;
 44  
 
 45  
         /**
 46  
          * インスタンスを生成します??
 47  
          * 
 48  
          * @param path
 49  
          *            フォワード??パス
 50  
          */
 51  3
         public Forward(final String path) {
 52  3
                 this.path = path;
 53  3
         }
 54  
 
 55  
         public void execute(final ActionContext context,
 56  
                         final HttpServletRequest request, final HttpServletResponse response)
 57  
                         throws ServletException, IOException {
 58  3
                 final Action action = context.getAction();
 59  3
                 final String actionClassName = CubbyUtils.getActionClassName(context
 60  
                                 .getComponentDef().getComponentClass());
 61  
 
 62  
                 final String absolutePath;
 63  3
                 if (this.path.startsWith("/")) {
 64  1
                         absolutePath = this.path;
 65  1
                 } else if (StringUtil.isEmpty(actionClassName)) {
 66  
                         absolutePath = "/" + this.path;
 67  
                 } else {
 68  2
                         absolutePath = "/" + actionClassName + "/" + this.path;
 69  
                 }
 70  3
                 if (logger.isDebugEnabled()) {
 71  3
                         logger.log("DCUB0001", new String[] { absolutePath });
 72  
                 }
 73  3
                 final RequestDispatcher dispatcher = request
 74  
                                 .getRequestDispatcher(absolutePath);
 75  3
                 dispatcher.forward(request, response);
 76  3
                 if (logger.isDebugEnabled()) {
 77  3
                         logger.log("DCUB0002", new String[] { absolutePath });
 78  
                 }
 79  3
                 action.postrender();
 80  
 
 81  3
                 action.getFlash().clear();
 82  3
         }
 83  
 
 84  
         /**
 85  
          * フォワード前の処?を行います??
 86  
          * <p>
 87  
          * {@link Action#prerender()} を実行します??
 88  
          * </p>
 89  
          */
 90  
         @Override
 91  
         public void prerender(final ActionContext context) {
 92  1
                 final Action action = context.getAction();
 93  1
                 action.prerender();
 94  1
         }
 95  
 
 96  
 }