001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.html;
021:
022: import java.lang.reflect.Method;
023: import java.security.Principal;
024: import java.util.*;
025:
026: import javax.portlet.ActionRequest;
027: import javax.portlet.PortletSession;
028: import javax.servlet.RequestDispatcher;
029: import javax.servlet.http.HttpServletRequest;
030: import javax.servlet.http.HttpSession;
031:
032: /**
033: * This class is a wrapper used by internal processes in the framework and isn't intended to be used directly. For more information see HttpServletRequest in the JSDK documentation.
034: */
035: public class HttpServletRequestWrapper implements HttpServletRequest {
036: HttpServletRequest _req;
037: ActionRequest _preq;
038:
039: /**
040: * HttpServletRequestWrapper constructor comment.
041: */
042: public HttpServletRequestWrapper(HttpServletRequest req) {
043: super ();
044: _req = req;
045: }
046:
047: /**
048: * HttpServletRequestWrapper constructor comment.
049: */
050: public HttpServletRequestWrapper(ActionRequest req) {
051: super ();
052: _preq = req;
053: }
054:
055: /**
056: * getAttribute method comment.
057: */
058: public Object getAttribute(String arg1) {
059: if (_preq != null)
060: return _preq.getAttribute(arg1);
061: else
062: return _req.getAttribute(arg1);
063: }
064:
065: /**
066: * getAuthType method comment.
067: */
068: public String getAuthType() {
069: if (_preq != null)
070: return _preq.getAuthType();
071: else
072: return _req.getAuthType();
073: }
074:
075: public boolean isUserInRole(String role) {
076: if (_preq != null)
077: return _preq.isUserInRole(role);
078: else
079: return _req.isUserInRole(role);
080: }
081:
082: public Principal getUserPrincipal() {
083: if (_preq != null)
084: return _preq.getUserPrincipal();
085: else
086: return _req.getUserPrincipal();
087: }
088:
089: /**
090: * getContentLength method comment.
091: */
092: public int getContentLength() {
093: if (_preq != null)
094: return _preq.getContentLength();
095: else
096: return _req.getContentLength();
097: }
098:
099: /**
100: * getContentType method comment.
101: */
102: public String getContentType() {
103: if (_preq != null)
104: return _preq.getContentType();
105: else
106: return _req.getContentType();
107: }
108:
109: /**
110: * getCookies method comment.
111: */
112: public javax.servlet.http.Cookie[] getCookies() {
113: if (_preq != null)
114: return null;
115: else
116: return _req.getCookies();
117: }
118:
119: /**
120: * getDateHeader method comment.
121: */
122: public long getDateHeader(String arg1) {
123: if (_preq != null)
124: return -1;
125: else
126: return _req.getDateHeader(arg1);
127: }
128:
129: /**
130: * getHeader method comment.
131: */
132: public String getHeader(String arg1) {
133: if (_preq != null)
134: return null;
135: else
136: return _req.getHeader(arg1);
137: }
138:
139: /**
140: * getHeaderNames method comment.
141: */
142: public java.util.Enumeration getHeaderNames() {
143: if (_preq != null)
144: return null;
145: else
146: return _req.getHeaderNames();
147: }
148:
149: /**
150: * getInputStream method comment.
151: */
152: public javax.servlet.ServletInputStream getInputStream()
153: throws java.io.IOException {
154: if (_preq != null)
155: return null;
156: else
157: return _req.getInputStream();
158: }
159:
160: /**
161: * getIntHeader method comment.
162: */
163: public int getIntHeader(String arg1) {
164: if (_preq != null)
165: return -1;
166: else
167: return _req.getIntHeader(arg1);
168: }
169:
170: /**
171: * getMethod method comment.
172: */
173: public String getMethod() {
174: if (_preq != null)
175: return null;
176: else
177: return _req.getMethod();
178: }
179:
180: /**
181: * getParameter method comment.
182: */
183: public String getParameter(String arg1) {
184: String parms[] = null;
185: if (_preq != null)
186: parms = _preq.getParameterValues(arg1);
187: else
188: parms = _req.getParameterValues(arg1);
189: if (parms == null)
190: return null;
191: else
192: return parms[0];
193: }
194:
195: /**
196: * getParameterNames method comment.
197: */
198: public java.util.Enumeration getParameterNames() {
199: if (_preq != null)
200: return _preq.getParameterNames();
201: else
202: return _req.getParameterNames();
203: }
204:
205: /**
206: * getParameterValues method comment.
207: */
208: public java.lang.String[] getParameterValues(String arg1) {
209: if (_preq != null)
210: return _preq.getParameterValues(arg1);
211: else
212: return _req.getParameterValues(arg1);
213: }
214:
215: /**
216: * getPathInfo method comment.
217: */
218: public String getPathInfo() {
219: if (_preq != null)
220: return null;
221: else
222: return _req.getPathInfo();
223: }
224:
225: /**
226: * getPathTranslated method comment.
227: */
228: public String getPathTranslated() {
229: if (_preq != null)
230: return null;
231: else
232: return _req.getPathTranslated();
233: }
234:
235: /**
236: * getProtocol method comment.
237: */
238: public String getProtocol() {
239: if (_preq != null)
240: return null;
241: else
242: return _req.getProtocol();
243: }
244:
245: /**
246: * getQueryString method comment.
247: */
248: public String getQueryString() {
249: if (_preq != null)
250: return null;
251: else
252: return _req.getQueryString();
253: }
254:
255: /**
256: * getReader method comment.
257: */
258: public java.io.BufferedReader getReader()
259: throws java.io.IOException {
260: if (_preq != null)
261: return _preq.getReader();
262: else
263: return _req.getReader();
264: }
265:
266: /**
267: * getRealPath method comment.
268: */
269: /** @deprecated */
270: public String getRealPath(String arg1) {
271: if (_preq != null)
272: return null;
273: else
274: return null;
275: }
276:
277: /**
278: * getRemoteAddr method comment.
279: */
280: public String getRemoteAddr() {
281: if (_preq != null)
282: return null;
283: else
284: return _req.getRemoteAddr();
285: }
286:
287: /**
288: * getRemoteHost method comment.
289: */
290: public String getRemoteHost() {
291: if (_preq != null)
292: return null;
293: else
294: return _req.getRemoteHost();
295: }
296:
297: /**
298: * getRemoteUser method comment.
299: */
300: public String getRemoteUser() {
301: if (_preq != null)
302: return _preq.getRemoteUser();
303: else
304: return _req.getRemoteUser();
305: }
306:
307: /**
308: * getRequestedSessionId method comment.
309: */
310: public String getRequestedSessionId() {
311: if (_preq != null) {
312: PortletSession sess = _preq.getPortletSession(false);
313: if (sess != null)
314: return sess.getId();
315: else
316: return null;
317: } else
318: return _req.getRequestedSessionId();
319: }
320:
321: /**
322: * getRequestURI method comment.
323: */
324: public String getRequestURI() {
325: if (_preq != null)
326: return null;
327: else
328: return _req.getRequestURI();
329: }
330:
331: /**
332: * getScheme method comment.
333: */
334: public String getScheme() {
335: if (_preq != null)
336: return _preq.getScheme();
337: else
338: return _req.getScheme();
339: }
340:
341: /**
342: * getServerName method comment.
343: */
344: public String getServerName() {
345: if (_preq != null)
346: return _preq.getServerName();
347: else
348:
349: return _req.getServerName();
350: }
351:
352: /**
353: * getServerPort method comment.
354: */
355: public int getServerPort() {
356: if (_preq != null)
357: return _preq.getServerPort();
358: else
359: return _req.getServerPort();
360: }
361:
362: /**
363: * getServletPath method comment.
364: */
365: public String getServletPath() {
366: if (_preq != null)
367: return null;
368: else
369: return _req.getServletPath();
370: }
371:
372: /**
373: * getSession method comment.
374: */
375: public HttpSession getSession(boolean arg1) {
376: if (_preq != null)
377: return null;
378: else
379: return _req.getSession(arg1);
380: }
381:
382: /**
383: * Returns the portlet session used by the portlet
384: */
385: public PortletSession getPortletSession(boolean arg1) {
386: if (_preq != null)
387: return _preq.getPortletSession(arg1);
388: else
389: return null;
390: }
391:
392: /**
393: * isRequestedSessionIdFromCookie method comment.
394: */
395: public boolean isRequestedSessionIdFromCookie() {
396: if (_preq != null)
397: return false;
398: else
399: return _req.isRequestedSessionIdFromCookie();
400: }
401:
402: /**
403: * isRequestedSessionIdFromUrl method comment.
404: */
405: /** @deprecated */
406: public boolean isRequestedSessionIdFromUrl() {
407: if (_preq != null)
408: return false;
409: else
410: return _req.isRequestedSessionIdFromURL();
411: }
412:
413: /**
414: * isRequestedSessionIdValid method comment.
415: */
416: public boolean isRequestedSessionIdValid() {
417: if (_preq != null)
418: return _preq.isRequestedSessionIdValid();
419: else
420: return _req.isRequestedSessionIdValid();
421: }
422:
423: /**
424: * This method was created in VisualAge.
425: * @param req javax.servlet.http.HttpServletRequest
426: */
427: void setRequest(HttpServletRequest req) {
428: _req = req;
429: _preq = null;
430: }
431:
432: void setRequest(ActionRequest req) {
433: _preq = req;
434: _req = null;
435: }
436:
437: public java.util.Enumeration getAttributeNames() {
438: if (_preq != null)
439: return (_preq.getAttributeNames());
440: else
441: return _req.getAttributeNames();
442: }
443:
444: public java.lang.String getCharacterEncoding() {
445: if (_preq != null)
446: return (_preq.getCharacterEncoding());
447: else
448: return _req.getCharacterEncoding();
449: }
450:
451: public javax.servlet.http.HttpSession getSession() {
452: if (_preq != null)
453: return null;
454: else
455: return _req.getSession();
456: }
457:
458: /**
459: * Returns the portlet session used by the portlet
460: */
461: public PortletSession getPortletSession() {
462: if (_preq != null)
463: return _preq.getPortletSession();
464: else
465: return null;
466: }
467:
468: /**
469: * isRequestedSessionIdFromUrl method comment.
470: */
471: public boolean isRequestedSessionIdFromURL() {
472: if (_preq != null)
473: return false;
474: else
475: return _req.isRequestedSessionIdFromURL();
476: }
477:
478: public void setAttribute(java.lang.String param1,
479: java.lang.Object param2) {
480: if (_preq != null)
481: _preq.setAttribute(param1, param2);
482: else
483: _req.setAttribute(param1, param2);
484: }
485:
486: public java.util.Enumeration getHeaders(String name) {
487: if (_preq != null)
488: return null;
489: else
490: return _req.getHeaders(name);
491: }
492:
493: public String getContextPath() {
494: if (_preq != null)
495: return _preq.getContextPath();
496: else
497: return _req.getContextPath();
498: }
499:
500: public void removeAttribute(String name) {
501: if (_preq != null)
502: _preq.removeAttribute(name);
503: else
504: _req.removeAttribute(name);
505: }
506:
507: public boolean isSecure() {
508: if (_preq != null)
509: return _preq.isSecure();
510: else
511: return _req.isSecure();
512: }
513:
514: public RequestDispatcher getRequestDispatcher(String dispatcher) {
515: if (_preq != null)
516: return null;
517: else
518: return _req.getRequestDispatcher(dispatcher);
519: }
520:
521: public Enumeration getLocales() {
522: if (_preq != null)
523: return _preq.getLocales();
524: else
525: return _req.getLocales();
526: }
527:
528: public Locale getLocale() {
529: if (_preq != null)
530: return _preq.getLocale();
531: else
532: return _req.getLocale();
533: }
534:
535: public Map getParameterMap() {
536: if (_preq != null)
537: return _preq.getParameterMap();
538: else
539: return null;
540: }
541:
542: public StringBuffer getRequestURL() {
543: return null;
544: }
545:
546: public void setCharacterEncoding(String enc) {
547:
548: }
549:
550: public HttpServletRequest getWrappedRequest() {
551: return _req;
552: }
553:
554: public ActionRequest getPortletWrapppedRequest() {
555: return _preq;
556: }
557:
558: /* (non-Javadoc)
559: * @see javax.servlet.ServletRequest#getRemotePort()
560: */
561: public int getRemotePort() {
562: try {
563: Method m = _req.getClass().getMethod("getRemotePort", null);
564: return ((Integer) m.invoke(this , null)).intValue();
565: } catch (Exception e) {
566: return 0;
567: }
568: }
569:
570: /* (non-Javadoc)
571: * @see javax.servlet.ServletRequest#getLocalName()
572: */
573: public String getLocalName() {
574: try {
575: Method m = _req.getClass().getMethod("getLocalName", null);
576: return (String) m.invoke(this , null);
577: } catch (Exception e) {
578: return null;
579: }
580: }
581:
582: /* (non-Javadoc)
583: * @see javax.servlet.ServletRequest#getLocalAddr()
584: */
585: public String getLocalAddr() {
586: try {
587: Method m = _req.getClass().getMethod("getLocalAddr", null);
588: return (String) m.invoke(this , null);
589: } catch (Exception e) {
590: return null;
591: }
592: }
593:
594: /* (non-Javadoc)
595: * @see javax.servlet.ServletRequest#getLocalPort()
596: */
597: public int getLocalPort() {
598: try {
599: Method m = _req.getClass().getMethod("getLocalPort", null);
600: return ((Integer) m.invoke(this , null)).intValue();
601: } catch (Exception e) {
602: return 0;
603: }
604: }
605: }
|