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 | |
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 | |
|
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 | |
|
87 | |
|
88 | |
|
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 | |
} |