1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.cubby.action; |
17 | |
|
18 | |
import java.io.IOException; |
19 | |
|
20 | |
import javax.servlet.RequestDispatcher; |
21 | |
import javax.servlet.ServletException; |
22 | |
import javax.servlet.http.HttpServletRequest; |
23 | |
import javax.servlet.http.HttpServletResponse; |
24 | |
|
25 | |
import org.seasar.cubby.controller.ActionContext; |
26 | |
import org.seasar.cubby.util.CubbyUtils; |
27 | |
import org.seasar.framework.log.Logger; |
28 | |
import org.seasar.framework.util.StringUtil; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public class Forward extends AbstractActionResult { |
56 | |
|
57 | 1 | private static final Logger logger = Logger.getLogger(Forward.class); |
58 | |
|
59 | |
private final String path; |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | 4 | public Forward(final String path) { |
68 | 4 | this.path = path; |
69 | 4 | } |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
public String getPath() { |
77 | 1 | return this.path; |
78 | |
} |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
public void execute(final ActionContext context, |
84 | |
final HttpServletRequest request, final HttpServletResponse response) |
85 | |
throws ServletException, IOException { |
86 | 3 | final Action action = context.getAction(); |
87 | 3 | final String actionDirectory = CubbyUtils.getActionDirectory(context |
88 | |
.getComponentDef().getComponentClass()); |
89 | |
|
90 | |
final String absolutePath; |
91 | 3 | if (this.path.startsWith("/")) { |
92 | 1 | absolutePath = this.path; |
93 | 2 | } else if (StringUtil.isEmpty(actionDirectory)) { |
94 | 0 | absolutePath = "/" + this.path; |
95 | |
} else { |
96 | 2 | absolutePath = "/" + actionDirectory + "/" + this.path; |
97 | |
} |
98 | 3 | if (logger.isDebugEnabled()) { |
99 | 3 | logger.log("DCUB0001", new String[] { absolutePath }); |
100 | |
} |
101 | 3 | final RequestDispatcher dispatcher = request |
102 | |
.getRequestDispatcher(absolutePath); |
103 | 3 | dispatcher.forward(request, response); |
104 | 3 | if (logger.isDebugEnabled()) { |
105 | 3 | logger.log("DCUB0002", new String[] { absolutePath }); |
106 | |
} |
107 | 3 | action.postrender(); |
108 | |
|
109 | 3 | action.getFlash().clear(); |
110 | 3 | } |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
@Override |
119 | |
public void prerender(final ActionContext context) { |
120 | 1 | final Action action = context.getAction(); |
121 | 1 | action.prerender(); |
122 | 1 | } |
123 | |
|
124 | |
} |