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 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
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 | |
|
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 | |
} |