Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members

OpenmisHttpServletRequest.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *  
00024  *  Modifications :
00025  *  2004 Creation P.Delrieu
00026  *  2004 Modified by Romain Beaugrand
00027  * 
00028  */
00029 
00030 package org.openmobileis.services.servlet;
00031 
00032 import java.io.BufferedReader;
00033 import java.io.IOException;
00034 import java.io.UnsupportedEncodingException;
00035 import java.security.Principal;
00036 import java.util.Enumeration;
00037 import java.util.Hashtable;
00038 import java.util.Locale;
00039 import java.util.Map;
00040 
00041 import javax.servlet.RequestDispatcher;
00042 import javax.servlet.ServletInputStream;
00043 import javax.servlet.http.Cookie;
00044 import javax.servlet.http.HttpServletRequest;
00045 import javax.servlet.http.HttpSession;
00046 
00060 public class OpenmisHttpServletRequest implements HttpServletRequest {
00061 
00062     private HttpServletRequest req;
00063     private Hashtable parameters;
00064     
00065     public OpenmisHttpServletRequest(HttpServletRequest req) {
00066         this.req = req;
00067         
00068         // We use our own parameters table.
00069         // We first initialize it with the request's values.
00070         Enumeration paramEnum = req.getParameterNames();
00071         this.parameters = new Hashtable();
00072         while (paramEnum.hasMoreElements()) {
00073             String paramName = (String)paramEnum.nextElement();
00074             
00075             this.parameters.put(paramName, req.getParameterValues(paramName));
00076         }
00077     }
00078     
00079     public String getAuthType() {
00080         return req.getAuthType();
00081     }
00082 
00083     public Cookie[] getCookies() {
00084         return req.getCookies();
00085     }
00086 
00087     public long getDateHeader(String arg0) {
00088         return req.getDateHeader(arg0);
00089     }
00090 
00091     public String getHeader(String arg0) {
00092         return req.getHeader(arg0);
00093     }
00094 
00095     public Enumeration getHeaders(String arg0) {
00096         return req.getHeaders(arg0);
00097     }
00098 
00099     public Enumeration getHeaderNames() {
00100         return req.getHeaderNames();
00101     }
00102 
00103     public int getIntHeader(String arg0) {
00104         return req.getIntHeader(arg0);
00105     }
00106 
00107     public String getMethod() {
00108         return req.getMethod();
00109     }
00110 
00111     public String getPathInfo() {
00112         return req.getPathInfo();
00113     }
00114 
00115     public String getPathTranslated() {
00116         return req.getPathTranslated();
00117     }
00118 
00119     public String getContextPath() {
00120         return req.getContextPath();
00121     }
00122 
00123     public String getQueryString() {
00124         return req.getQueryString();
00125     }
00126 
00127     public String getRemoteUser() {
00128         return req.getRemoteUser();
00129     }
00130 
00131     public boolean isUserInRole(String arg0) {
00132         return req.isUserInRole(arg0);
00133     }
00134 
00135     public Principal getUserPrincipal() {
00136         return req.getUserPrincipal();
00137     }
00138 
00139     public String getRequestedSessionId() {
00140         return req.getRequestedSessionId();
00141     }
00142 
00143     public String getRequestURI() {
00144         return req.getRequestURI();
00145     }
00146 
00147     public StringBuffer getRequestURL() {
00148         return req.getRequestURL();
00149     }
00150 
00151     public String getServletPath() {
00152         return req.getServletPath();
00153     }
00154 
00155     public HttpSession getSession(boolean arg0) {
00156         return req.getSession(arg0);
00157     }
00158 
00159     public HttpSession getSession() {
00160         return req.getSession();
00161     }
00162 
00163     public boolean isRequestedSessionIdValid() {
00164         return req.isRequestedSessionIdValid();
00165     }
00166 
00167     public boolean isRequestedSessionIdFromCookie() {
00168         return req.isRequestedSessionIdFromCookie();
00169     }
00170 
00171     public boolean isRequestedSessionIdFromURL() {
00172         return req.isRequestedSessionIdFromURL();
00173     }
00174 
00175     public boolean isRequestedSessionIdFromUrl() {
00176         return req.isRequestedSessionIdFromUrl();
00177     }
00178 
00179     public Object getAttribute(String arg0) {
00180         return req.getAttribute(arg0);
00181     }
00182 
00183     public Enumeration getAttributeNames() {
00184         return req.getAttributeNames();
00185     }
00186 
00187     public String getCharacterEncoding() {
00188         return req.getCharacterEncoding();
00189     }
00190 
00191     public void setCharacterEncoding(String arg0)
00192             throws UnsupportedEncodingException {
00193         req.setCharacterEncoding(arg0);
00194     }
00195 
00196     public int getContentLength() {
00197         return req.getContentLength();
00198     }
00199 
00200     public String getContentType() {
00201         return req.getContentType();
00202     }
00203 
00204     public ServletInputStream getInputStream() throws IOException {
00205         return req.getInputStream();
00206     }
00207 
00208 
00209 /*********************************************************************************************
00210  * 
00211  * The following 4 methods don't call the wrapped HttpServletRequest,
00212  * as we use our own parameters table.
00213  * 
00214  */    
00215     public String getParameter(String name) {
00216         String[] params = getParameterValues(name);
00217         if (params == null || params.length == 0)
00218             return null;
00219 
00220         return params[0];
00221     }
00222 
00223     public Enumeration getParameterNames() {
00224         return this.parameters.keys();
00225     }
00226 
00227     public String[] getParameterValues(String arg0) {
00228         Object obj = this.parameters.get(arg0);
00229         return (String[])this.parameters.get(arg0);
00230     }
00231 
00232     public Map getParameterMap() {
00233         return (java.util.Map)this.parameters;
00234     }
00238     public String getProtocol() {
00239         return req.getProtocol();
00240     }
00241 
00242     public String getScheme() {
00243         return req.getScheme();
00244     }
00245 
00246     public String getServerName() {
00247         return req.getServerName();
00248     }
00249 
00250     public int getServerPort() {
00251         return req.getServerPort();
00252     }
00253 
00254     public BufferedReader getReader() throws IOException {
00255         return req.getReader();
00256     }
00257 
00258     public String getRemoteAddr() {
00259         return req.getRemoteAddr();
00260     }
00261 
00262     public String getRemoteHost() {
00263         return req.getRemoteHost();
00264     }
00265 
00266     public void setAttribute(String arg0, Object arg1) {
00267         req.setAttribute(arg0, arg1);
00268     }
00269 
00270     public void removeAttribute(String arg0) {
00271         req.removeAttribute(arg0);
00272     }
00273     
00274 /*********************************************************************************************
00275  * 
00276  * The following 3 methods are not part of the Servlet API.
00277  * We use them to make the requests more flexible.
00278  * 
00279  */    
00280     public void addParameter(String key, Object value) {
00281         if (parameters.containsKey(key)) {
00282             String[] values = (String[])this.parameters.get(key);
00283             String[] newValues = new String[values.length+1];
00284             for (int i = 0; i < values.length; i++) {
00285                 newValues[i] = values[i];
00286             }
00287             newValues[values.length] = (String)value;
00288         }
00289         else {
00290             String[] values = new String[] {(String)value};
00291             this.parameters.put(key, values);
00292         }
00293     }
00294     
00295     public void addParameters(Hashtable table)  {
00296         Enumeration enum = table.keys();
00297         while (enum.hasMoreElements())  {
00298             Object key = enum.nextElement();
00299             Object value = table.get(key);
00300             parameters.put(key, value);                 
00301         }
00302         }
00303 
00304     public void removeParameter(String key) {
00305         this.parameters.remove(key);
00306     }
00311     public Locale getLocale() {
00312         return req.getLocale();
00313     }
00314 
00315     public Enumeration getLocales() {
00316         return req.getLocales();
00317     }
00318 
00319     public boolean isSecure() {
00320         return req.isSecure();
00321     }
00322 
00323     public RequestDispatcher getRequestDispatcher(String arg0) {
00324         return req.getRequestDispatcher(arg0);
00325     }
00326 
00327     public String getRealPath(String arg0) {
00328         return req.getRealPath(arg0);
00329     }
00330 
00331     public int getRemotePort() {
00332         return req.getRemotePort();
00333     }
00334 
00335     public String getLocalName() {
00336         return req.getLocalName();
00337     }
00338 
00339     public String getLocalAddr() {
00340         return req.getLocalAddr();
00341     }
00342 
00343     public int getLocalPort() {
00344         return req.getLocalPort();
00345     }
00346 
00347 }

Generated on Thu Oct 6 10:06:33 2005 for OpenMobileIS by  doxygen 1.4.3