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