Annotation of java/classes/org/w3c/jigsaw/servlet/JigsawHttpServletRequest.java, revision 1.2
1.1 abaird 1: // JigsawHttpServletRequest.java
1.2 ! abaird 2: // $Id: JigsawHttpServletRequest.java,v 1.1 1996/12/17 12:25:52 abaird Exp $
1.1 abaird 3: // (c) COPYRIGHT MIT and INRIA, 1996.
4: // Please first read the full copyright statement in file COPYRIGHT.html
5:
6: package w3c.jigsaw.servlet;
7:
8: import java.io.*;
9: import java.util.*;
10:
11: import java.servlet.*;
12: import java.servlet.http.*;
13:
14: import w3c.jigsaw.http.*;
15: import w3c.jigsaw.forms.*;
16: import w3c.www.http.*;
17: import w3c.jigsaw.auth.AuthFilter; // for auth infos access
1.2 ! abaird 18:
! 19: /**
! 20: * @author Alexandre Rafalovitch <alex@access.com.au>
! 21: * @author Anselm Baird-Smith <abaird@w3.org>
! 22: */
1.1 abaird 23:
24: public class JigsawHttpServletRequest implements HttpServletRequest {
25: /**
26: * The initial request.
27: */
28: private Request request;
29: /**
30: * The lazyly computed queryParameters hashtable.
31: */
32: private Hashtable queryParameters = null;
33:
34: private void prepareQueryParameters()
35: {
36: if( queryParameters != null )
37: return;
38: String query = request.getQueryString();
39: if (query == null)
40: return ;
41: InputStream qis = new StringBufferInputStream(query);
42: try {
43: queryParameters = new URLDecoder(qis).parse();
44: } catch (Exception ex) {
45: throw new RuntimeException("Java implementation bug.");
46: }
47: }
48:
49: public int getContentLength()
50: {
51: return request.getContentLength();
52: }
53:
54: public String getContentType()
55: {
56: return request.getContentType().toString();
57: }
58:
59: protected ServletInputStream is = null;
60: public ServletInputStream getInputStream()
61: {
62: // If alaredy computed return:
63: if ( is != null )
64: return is;
65: // Built it:
66: InputStream stream = null;
67: if ((stream = request.getClient().getInputStream()) != null)
68: return is = new JigsawServletInputStream(stream);
69: return null;
70: }
71:
72: public String getParameter(String name)
73: {
74: prepareQueryParameters();
75: if ( queryParameters != null )
76: return (String) queryParameters.get(name);
77: else
78: return null;
79: }
80:
81: public Hashtable getParameters()
82: {
83: prepareQueryParameters();
84: return queryParameters;
85: }
86:
87: public String getProtocol()
88: {
89: return request.getVersion();
90: }
91:
92: public String getRemoteAddr()
93: {
94: return request.getClient().getInetAddress().toString();
95: }
96:
97: public String getRemoteHost()
98: {
99: return request.getClient().getInetAddress().getHostName();
100: }
101:
102: public String getServerName()
103: {
104: return request.getClient().getServer().getHost();
105: }
106:
107: public int getServerPort()
108: {
109: return request.getClient().getServer().getLocalPort();
110: }
111:
112: /**
113: * HttpServletRequet implementation -
114: */
115:
116: public String getAuthType()
117: {
118: return (String) request.getState(AuthFilter.STATE_AUTHTYPE);
119: }
120:
121: public long getDateHeader(String name, long i)
122: {
123: String value = getHeader(name);
124: long longVal = i;
125:
126: if (value != null) {
127: try {
128: return longVal = Date.parse(value);
129: } catch(Exception e) {
130: }
131: }
132: return longVal;
133: }
134:
135: public String getHeader(int i) {
136: return null;
137: }
138:
139: public String getHeader(String name)
140: {
141: return request.getValue(name);
142: }
143:
144: public String getHeaderName(int i)
145: {
146: return null;
147: }
148:
149: public int getIntHeader(String name, int i)
150: {
151: String value = getHeader(name);
152: int intVal = i;
153:
154: if (value != null) {
155: try {
156: intVal = Integer.parseInt(value);
157: } catch(NumberFormatException eX) {
158: }
159: }
160: return intVal;
161: }
162:
163: public String getMethod()
164: {
165: return request.getMethod();
166: }
167:
168: public String getPathInfo()
169: {
170: return (String) request.getState(ServletWrapper.STATE_EXTRA_PATH);
171: }
172:
173: public String getPathTranslated()
174: {
175: return null;
176: }
177:
178: public String getQueryString()
179: {
180: // FIXME make sure this gets untranslated
181: return request.getQueryString();
182: }
183:
184: public String getRemoteUser()
185: {
186: return (String) request.getState(AuthFilter.STATE_AUTHUSER);
187: }
188:
189: public String getRequestURI()
190: {
191: return request.getURL().toExternalForm();
192: }
193:
194: public String getRequestPath()
195: {
196: return request.getURLPath();
197: }
198:
199: public String getServletPath()
200: {
201: return request.getTargetResource().getURL();
202: }
203:
204: JigsawHttpServletRequest(Request request)
205: {
206: this.request = request;
207: }
208:
209:
210: }
Webmaster