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 final Logger logger = Logger.getLogger(this.getClass());
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 = request.getContextPath();
57 if (this.path.charAt(0) == '/') {
58 absolutePath = contextPath + this.path;
59 } else {
60 final String actionClassName = CubbyUtils
61 .getActionClassName(context.getComponentDef()
62 .getComponentClass());
63 if (StringUtil.isEmpty(actionClassName)) {
64 absolutePath = contextPath + "/" + this.path;
65 } else {
66 absolutePath = contextPath + "/" + actionClassName + "/"
67 + this.path;
68 }
69 }
70 if (logger.isDebugEnabled()) {
71 logger.log("DCUB0003", new String[] { absolutePath });
72 }
73 response.sendRedirect(absolutePath);
74 }
75
76 }