OpenmisHttpServletRequest.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
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 
00047 import org.openmobileis.common.context.SessionContextManager;
00048 
00062 public class OpenmisHttpServletRequest implements HttpServletRequest {
00063 
00064     private HttpServletRequest req;
00065     private Hashtable parameters;
00066     private String newrequestURI;
00067     
00068     public OpenmisHttpServletRequest(HttpServletRequest req) {
00069         this.req = req;
00070         
00071         // We use our own parameters table.
00072         // We first initialize it with the request's values.
00073         Enumeration paramEnum = req.getParameterNames();
00074         this.parameters = new Hashtable();
00075         while (paramEnum.hasMoreElements()) {
00076             String paramName = (String)paramEnum.nextElement();
00077             
00078             this.parameters.put(paramName, req.getParameterValues(paramName));
00079         }
00080     }
00081     
00082     public String getAuthType() {
00083         return req.getAuthType();
00084     }
00085 
00086     public Cookie[] getCookies() {
00087         return req.getCookies();
00088     }
00089 
00090     public long getDateHeader(String arg0) {
00091         return req.getDateHeader(arg0);
00092     }
00093 
00094     public String getHeader(String arg0) {
00095         return req.getHeader(arg0);
00096     }
00097 
00098     public Enumeration getHeaders(String arg0) {
00099         return req.getHeaders(arg0);
00100     }
00101 
00102     public Enumeration getHeaderNames() {
00103         return req.getHeaderNames();
00104     }
00105 
00106     public int getIntHeader(String arg0) {
00107         return req.getIntHeader(arg0);
00108     }
00109 
00110     public String getMethod() {
00111         return req.getMethod();
00112     }
00113 
00114     public String getPathInfo() {
00115         return req.getPathInfo();
00116     }
00117 
00118     public String getPathTranslated() {
00119         return req.getPathTranslated();
00120     }
00121 
00122     public String getContextPath() {
00123         return req.getContextPath();
00124     }
00125 
00126     public String getQueryString() {
00127         return req.getQueryString();
00128     }
00129 
00130     public String getRemoteUser() {
00131         return req.getRemoteUser();
00132     }
00133 
00134     public boolean isUserInRole(String arg0) {
00135         return req.isUserInRole(arg0);
00136     }
00137 
00138     public Principal getUserPrincipal() {
00139         return req.getUserPrincipal();
00140     }
00141 
00142     public String getRequestedSessionId() {
00143         return req.getRequestedSessionId();
00144     }
00145 
00146     public String getRequestURI() {
00147       if (newrequestURI != null) return newrequestURI;
00148       return req.getRequestURI();
00149     }
00150     
00151     public void setRequestURI(String uri) {
00152       this.newrequestURI = uri;
00153     }
00154 
00155     public StringBuffer getRequestURL() {
00156         return req.getRequestURL();
00157     }
00158 
00159     public String getServletPath() {
00160         return req.getServletPath();
00161     }
00162 
00163     public HttpSession getSession(boolean arg0) {
00164         return SessionContextManager.getManager().getSessionContext();
00165     }
00166 
00167     public HttpSession getSession() {
00168         return this.getSession(true);
00169     }
00170 
00171     public boolean isRequestedSessionIdValid() {
00172         return req.isRequestedSessionIdValid();
00173     }
00174 
00175     public boolean isRequestedSessionIdFromCookie() {
00176         return req.isRequestedSessionIdFromCookie();
00177     }
00178 
00179     public boolean isRequestedSessionIdFromURL() {
00180         return req.isRequestedSessionIdFromURL();
00181     }
00182 
00183     public boolean isRequestedSessionIdFromUrl() {
00184         return req.isRequestedSessionIdFromUrl();
00185     }
00186 
00187     public Object getAttribute(String arg0) {
00188         return req.getAttribute(arg0);
00189     }
00190 
00191     public Enumeration getAttributeNames() {
00192         return req.getAttributeNames();
00193     }
00194 
00195     public String getCharacterEncoding() {
00196         return req.getCharacterEncoding();
00197     }
00198 
00199     public void setCharacterEncoding(String arg0)
00200             throws UnsupportedEncodingException {
00201         req.setCharacterEncoding(arg0);
00202     }
00203 
00204     public int getContentLength() {
00205         return req.getContentLength();
00206     }
00207 
00208     public String getContentType() {
00209         return req.getContentType();
00210     }
00211 
00212     public ServletInputStream getInputStream() throws IOException {
00213         return req.getInputStream();
00214     }
00215 
00216 
00217 /*********************************************************************************************
00218  * 
00219  * The following 4 methods don't call the wrapped HttpServletRequest,
00220  * as we use our own parameters table.
00221  * 
00222  */    
00223     public String getParameter(String name) {
00224         String[] params = getParameterValues(name);
00225         if (params == null || params.length == 0)
00226             return null;
00227 
00228         return params[0];
00229     }
00230 
00231     public Enumeration getParameterNames() {
00232         return this.parameters.keys();
00233     }
00234 
00235     public String[] getParameterValues(String arg0) {
00236       return (String[])this.parameters.get(arg0);
00237     }
00238 
00239     public Map getParameterMap() {
00240         return (java.util.Map)this.parameters;
00241     }
00245     public String getProtocol() {
00246         return req.getProtocol();
00247     }
00248 
00249     public String getScheme() {
00250         return req.getScheme();
00251     }
00252 
00253     public String getServerName() {
00254         return req.getServerName();
00255     }
00256 
00257     public int getServerPort() {
00258         return req.getServerPort();
00259     }
00260 
00261     public BufferedReader getReader() throws IOException {
00262         return req.getReader();
00263     }
00264 
00265     public String getRemoteAddr() {
00266         return req.getRemoteAddr();
00267     }
00268 
00269     public String getRemoteHost() {
00270         return req.getRemoteHost();
00271     }
00272 
00273     public void setAttribute(String arg0, Object arg1) {
00274         req.setAttribute(arg0, arg1);
00275     }
00276 
00277     public void removeAttribute(String arg0) {
00278         req.removeAttribute(arg0);
00279     }
00280     
00281 /*********************************************************************************************
00282  * 
00283  * The following 3 methods are not part of the Servlet API.
00284  * We use them to make the requests more flexible.
00285  * 
00286  */    
00287     public void addParameter(String key, Object value) {
00288         if (parameters.containsKey(key)) {
00289             String[] values = (String[])this.parameters.get(key);
00290             String[] newValues = new String[values.length+1];
00291             for (int i = 0; i < values.length; i++) {
00292                 newValues[i] = values[i];
00293             }
00294             newValues[values.length] = (String)value;
00295         }
00296         else {
00297             String[] values = new String[] {(String)value};
00298             this.parameters.put(key, values);
00299         }
00300     }
00301     
00302     public void addParameters(Hashtable table)  {
00303         Enumeration enuma = table.keys();
00304         while (enuma.hasMoreElements()) {
00305             Object key = enuma.nextElement();
00306             Object value = table.get(key);
00307             parameters.put(key, value);                 
00308         }
00309         }
00310 
00311     public void removeParameter(String key) {
00312         this.parameters.remove(key);
00313     }
00318     public Locale getLocale() {
00319         return req.getLocale();
00320     }
00321 
00322     public Enumeration getLocales() {
00323         return req.getLocales();
00324     }
00325 
00326     public boolean isSecure() {
00327         return req.isSecure();
00328     }
00329 
00330     public RequestDispatcher getRequestDispatcher(String arg0) {
00331         return req.getRequestDispatcher(arg0);
00332     }
00333 
00334     public String getRealPath(String arg0) {
00335         return req.getRealPath(arg0);
00336     }
00337 
00338     public int getRemotePort() {
00339         return req.getRemotePort();
00340     }
00341 
00342     public String getLocalName() {
00343         return req.getLocalName();
00344     }
00345 
00346     public String getLocalAddr() {
00347         return req.getLocalAddr();
00348     }
00349 
00350     public int getLocalPort() {
00351         return req.getLocalPort();
00352     }
00353 
00354 }

Generated on Mon Dec 4 11:03:28 2006 for OpenMobileIS by  doxygen 1.5.1-p1