001: package de.webman.template.jsp;
002:
003: import javax.servlet.*;
004: import javax.servlet.http.*;
005: import java.util.*;
006: import java.io.*;
007:
008: /**
009: Implementierung des HttpRequest fuer die Abarbeitung der jsp Templates
010: * @author $Author: alex $
011: * @version $Revision: 1.5 $
012: */
013: public class WebManRequest implements HttpServletRequest {
014: private static final String ATTRIBUTE = "wm-data";
015:
016: private Hashtable attributes = new Hashtable();
017:
018: private HttpServletRequest originalRequest;
019:
020: private WebManSession session;
021:
022: private ServletContext context;
023:
024: public WebManRequest(ServletContext _context) {
025: context = _context;
026: }
027:
028: /*
029: public WebManRequest(Object _data, HttpServletRequest _originalRequest)
030: {
031: attributes.put(ATTRIBUTE, _data);
032: originalRequest = _originalRequest;
033: }
034: */
035: public void setData(Object data) {
036: attributes.put(ATTRIBUTE, data);
037: }
038:
039: public void setOriginalRequest(HttpServletRequest _originalRequest) {
040: originalRequest = _originalRequest;
041: }
042:
043: /**
044: * Returns an input stream for reading binary data in the request body.
045: *
046: * @see getReader
047: * @exception IllegalStateException if getReader has been
048: * called on this same request.
049: * @exception IOException on other I/O related errors.
050: */
051: public ServletInputStream getInputStream() throws IOException {
052: return null; // ???
053: }
054:
055: /**
056: * Returns a string containing the lone value of the specified
057: * parameter, or null if the parameter does not exist. For example,
058: * in an HTTP servlet this method would return the value of the
059: * specified query string parameter. Servlet writers should use
060: * this method only when they are sure that there is only one value
061: * for the parameter. If the parameter has (or could have)
062: * multiple values, servlet writers should use
063: * getParameterValues. If a multiple valued parameter name is
064: * passed as an argument, the return value is implementation
065: * dependent.
066: *
067: * @see #getParameterValues
068: *
069: * @param name the name of the parameter whose value is required.
070: */
071: public String getParameter(String name) {
072: // ausfuellen !!
073: return "";
074: }
075:
076: /**
077: * Returns the values of the specified parameter for the request as
078: * an array of strings, or null if the named parameter does not
079: * exist. For example, in an HTTP servlet this method would return
080: * the values of the specified query string or posted form as an
081: * array of strings.
082: *
083: * @param name the name of the parameter whose value is required.
084: * @see javax.servlet.ServletRequest#getParameter
085: */
086: public String[] getParameterValues(String name) {
087: return null;
088: }
089:
090: /**
091: * Returns the parameter names for this request as an enumeration
092: * of strings, or an empty enumeration if there are no parameters
093: * or the input stream is empty. The input stream would be empty
094: * if all the data had been read from the stream returned by the
095: * method getInputStream.
096: */
097: public Enumeration getParameterNames() {
098: return null;
099: }
100:
101: /**
102: * Returns the value of the named attribute of the request, or
103: * null if the attribute does not exist. This method allows
104: * access to request information not already provided by the other
105: * methods in this interface. Attribute names should follow the
106: * same convention as package names.
107: * @param name the name of the attribute whose value is required
108: */
109: public Object getAttribute(String name) {
110: return attributes.get(name);
111: }
112:
113: public java.lang.String getContextPath() {
114: if (originalRequest != null)
115: return originalRequest.getContextPath();
116: return "";
117: }
118:
119: public java.util.Enumeration getHeaders(java.lang.String name) {
120: if (originalRequest != null)
121: return originalRequest.getHeaders(name);
122: return null;
123: }
124:
125: public boolean isUserInRole(java.lang.String role) {
126: return false;
127: }
128:
129: public boolean isRequestedSessionIdFromURL() {
130: if (originalRequest != null)
131: return originalRequest.isRequestedSessionIdFromURL();
132: return false;
133: }
134:
135: public java.security.Principal getUserPrincipal() {
136: return null;
137: }
138:
139: public java.util.Locale getLocale() {
140: if (originalRequest != null)
141: return originalRequest.getLocale();
142: return null;
143: }
144:
145: public boolean isSecure() {
146: return false;
147: }
148:
149: public void removeAttribute(java.lang.String name) {
150: }
151:
152: public void setAttribute(java.lang.String name, java.lang.Object o) {
153: }
154:
155: public RequestDispatcher getRequestDispatcher(java.lang.String path) {
156: if (originalRequest != null)
157: return originalRequest.getRequestDispatcher(path);
158: return null;
159: }
160:
161: public java.util.Enumeration getLocales() {
162: return null;
163: }
164:
165: public java.util.Enumeration getAttributeNames() {
166: return attributes.keys();
167: }
168:
169: /**
170: * Returns a buffered reader for reading text in the request body.
171: * This translates character set encodings as appropriate.
172: *
173: * @see getInputStream
174: *
175: * @exception UnsupportedEncodingException if the character set encoding
176: * is unsupported, so the text can't be correctly decoded.
177: * @exception IllegalStateException if getInputStream has been
178: * called on this same request.
179: * @exception IOException on other I/O related errors.
180: */
181: public BufferedReader getReader() throws IOException {
182: return null;
183: }
184:
185: /**
186: * Returns the character set encoding for the input of this request.
187: */
188: public String getCharacterEncoding() {
189: if (originalRequest != null)
190: return originalRequest.getCharacterEncoding();
191: return null;
192: }
193:
194: /**
195: * Gets the array of cookies found in this request.
196: *
197: * @return the array of cookies found in this request
198: */
199: public Cookie[] getCookies() {
200: return null;
201: }
202:
203: /**
204: * Gets the HTTP method (for example, GET, POST, PUT) with which
205: * this request was made. Same as the CGI variable REQUEST_METHOD.
206: *
207: * @return the HTTP method with which this request was made
208: */
209: public String getMethod() {
210: if (originalRequest != null)
211: return originalRequest.getMethod();
212: return "POST";
213: }
214:
215: /**
216: * Gets, from the first line of the HTTP request, the part of this
217: * request's URI that is to the left of any query string.
218: *
219: *
220: * @return this request's URI
221: */
222: public String getRequestURI() {
223: if (originalRequest != null)
224: return originalRequest.getRequestURI();
225: return "";
226: }
227:
228: /**
229: 2.3
230: Overrides the name of the character encoding used in the body of this request.
231: This method must be called prior to reading request parameters or reading input using getReader()
232: */
233: public void setCharacterEncoding(java.lang.String env)
234: throws java.io.UnsupportedEncodingException
235:
236: {
237: }
238:
239: /**
240: 2.3
241: Returns a java.util.Map of the parameters of this request.
242: Request parameters are extra information sent with the request.
243: For HTTP servlets, parameters are contained in the query string or posted form data.
244: */
245: public java.util.Map getParameterMap() {
246: return null;
247: }
248:
249: /**
250: 2.3
251: Reconstructs the URL the client used to make the request.
252: The returned URL contains a protocol, server name, port number, and server path,
253: but it does not include query string parameters.
254: Because this method returns a StringBuffer, not a string, you can modify the URL easily,
255: for example, to append query parameters.
256: This method is useful for creating redirect messages and for reporting errors.
257: */
258: public java.lang.StringBuffer getRequestURL() {
259: if (originalRequest != null)
260: return new StringBuffer("");
261: return new StringBuffer("");
262: }
263:
264: /**
265: * Gets the part of this request's URI that refers to the servlet
266: * being invoked. Analogous to the CGI variable SCRIPT_NAME.
267: *
268: * @return the servlet being invoked, as contained in this
269: * request's URI
270: */
271: public String getServletPath() {
272: if (originalRequest != null)
273: return originalRequest.getServletPath();
274: return "";
275: }
276:
277: /**
278: * Gets any optional extra path information following the servlet
279: * path of this request's URI, but immediately preceding its query
280: * string. Same as the CGI variable PATH_INFO.
281: *
282: * @return the optional path information following the servlet
283: * path, but before the query string, in this request's URI; null
284: * if this request's URI contains no extra path information
285: */
286: public String getPathInfo() {
287: if (originalRequest != null)
288: return originalRequest.getPathInfo();
289: return null;
290: }
291:
292: /**
293: * Gets any optional extra path information following the servlet
294: * path of this request's URI, but immediately preceding its query
295: * string, and translates it to a real path. Similar to the CGI
296: * variable PATH_TRANSLATED
297: *
298: * @return extra path information translated to a real path or null
299: * if no extra path information is in the request's URI
300: */
301: public String getPathTranslated() {
302: if (originalRequest != null)
303: return originalRequest.getPathTranslated();
304: return null;
305: }
306:
307: /**
308: * Gets any query string that is part of the HTTP request URI.
309: * Same as the CGI variable QUERY_STRING.
310: *
311: * @return query string that is part of this request's URI, or null
312: * if it contains no query string
313: */
314: public String getQueryString() {
315: if (originalRequest != null)
316: return originalRequest.getQueryString();
317: return null;
318: }
319:
320: /**
321: * Gets the name of the user making this request. The user name is
322: * set with HTTP authentication. Whether the user name will
323: * continue to be sent with each subsequent communication is
324: * browser-dependent. Same as the CGI variable REMOTE_USER.
325: *
326: * @return the name of the user making this request, or null if not
327: * known.
328: */
329: public String getRemoteUser() {
330: if (originalRequest != null)
331: return originalRequest.getRemoteUser();
332: return null;
333: }
334:
335: /**
336: * Gets the authentication scheme of this request. Same as the CGI
337: * variable AUTH_TYPE.
338: *
339: * @return this request's authentication scheme, or null if none.
340: */
341: public String getAuthType() {
342: return null;
343: }
344:
345: /**
346: * Gets the value of the requested header field of this request.
347: * The case of the header field name is ignored.
348: *
349: * @param name the String containing the name of the requested
350: * header field
351: * @return the value of the requested header field, or null if not
352: * known.
353: */
354: public String getHeader(String name) {
355: return null;
356: }
357:
358: /**
359: * Gets the value of the specified integer header field of this
360: * request. The case of the header field name is ignored. If the
361: * header can't be converted to an integer, the method throws a
362: * NumberFormatException.
363: *
364: * @param name the String containing the name of the requested
365: * header field
366: * @return the value of the requested header field, or -1 if not
367: * found.
368: */
369: public int getIntHeader(String name) {
370: return -1;
371: }
372:
373: /**
374: * Gets the value of the requested date header field of this
375: * request. If the header can't be converted to a date, the method
376: * throws an IllegalArgumentException. The case of the header
377: * field name is ignored.
378: *
379: * @param name the String containing the name of the requested
380: * header field
381: * @return the value the requested date header field, or -1 if not
382: * found.
383: */
384: public long getDateHeader(String name) {
385: return -1;
386: }
387:
388: /**
389: * Gets the header names for this request.
390: *
391: * @return an enumeration of strings representing the header names
392: * for this request. Some server implementations do not allow
393: * headers to be accessed in this way, in which case this method
394: * will return null.
395: */
396: public Enumeration getHeaderNames() {
397: return null;
398: }
399:
400: /**
401: * Gets the current valid session associated with this request, if
402: * create is false or, if necessary, creates a new session for the
403: * request, if create is true.
404: *
405: *
406: * @return the session associated with this request or null if
407: * create was false and no valid session is associated
408: * with this request.
409: */
410: public HttpSession getSession(boolean create) {
411: if (session == null && create) {
412: session = new WebManSession(context);
413: }
414: return session;
415: }
416:
417: public HttpSession getSession() {
418: return getSession(true);
419: }
420:
421: /**
422: * Gets the session id specified with this request. This may
423: * differ from the actual session id. For example, if the request
424: * specified an id for an invalid session, then this will get a new
425: * session with a new id.
426: *
427: * @return the session id specified by this request, or null if the
428: * request did not specify a session id
429: *
430: * @see #isRequestedSessionIdValid */
431: public String getRequestedSessionId() {
432: return null;
433: }
434:
435: /**
436: * Checks whether this request is associated with a session that
437: * is valid in the current session context. If it is not valid,
438: * the requested session will never be returned from the
439: * <code>getSession</code> method.
440: *
441: * @return true if this request is assocated with a session that is
442: * valid in the current session context.
443: *
444: * @see #getRequestedSessionId
445: * @see javax.servlet.http.HttpSessionContext
446: * @see #getSession
447: */
448: public boolean isRequestedSessionIdValid() {
449: return false;
450: }
451:
452: /**
453: * Checks whether the session id specified by this request came in
454: * as a cookie. (The requested session may not be one returned by
455: * the <code>getSession</code> method.)
456: *
457: * @return true if the session id specified by this request came in
458: * as a cookie; false otherwise
459: *
460: * @see #getSession
461: */
462: public boolean isRequestedSessionIdFromCookie() {
463: return false;
464: }
465:
466: /**
467: * Checks whether the session id specified by this request came in
468: * as part of the URL. (The requested session may not be the one
469: * returned by the <code>getSession</code> method.)
470: *
471: * @return true if the session id specified by the request for this
472: * session came in as part of the URL; false otherwise
473: *
474: * @see #getSession
475: @deprecated
476: */
477: public boolean isRequestedSessionIdFromUrl() {
478: return false;
479: }
480:
481: /**
482: * Returns the size of the request entity data, or -1 if not known.
483: * Same as the CGI variable CONTENT_LENGTH.
484: */
485: public int getContentLength() {
486: return -1; // Vielleicht aendern ?
487: }
488:
489: /**
490: * Returns the Internet Media Type of the request entity data, or
491: * null if not known. Same as the CGI variable CONTENT_TYPE.
492: */
493: public String getContentType() {
494: if (originalRequest != null)
495: return originalRequest.getContentType();
496: return null;
497: }
498:
499: /**
500: * Returns the protocol and version of the request as a string of
501: * the form <code><protocol>/<major version>.<minor
502: * version></code>. Same as the CGI variable SERVER_PROTOCOL.
503: */
504: public String getProtocol() {
505: if (originalRequest != null)
506: return originalRequest.getProtocol();
507: return null;
508: }
509:
510: /**
511: * Returns the scheme of the URL used in this request, for example
512: * "http", "https", or "ftp". Different schemes have different
513: * rules for constructing URLs, as noted in RFC 1738. The URL used
514: * to create a request may be reconstructed using this scheme, the
515: * server name and port, and additional information such as URIs.
516: */
517: public String getScheme() {
518: if (originalRequest != null)
519: return originalRequest.getScheme();
520: return null;
521: }
522:
523: /**
524: * Returns the host name of the server that received the request.
525: * Same as the CGI variable SERVER_NAME.
526: */
527: public String getServerName() {
528: if (originalRequest != null)
529: return originalRequest.getServerName();
530: return null;
531: }
532:
533: /**
534: * Returns the port number on which this request was received.
535: * Same as the CGI variable SERVER_PORT.
536: */
537: public int getServerPort() {
538: if (originalRequest != null)
539: return originalRequest.getServerPort();
540: return 0;
541: }
542:
543: /**
544: * Returns the IP address of the agent that sent the request.
545: * Same as the CGI variable REMOTE_ADDR.
546: */
547: public String getRemoteAddr() {
548: return null;
549: }
550:
551: /**
552: * Returns the fully qualified host name of the agent that sent the
553: * request. Same as the CGI variable REMOTE_HOST.
554: */
555: public String getRemoteHost() {
556: return null;
557: }
558:
559: /**
560: * Applies alias rules to the specified virtual path and returns
561: * the corresponding real path, or null if the translation can not
562: * be performed for any reason. For example, an HTTP servlet would
563: * resolve the path using the virtual docroot, if virtual hosting
564: * is enabled, and with the default docroot otherwise. Calling
565: * this method with the string "/" as an argument returns the
566: * document root.
567: *
568: * @param path the virtual path to be translated to a real path
569: @deprecated
570: */
571: public String getRealPath(String path) {
572: if (originalRequest != null)
573: return originalRequest.getRealPath(path);
574: return null;
575: }
576:
577: }
|