From adffaces-commits-return-1976-apmail-incubator-adffaces-commits-archive=incubator.apache.org@incubator.apache.org Sat Feb 03 03:28:25 2007 Return-Path: Delivered-To: apmail-incubator-adffaces-commits-archive@locus.apache.org Received: (qmail 389 invoked from network); 3 Feb 2007 03:28:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Feb 2007 03:28:25 -0000 Received: (qmail 45049 invoked by uid 500); 3 Feb 2007 03:28:31 -0000 Delivered-To: apmail-incubator-adffaces-commits-archive@incubator.apache.org Received: (qmail 45036 invoked by uid 500); 3 Feb 2007 03:28:31 -0000 Mailing-List: contact adffaces-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: adffaces-dev@incubator.apache.org Delivered-To: mailing list adffaces-commits@incubator.apache.org Received: (qmail 45027 invoked by uid 99); 3 Feb 2007 03:28:31 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Feb 2007 19:28:31 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Feb 2007 19:28:23 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id B3F271A981A; Fri, 2 Feb 2007 19:28:03 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r503163 - /incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletExternalContext.java Date: Sat, 03 Feb 2007 03:28:03 -0000 To: adffaces-commits@incubator.apache.org From: awiner@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070203032803.B3F271A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: awiner Date: Fri Feb 2 19:28:03 2007 New Revision: 503163 URL: http://svn.apache.org/viewvc?view=rev&rev=503163 Log: Implement full JSF 1.2 API, and get rid of Servlet 2.3 backwards compatibility Modified: incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletExternalContext.java Modified: incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletExternalContext.java URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletExternalContext.java?view=diff&rev=503163&r1=503162&r2=503163 ============================================================================== --- incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletExternalContext.java (original) +++ incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletExternalContext.java Fri Feb 2 19:28:03 2007 @@ -20,7 +20,8 @@ import java.io.IOException; import java.io.InputStream; -import java.lang.reflect.Method; +import java.io.UnsupportedEncodingException; + import java.net.MalformedURLException; import java.net.URL; import java.security.Principal; @@ -76,48 +77,8 @@ } if (_httpServletRequest != null) - { - // 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]) - _requestServletPath = _httpServletRequest.getServletPath(); - _requestPathInfo = _httpServletRequest.getPathInfo(); - - // try to set character encoding as described in section 2.5.2.2 of JSF 1.1 spec - // we have to use reflection as method setCharacterEncoding is not supported Servlet API <= - // 2.3 - try - { - if (_setCharacterEncodingMethod != null) - { - final String contentType = _httpServletRequest.getHeader("Content-Type"); - - String characterEncoding = _lookupCharacterEncoding(contentType); - - if (characterEncoding == null) - { - final HttpSession session = _httpServletRequest.getSession(false); - - if (session != null) - { - characterEncoding = (String) session.getAttribute(ViewHandler.CHARACTER_ENCODING_KEY); - } - - if (characterEncoding != null) - { - _setCharacterEncodingMethod - .invoke(servletRequest, new Object[] { characterEncoding }); - } - } - } - } - catch (final Exception e) - { - if (_LOG.isWarning()) - { - _LOG.warning("Failed to set character encoding " + e); - } - } + { + _initHttpServletRequest(); } } @@ -497,6 +458,77 @@ } } + @Override + public String getRequestCharacterEncoding() + { + return _servletRequest.getCharacterEncoding(); + } + + @Override + public String getRequestContentType() + { + return _servletRequest.getContentType(); + } + + @Override + public String getResponseCharacterEncoding() + { + return _servletResponse.getCharacterEncoding(); + } + + @Override + public String getResponseContentType() + { + return _servletResponse.getContentType(); + } + + @Override + public void setRequest(Object object) + { + _servletRequest = (ServletRequest) object; + if (object instanceof HttpServletRequest) + { + _httpServletRequest = (HttpServletRequest) object; + _initHttpServletRequest(); + } + else + { + _httpServletRequest = null; + } + + // And clear out any of the cached maps, since we should + // go back and look in the map + _requestCookieMap = null; + _requestHeaderMap = null; + _requestHeaderValuesMap = null; + _requestMap = null; + _requestParameterMap = null; + _requestParameterValuesMap = null; + } + + @Override + public void setRequestCharacterEncoding(String string) throws UnsupportedEncodingException + { + _servletRequest.setCharacterEncoding(string); + } + + @Override + public void setResponse(Object object) + { + _servletResponse = (ServletResponse) object; + if (_servletResponse instanceof HttpServletResponse) + _httpServletResponse = (HttpServletResponse) object; + else + _httpServletResponse = null; + } + + @Override + public void setResponseCharacterEncoding(String string) + { + _servletResponse.setCharacterEncoding(string); + } + + public void release() { _servletContext = null; @@ -578,6 +610,41 @@ return characterEncoding; } + private void _initHttpServletRequest() + { + // 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]) + _requestServletPath = _httpServletRequest.getServletPath(); + _requestPathInfo = _httpServletRequest.getPathInfo(); + + final String contentType = _httpServletRequest.getHeader("Content-Type"); + + String characterEncoding = _lookupCharacterEncoding(contentType); + + if (characterEncoding == null) + { + final HttpSession session = _httpServletRequest.getSession(false); + if (session != null) + { + characterEncoding = (String) session.getAttribute(ViewHandler.CHARACTER_ENCODING_KEY); + } + + if (characterEncoding != null) + { + try + { + _servletRequest.setCharacterEncoding(characterEncoding); + } + catch (UnsupportedEncodingException uee) + { + _LOG.warning(uee); + } + } + } + + } + private Map _applicationMap; private HttpServletRequest _httpServletRequest; private HttpServletResponse _httpServletResponse; @@ -594,22 +661,8 @@ private ServletRequest _servletRequest; private ServletResponse _servletResponse; private Map _sessionMap; - private static final String _INIT_PARAMETER_MAP_ATTRIBUTE = ServletInitParameterMap.class - .getName(); - private static final TrinidadLogger _LOG = TrinidadLogger - .createTrinidadLogger(ServletExternalContext.class); - private static Method _setCharacterEncodingMethod = null; - static - { - try - { - _setCharacterEncodingMethod = ServletRequest.class.getMethod("setCharacterEncoding", - new Class[] { String.class }); - } - catch (final Exception e) - { - _LOG.warning("Detecting request character encoding is disable."); - _LOG.warning("Failed to obtain ServletRequest#setCharacterEncoding() method: " + e); - } - } + private static final String _INIT_PARAMETER_MAP_ATTRIBUTE = + ServletInitParameterMap.class.getName(); + private static final TrinidadLogger _LOG + = TrinidadLogger.createTrinidadLogger(ServletExternalContext.class); }