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 private static final Logger logger = Logger.getLogger(Redirect.class);
38
39 private final String path;
40
41
42
43
44
45
46
47 public Redirect(final String path) {
48 this.path = path;
49 }
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 if ("/".equals(request.getContextPath())) {
58 contextPath = "";
59 } else {
60 contextPath = request.getContextPath();
61 }
62 if (this.path.startsWith("/")) {
63 absolutePath = contextPath + this.path;
64 } else {
65 final String actionClassName = CubbyUtils
66 .getActionClassName(context.getComponentDef()
67 .getComponentClass());
68 if (StringUtil.isEmpty(actionClassName)) {
69 absolutePath = contextPath + "/" + this.path;
70 } else {
71 absolutePath = contextPath + "/" + actionClassName + "/"
72 + this.path;
73 }
74 }
75 if (logger.isDebugEnabled()) {
76 logger.log("DCUB0003", new String[] { absolutePath });
77 }
78 response.sendRedirect(absolutePath);
79 }
80
81 }