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 import javax.servlet.http.HttpSession;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27 /***
28 * PortletServletRequestWrapper
29 *
30 * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
31 * @version $Id: PortletServletRequestWrapper.java 510753 2007-02-23 01:28:50Z ate $
32 */
33 public class PortletServletRequestWrapper extends HttpServletRequestWrapper
34 {
35 private static final Log log = LogFactory.getLog(PortletServletRequestWrapper.class);
36 private ServletContext context;
37 private HttpSession session;
38
39 public PortletServletRequestWrapper(ServletContext context, HttpServletRequest request, HttpSession proxiedSession)
40 {
41 super(request);
42 this.context = context;
43 session = proxiedSession;
44 if ( proxiedSession == null )
45 {
46 session = request.getSession();
47 }
48 }
49
50 public String getPathInfo()
51 {
52 return (String) getAttribute("javax.servlet.include.path_info");
53 }
54
55 public String getContextPath()
56 {
57 return (String) getAttribute("javax.servlet.include.context_path");
58 }
59
60 public String getRequestURI()
61 {
62 return (String) getAttribute("javax.servlet.include.request_uri");
63 }
64
65 public String getServletPath()
66 {
67 return (String) getAttribute("javax.servlet.include.servlet_path");
68 }
69
70 public String getQueryString()
71 {
72 return (String) getAttribute("javax.servlet.include.query_string");
73 }
74
75 public RequestDispatcher getRequestDispatcher(String relativePath)
76 {
77
78
79
80
81
82
83
84
85
86 String path;
87 if (!relativePath.startsWith("/"))
88 {
89 path = getServletPath();
90 path = path.substring(0, path.lastIndexOf('/')) + '/'
91 + relativePath;
92 } else
93 path = relativePath;
94
95
96
97
98
99
100
101 RequestDispatcher dispatcher = context.getRequestDispatcher(path);
102 if (dispatcher != null)
103 return new PortletServletRequestDispatcher(dispatcher, path, false);
104 else
105 return null;
106 }
107
108 public HttpSession getSession()
109 {
110 return session;
111 }
112 }