1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.portals.bridges.struts;
17
18 import javax.servlet.RequestDispatcher;
19 import javax.servlet.ServletContext;
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletRequestWrapper;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26 /***
27 * PortletServletRequestWrapper
28 *
29 * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
30 * @version $Id: PortletServletRequestWrapper.java 188278 2005-01-28 01:09:23 +0100 (Fri, 28 Jan 2005) ate $
31 */
32 public class PortletServletRequestWrapper extends HttpServletRequestWrapper
33 {
34 private static final Log log = LogFactory.getLog(PortletServletRequestWrapper.class);
35 private ServletContext context;
36 public PortletServletRequestWrapper(ServletContext context, HttpServletRequest request)
37 {
38 super(request);
39 this.context = context;
40 }
41
42 public String getPathInfo()
43 {
44 return (String) getAttribute("javax.servlet.include.path_info");
45 }
46
47 public String getContextPath()
48 {
49 return (String) getAttribute("javax.servlet.include.context_path");
50 }
51
52 public String getRequestURI()
53 {
54 return (String) getAttribute("javax.servlet.include.request_uri");
55 }
56
57 public String getServletPath()
58 {
59 return (String) getAttribute("javax.servlet.include.servlet_path");
60 }
61
62 public String getQueryString()
63 {
64 return (String) getAttribute("javax.servlet.include.query_string");
65 }
66
67 public RequestDispatcher getRequestDispatcher(String relativePath)
68 {
69
70
71
72
73
74
75
76
77
78 String path;
79 if (!relativePath.startsWith("/"))
80 {
81 path = getServletPath();
82 path = path.substring(0, path.lastIndexOf('/')) + '/'
83 + relativePath;
84 } else
85 path = relativePath;
86
87
88
89
90
91
92
93 RequestDispatcher dispatcher = context.getRequestDispatcher(path);
94 if (dispatcher != null)
95 return new PortletServletRequestDispatcher(dispatcher, path, false);
96 else
97 return null;
98 }
99 }