KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > request > RequestData


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.taglibs.request;
18
19 import javax.servlet.*;
20 import javax.servlet.http.*;
21 import javax.servlet.jsp.*;
22 import javax.servlet.jsp.tagext.*;
23
24 /**
25  * Stores the scripting variable data provided by the JSP Tag
26  * <b>request</b>, used to access HttpServletRequest information using
27  * the standard JSP &lt;jsp:getProperty&gt; tag.
28  * <p>
29  * The script variable of name <b>id</b> is available for use during
30  * processing of the remainder of the JSP page.
31  * <p>
32  *
33  * @see RequestTag
34  *
35  * @author Glenn Nielsen
36  */

37
38 public class RequestData
39 {
40     private HttpServletRequest req;
41
42     RequestData(HttpServletRequest request)
43     {
44         this.req = request;
45     }
46
47     /**
48      * Returns the name of the authentication scheme used to protect the
49      * servlet.
50      * <p>
51      * &lt;jsp:getProperty name=<i>"id"</i> property="authType"/&gt;
52      *
53      * @return String - "BASIC", "SSL," or "" if the servlet was not protected.
54      */

55     public final String JavaDoc getAuthType()
56     {
57     return req.getAuthType();
58     }
59
60     /**
61      * Returns the portion of the request URI that indicates the context
62      * of the request.
63      * <p>
64      * &lt;jsp:getProperty name=<i>"id"</i> property="contextPath"/&gt;
65      *
66      * @return String - request URI context path
67      */

68     public final String JavaDoc getContextPath()
69     {
70     return req.getContextPath();
71     }
72
73     /**
74      * Returns the name of the HTTP method with which this request was made.
75      * <p>
76      * &lt;jsp:getProperty name=<i>"id"</i> property="method"/&gt;
77      *
78      * @return String - "GET", "POST", or "PUT".
79      */

80     public final String JavaDoc getMethod()
81     {
82     return req.getMethod();
83     }
84
85     /**
86      * Returns any extra path information associated with the URL the
87      * client sent when it made this request.
88      * <p>
89      * &lt;jsp:getProperty name=<i>"id"</i> property="pathInfo"/&gt;
90      *
91      * @return String - path info portion of the request URL
92      */

93     public final String JavaDoc getPathInfo()
94     {
95     return req.getPathInfo();
96     }
97
98     /**
99      * Returns any extra path information after the servlet name but
100      * before the query string, and translates it to a real path.
101      * <p>
102      * &lt;jsp:getProperty name=<i>"id"</i> property="pathTranslated"/&gt;
103      *
104      * @return String - translated path information
105      */

106     public final String JavaDoc getPathTranslated()
107     {
108     return req.getPathTranslated();
109     }
110
111     /**
112      * Returns the query string that is contained in the request URL
113      * after the path.
114      * <p>
115      * &lt;jsp:getProperty name=<i>"id"</i> property="queryString"/&gt;
116      *
117      * @return String - query string from the URL
118      */

119     public final String JavaDoc getQueryString()
120     {
121     return req.getQueryString();
122     }
123
124     /**
125      * Returns the login of the user making this request, if the user has
126      * been authenticated, or "" if the user has not been authenticated.
127      * <p>
128      * &lt;jsp:getProperty name=<i>"id"</i> property="remoteUser"/&gt;
129      *
130      * @return String - remote user name or "" String
131      */

132     public final String JavaDoc getRemoteUser()
133     {
134     return req.getRemoteUser();
135     }
136
137     /**
138      * Returns the session ID specified by the client.
139      * <p>
140      * &lt;jsp:getProperty name=<i>"id"</i> property="requestedSessionId"/&gt;
141      *
142      * @return String - session ID
143      */

144     public final String JavaDoc getRequestedSessionId()
145     {
146     return req.getRequestedSessionId();
147     }
148
149     /**
150      * Returns the part of this request's URL from the protocol name up
151      * to the query string in the first line of the HTTP request.
152      * <p>
153      * &lt;jsp:getProperty name=<i>"id"</i> property="requestURI"/&gt;
154      *
155      * @return String - request URI
156      */

157     public final String JavaDoc getRequestURI()
158     {
159     return req.getRequestURI();
160     }
161
162     /**
163      * Returns the request URL up
164      * to the query string in the first line of the HTTP request.
165      * <p>
166      * &lt;jsp:getProperty name=<i>"id"</i> property="requestURL"/&gt;
167      *
168      * @return String - request URL
169      */

170     public final String JavaDoc getRequestURL()
171     {
172         return "" + HttpUtils.getRequestURL(req);
173     }
174
175     /**
176      * Returns the part of this request's URL that calls the servlet.
177      * <p>
178      * &lt;jsp:getProperty name=<i>"id"</i> property="servletPath"/&gt;
179      *
180      * @return String - servlet path
181      */

182     public final String JavaDoc getServletPath()
183     {
184     return req.getServletPath();
185     }
186
187     /**
188      * Returns the name of the character encoding used in the body of
189      * this request.
190      * <p>
191      * &lt;jsp:getProperty name=<i>"id"</i> property="characterEncoding"/&gt;
192      *
193      * @return String - character encoding
194      */

195     public final String JavaDoc getCharacterEncoding()
196     {
197     return req.getCharacterEncoding();
198     }
199
200     /**
201      * Returns the length, in bytes, of the request body and made available
202      * by the input stream, or -1 if the length is not known.
203      * <p>
204      * &lt;jsp:getProperty name=<i>"id"</i> property="contentLength"/&gt;
205      *
206      * @return String - content length or "-1"
207      */

208     public final String JavaDoc getContentLength()
209     {
210     return "" + req.getContentLength();
211     }
212
213     /**
214      * Returns the MIME type of the body of the request, or null if
215      * the type is not known.
216      * <p>
217      * &lt;jsp:getProperty name=<i>"id"</i> property="contentType"/&gt;
218      *
219      * @return String - content type
220      */

221     public final String JavaDoc getContentType()
222     {
223     return req.getContentType();
224     }
225
226     /**
227      * Returns the name and version of the protocol the request uses in the
228      * form protocol/majorVersion.minorVersion, for example, HTTP/1.1.
229      * <p>
230      * &lt;jsp:getProperty name=<i>"id"</i> property="protocol"/&gt;
231      *
232      * @return String - protocol of the request
233      */

234     public final String JavaDoc getProtocol()
235     {
236     return req.getProtocol();
237     }
238
239     /**
240      * Returns the Internet Protocol (IP) address of the client that
241      * sent the request.
242      * <p>
243      * &lt;jsp:getProperty name=<i>"id"</i> property="remoteAddr"/&gt;
244      *
245      * @return String - remote IP address
246      */

247     public final String JavaDoc getRemoteAddr()
248     {
249     return req.getRemoteAddr();
250     }
251
252     /**
253      * Returns the fully qualified name of the client that sent the request,
254      * or the IP address of the client if the name cannot be determined.
255      * <p>
256      * &lt;jsp:getProperty name=<i>"id"</i> property="remoteHost"/&gt;
257      *
258      * @return String - remote host
259      */

260     public final String JavaDoc getRemoteHost()
261     {
262     return req.getRemoteHost();
263     }
264
265     /**
266      * Returns the name of the scheme used to make this request, for
267      * example, http, https, or ftp.
268      * <p>
269      * &lt;jsp:getProperty name=<i>"id"</i> property="scheme"/&gt;
270      *
271      * @return String - scheme used to make the request
272      */

273     public final String JavaDoc getScheme()
274     {
275     return req.getScheme();
276     }
277
278     /**
279      * Returns the host name of the server that received the request.
280      * <p>
281      * &lt;jsp:getProperty name=<i>"id"</i> property="serverName"/&gt;
282      *
283      * @return String - host name of the server
284      */

285     public final String JavaDoc getServerName()
286     {
287     return req.getServerName();
288     }
289
290     /**
291      * Returns the port number on which this request was received.
292      * <p>
293      * &lt;jsp:getProperty name=<i>"id"</i> property="serverPort"/&gt;
294      *
295      * @return String - server port number
296      */

297     public final String JavaDoc getServerPort()
298     {
299     return "" + req.getServerPort();
300     }
301
302 }
303
Popular Tags