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
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public class Forward extends AbstractActionResult {
44
45 private final Logger logger = Logger.getLogger(this.getClass());
46
47 private final String path;
48
49
50
51
52
53
54
55 public Forward(final String path) {
56 this.path = path;
57 }
58
59 public void execute(final ActionContext context,
60 final HttpServletRequest request, final HttpServletResponse response)
61 throws ServletException, IOException {
62 final Action action = context.getAction();
63 final String actionClassName = CubbyUtils.getActionClassName(context
64 .getComponentDef().getComponentClass());
65
66 final String absolutePath;
67 if (this.path.startsWith("/")) {
68 absolutePath = this.path;
69 } else if (StringUtil.isEmpty(actionClassName)) {
70 absolutePath = "/" + this.path;
71 } else {
72 absolutePath = "/" + actionClassName + "/" + this.path;
73 }
74 final HttpServletRequest wrappedRequest = new ForwardHttpServletRequestWrapper(
75 request, context);
76 if (logger.isDebugEnabled()) {
77 logger.log("DCUB0001", new String[] { absolutePath });
78 }
79 final RequestDispatcher dispatcher = request
80 .getRequestDispatcher(absolutePath);
81 dispatcher.forward(wrappedRequest, response);
82 if (logger.isDebugEnabled()) {
83 logger.log("DCUB0002", new String[] { absolutePath });
84 }
85 action.postrender();
86
87 action.getFlash().clear();
88 }
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104 @Override
105 public void prerender(final ActionContext context,
106 final HttpServletRequest request) {
107
108 final Action action = context.getAction();
109 action.prerender();
110 }
111
112 }