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
51 public class Redirect extends AbstractActionResult {
52
53 private static final Logger logger = Logger.getLogger(Redirect.class);
54
55 private final String path;
56
57
58
59
60
61
62
63 public Redirect(final String path) {
64 this.path = path;
65 }
66
67
68
69
70
71
72 public String getPath() {
73 return this.path;
74 }
75
76
77
78
79 public void execute(final ActionContext context,
80 final HttpServletRequest request, final HttpServletResponse response)
81 throws Exception {
82
83 final String absolutePath;
84 final String contextPath;
85 if ("/".equals(request.getContextPath())) {
86 contextPath = "";
87 } else {
88 contextPath = request.getContextPath();
89 }
90 if (this.path.startsWith("/")) {
91 absolutePath = contextPath + this.path;
92 } else {
93 final String actionDirectory = CubbyUtils
94 .getActionDirectory(context.getComponentDef()
95 .getComponentClass());
96 if (StringUtil.isEmpty(actionDirectory)) {
97 absolutePath = contextPath + "/" + this.path;
98 } else {
99 absolutePath = contextPath + "/" + actionDirectory + "/"
100 + this.path;
101 }
102 }
103 if (logger.isDebugEnabled()) {
104 logger.log("DCUB0003", new String[] { absolutePath });
105 }
106 response.sendRedirect(absolutePath);
107 }
108
109 }