1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.cubby.action;
17
18 import javax.servlet.http.HttpServletRequest;
19 import javax.servlet.http.HttpServletResponse;
20
21 import org.seasar.cubby.controller.ActionContext;
22 import org.seasar.cubby.util.CubbyUtils;
23 import org.seasar.framework.log.Logger;
24 import org.seasar.framework.util.StringUtil;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 public class Redirect extends AbstractActionResult {
51
52 private static final Logger logger = Logger.getLogger(Redirect.class);
53
54 private final String path;
55
56
57
58
59
60
61
62 public Redirect(final String path) {
63 this.path = path;
64 }
65
66
67
68
69
70 public String getPath() {
71 return this.path;
72 }
73
74 public void execute(final ActionContext context,
75 final HttpServletRequest request, final HttpServletResponse response)
76 throws Exception {
77
78 final String absolutePath;
79 final String contextPath;
80 if ("/".equals(request.getContextPath())) {
81 contextPath = "";
82 } else {
83 contextPath = request.getContextPath();
84 }
85 if (this.path.startsWith("/")) {
86 absolutePath = contextPath + this.path;
87 } else {
88 final String actionClassName = CubbyUtils
89 .getActionClassName(context.getComponentDef()
90 .getComponentClass());
91 if (StringUtil.isEmpty(actionClassName)) {
92 absolutePath = contextPath + "/" + this.path;
93 } else {
94 absolutePath = contextPath + "/" + actionClassName + "/"
95 + this.path;
96 }
97 }
98 if (logger.isDebugEnabled()) {
99 logger.log("DCUB0003", new String[] { absolutePath });
100 }
101 response.sendRedirect(absolutePath);
102 }
103
104 }