myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r512416 - /myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java
Date Tue, 27 Feb 2007 21:20:38 GMT
Author: mbr
Date: Tue Feb 27 13:20:38 2007
New Revision: 512416

URL: http://svn.apache.org/viewvc?view=rev&rev=512416
Log:
generics injected
+ minor cleanup

Modified:
    myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java

Modified: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java?view=diff&rev=512416&r1=512415&r2=512416
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java
(original)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java
Tue Feb 27 13:20:38 2007
@@ -20,7 +20,6 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.security.Principal;
-import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.Locale;
 import java.util.Map;
@@ -37,45 +36,38 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.myfaces.context.ReleaseableExternalContext;
 import org.apache.myfaces.util.EnumerationIterator;
 
 /**
- * JSF 1.0 PRD2, 6.1.1
+ * Implements the external context for servlet request. JSF 1.2, 6.1.3
+ * 
  * @author Manfred Geiler (latest modification by $Author$)
  * @author Anton Koinov
  * @version $Revision$ $Date$
- *
- * Revision 1.11 Sylvain Vieujot
- * Forward the message when an exception is thrown in dispatch
  */
-public class ServletExternalContextImpl
-    extends ExternalContext implements ReleaseableExternalContext
+public class ServletExternalContextImpl extends ExternalContext implements ReleaseableExternalContext
 {
-
     private static final String INIT_PARAMETER_MAP_ATTRIBUTE = InitParameterMap.class.getName();
 
     private ServletContext _servletContext;
     private ServletRequest _servletRequest;
     private ServletResponse _servletResponse;
-    private Map _applicationMap;
-    private Map _sessionMap;
-    private Map _requestMap;
-    private Map _requestParameterMap;
-    private Map _requestParameterValuesMap;
-    private Map _requestHeaderMap;
-    private Map _requestHeaderValuesMap;
+    private Map<String, Object> _applicationMap;
+    private Map<String, Object> _sessionMap;
+    private Map<String, Object> _requestMap;
+    private Map<String, String> _requestParameterMap;
+    private Map<String, String[]> _requestParameterValuesMap;
+    private Map<String, String> _requestHeaderMap;
+    private Map<String, String[]> _requestHeaderValuesMap;
     private Map _requestCookieMap;
-    private Map _initParameterMap;
+    private Map<String, String> _initParameterMap;
     private HttpServletRequest _httpServletRequest;
     private String _requestServletPath;
     private String _requestPathInfo;
-    
-    public ServletExternalContextImpl(ServletContext servletContext,
-                                      ServletRequest servletRequest,
-                                      ServletResponse servletResponse)
+
+    public ServletExternalContextImpl(ServletContext servletContext, ServletRequest servletRequest,
+            ServletResponse servletResponse)
     {
         _servletContext = servletContext;
         _servletRequest = servletRequest;
@@ -89,27 +81,18 @@
         _requestHeaderValuesMap = null;
         _requestCookieMap = null;
         _initParameterMap = null;
-        _httpServletRequest = isHttpServletRequest(servletRequest) ? (HttpServletRequest)servletRequest
: null;
-        
+        _httpServletRequest = isHttpServletRequest(servletRequest) ? (HttpServletRequest)
servletRequest : null;
+
         if (_httpServletRequest != null)
         {
-            //HACK: MultipartWrapper scrambles the servletPath for some reason in Tomcat
4.1.29 embedded in JBoss 3.2.3!?
+            // HACK: MultipartWrapper scrambles the servletPath for some reason in Tomcat
4.1.29 embedded in JBoss
+            // 3.2.3!?
             // (this was reported by frederic.auge [frederic.auge@laposte.net])
-            HttpServletRequest httpServletRequest = (HttpServletRequest)servletRequest;
-
-            _requestServletPath = httpServletRequest.getServletPath();
-            _requestPathInfo = httpServletRequest.getPathInfo();
+            _requestServletPath = _httpServletRequest.getServletPath();
+            _requestPathInfo = _httpServletRequest.getPathInfo();
         }
     }
 
-
-    private boolean isHttpServletRequest(ServletRequest servletRequest)
-    {
-        return (servletRequest != null &&
-                                 servletRequest instanceof HttpServletRequest);
-    }
-
-
     public void release()
     {
         _servletContext = null;
@@ -127,35 +110,39 @@
         _httpServletRequest = null;
     }
 
-
+    @Override
     public Object getSession(boolean create)
     {
         checkHttpServletRequest();
-        return _httpServletRequest.getSession(create);
+        return ((HttpServletRequest) _servletRequest).getSession(create);
     }
 
-
+    @Override
     public Object getContext()
     {
         return _servletContext;
     }
 
+    @Override
     public Object getRequest()
     {
         return _servletRequest;
     }
 
+    @Override
     public Object getResponse()
     {
         return _servletResponse;
     }
 
+    @Override
     public String getResponseContentType()
     {
         return _servletResponse.getContentType();
     }
-    
-    public Map getApplicationMap()
+
+    @Override
+    public Map<String, Object> getApplicationMap()
     {
         if (_applicationMap == null)
         {
@@ -164,7 +151,8 @@
         return _applicationMap;
     }
 
-    public Map getSessionMap()
+    @Override
+    public Map<String, Object> getSessionMap()
     {
         if (_sessionMap == null)
         {
@@ -174,7 +162,8 @@
         return _sessionMap;
     }
 
-    public Map getRequestMap()
+    @Override
+    public Map<String, Object> getRequestMap()
     {
         if (_requestMap == null)
         {
@@ -183,7 +172,8 @@
         return _requestMap;
     }
 
-    public Map getRequestParameterMap()
+    @Override
+    public Map<String, String> getRequestParameterMap()
     {
         if (_requestParameterMap == null)
         {
@@ -192,7 +182,8 @@
         return _requestParameterMap;
     }
 
-    public Map getRequestParameterValuesMap()
+    @Override
+    public Map<String, String[]> getRequestParameterValuesMap()
     {
         if (_requestParameterValuesMap == null)
         {
@@ -201,27 +192,15 @@
         return _requestParameterValuesMap;
     }
 
-    public Iterator getRequestParameterNames()
+    @Override
+    @SuppressWarnings("unchecked")
+    public Iterator<String> getRequestParameterNames()
     {
-        final Enumeration enumer = _servletRequest.getParameterNames();
-        Iterator it = new Iterator()
-        {
-            public boolean hasNext() {
-                return enumer.hasMoreElements();
-            }
-
-            public Object next() {
-                return enumer.nextElement();
-            }
-
-            public void remove() {
-                throw new UnsupportedOperationException(this.getClass().getName() + " UnsupportedOperationException");
-            }
-        };
-        return it;
+        return new EnumerationIterator(_servletRequest.getParameterNames());
     }
 
-    public Map getRequestHeaderMap()
+    @Override
+    public Map<String, String> getRequestHeaderMap()
     {
         if (_requestHeaderMap == null)
         {
@@ -231,7 +210,8 @@
         return _requestHeaderMap;
     }
 
-    public Map getRequestHeaderValuesMap()
+    @Override
+    public Map<String, String[]> getRequestHeaderValuesMap()
     {
         if (_requestHeaderValuesMap == null)
         {
@@ -241,6 +221,8 @@
         return _requestHeaderValuesMap;
     }
 
+    @Override
+    @SuppressWarnings("unchecked")
     public Map<String, Object> getRequestCookieMap()
     {
         if (_requestCookieMap == null)
@@ -251,40 +233,48 @@
         return _requestCookieMap;
     }
 
+    @Override
     public Locale getRequestLocale()
     {
         return _servletRequest.getLocale();
     }
 
+    @Override
     public String getRequestPathInfo()
     {
         checkHttpServletRequest();
-        //return (_httpServletRequest).getPathInfo();
-        //HACK: see constructor
+        // return (_httpServletRequest).getPathInfo();
+        // HACK: see constructor
         return _requestPathInfo;
     }
 
-    public String getRequestContentType() {
+    @Override
+    public String getRequestContentType()
+    {
         return _servletRequest.getContentType();
     }
-    
+
+    @Override
     public String getRequestContextPath()
     {
         checkHttpServletRequest();
         return _httpServletRequest.getContextPath();
     }
 
+    @Override
     public String getInitParameter(String s)
     {
         return _servletContext.getInitParameter(s);
     }
 
-    public Map getInitParameterMap()
+    @Override
+    @SuppressWarnings("unchecked")
+    public Map<String, String> getInitParameterMap()
     {
         if (_initParameterMap == null)
         {
             // We cache it as an attribute in ServletContext itself (is this circular reference
a problem?)
-            if ((_initParameterMap = (Map) _servletContext.getAttribute(INIT_PARAMETER_MAP_ATTRIBUTE))
== null)
+            if ((_initParameterMap = (Map<String, String>) _servletContext.getAttribute(INIT_PARAMETER_MAP_ATTRIBUTE))
== null)
             {
                 _initParameterMap = new InitParameterMap(_servletContext);
                 _servletContext.setAttribute(INIT_PARAMETER_MAP_ATTRIBUTE, _initParameterMap);
@@ -293,110 +283,124 @@
         return _initParameterMap;
     }
 
+    @Override
     @SuppressWarnings("unchecked")
     public Set<String> getResourcePaths(String s)
     {
         return _servletContext.getResourcePaths(s);
     }
 
+    @Override
     public InputStream getResourceAsStream(String s)
     {
         return _servletContext.getResourceAsStream(s);
     }
 
+    @Override
     public String encodeActionURL(String s)
     {
         checkHttpServletRequest();
-        return ((HttpServletResponse)_servletResponse).encodeURL(s);
+        return ((HttpServletResponse) _servletResponse).encodeURL(s);
     }
 
+    @Override
     public String encodeResourceURL(String s)
     {
         checkHttpServletRequest();
-        return ((HttpServletResponse)_servletResponse).encodeURL(s);
+        return ((HttpServletResponse) _servletResponse).encodeURL(s);
     }
 
+    @Override
     public String encodeNamespace(String s)
     {
         return s;
     }
 
+    @Override
     public void dispatch(String requestURI) throws IOException, FacesException
     {
-        RequestDispatcher requestDispatcher
-            = _servletRequest.getRequestDispatcher(requestURI);
-        
+        RequestDispatcher requestDispatcher = _servletRequest.getRequestDispatcher(requestURI);
+
         // If there is no dispatcher, send NOT_FOUND
         if (requestDispatcher == null)
         {
-           ((HttpServletResponse)_servletResponse).sendError(
-                  HttpServletResponse.SC_NOT_FOUND);
+            ((HttpServletResponse) _servletResponse).sendError(HttpServletResponse.SC_NOT_FOUND);
+
+            return;
+        }
 
-           return;
-       } 
-        
         try
         {
             requestDispatcher.forward(_servletRequest, _servletResponse);
         }
         catch (ServletException e)
         {
-        	if (e.getMessage() != null)
+            if (e.getMessage() != null)
             {
                 throw new FacesException(e.getMessage(), e);
             }
 
             throw new FacesException(e);
-            
+
         }
     }
 
+    @Override
     public String getRequestServletPath()
     {
         checkHttpServletRequest();
-        //return (_httpServletRequest).getServletPath();
-        //HACK: see constructor
+        // return (_httpServletRequest).getServletPath();
+        // HACK: see constructor
         return _requestServletPath;
     }
 
+    @Override
     public String getAuthType()
     {
         checkHttpServletRequest();
         return _httpServletRequest.getAuthType();
     }
 
+    @Override
     public String getRemoteUser()
     {
         checkHttpServletRequest();
         return _httpServletRequest.getRemoteUser();
     }
 
+    @Override
     public boolean isUserInRole(String role)
     {
         checkHttpServletRequest();
         return _httpServletRequest.isUserInRole(role);
     }
 
+    @Override
     public Principal getUserPrincipal()
     {
         checkHttpServletRequest();
         return _httpServletRequest.getUserPrincipal();
     }
 
-    public void log(String message) {
+    @Override
+    public void log(String message)
+    {
         _servletContext.log(message);
     }
 
-    public void log(String message, Throwable t) {
+    @Override
+    public void log(String message, Throwable t)
+    {
         _servletContext.log(message, t);
     }
 
+    @Override
     public void redirect(String url) throws IOException
     {
         if (_servletResponse instanceof HttpServletResponse)
         {
-            ((HttpServletResponse)_servletResponse).sendRedirect(url);
-            FacesContext.getCurrentInstance().responseComplete();            
+            ((HttpServletResponse) _servletResponse).sendRedirect(url);
+            FacesContext.getCurrentInstance().responseComplete();
         }
         else
         {
@@ -411,33 +415,37 @@
         return new EnumerationIterator(_httpServletRequest.getLocales());
     }
 
+    @Override
     public URL getResource(String s) throws MalformedURLException
     {
         return _servletContext.getResource(s);
     }
-    
+
     /**
      * @since JSF 1.2
      * @param request
      */
+    @Override
     public void setRequest(java.lang.Object request)
     {
         this._servletRequest = (ServletRequest) request;
         this._httpServletRequest = isHttpServletRequest(_servletRequest) ? (HttpServletRequest)
_servletRequest : null;
+        this._httpServletRequest = isHttpServletRequest(_servletRequest) ? (HttpServletRequest)
_servletRequest : null;
     }
-    
+
     /**
      * @since JSF 1.2
      * @param encoding
      * @throws java.io.UnsupportedEncodingException
      */
-    public void setRequestCharacterEncoding(java.lang.String encoding)
-        throws java.io.UnsupportedEncodingException{
-      
+    @Override
+    public void setRequestCharacterEncoding(java.lang.String encoding) throws java.io.UnsupportedEncodingException
+    {
+
         this._servletRequest.setCharacterEncoding(encoding);
-      
+
     }
-    
+
     /**
      * @since JSF 1.2
      */
@@ -446,7 +454,7 @@
     {
         return _servletRequest.getCharacterEncoding();
     }
-    
+
     /**
      * @since JSF 1.2
      */
@@ -455,20 +463,22 @@
     {
         return _servletResponse.getCharacterEncoding();
     }
-    
+
     /**
      * @since JSF 1.2
      * @param response
      */
+    @Override
     public void setResponse(java.lang.Object response)
     {
         this._servletResponse = (ServletResponse) response;
     }
-    
+
     /**
      * @since JSF 1.2
      * @param encoding
      */
+    @Override
     public void setResponseCharacterEncoding(java.lang.String encoding)
     {
         this._servletResponse.setCharacterEncoding(encoding);
@@ -481,4 +491,10 @@
             throw new UnsupportedOperationException("Only HttpServletRequest supported");
         }
     }
+
+    private boolean isHttpServletRequest(ServletRequest servletRequest)
+    {
+        return servletRequest instanceof HttpServletRequest;
+    }
+
 }



Mime
View raw message