roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r467398 - in /incubator/roller/trunk: metadata/xdoclet/filter-mappings.xml src/org/apache/roller/ui/core/filters/CharEncodingFilter.java src/org/apache/roller/ui/core/filters/StrutsCharEncodingFilter.java
Date Tue, 24 Oct 2006 17:34:42 GMT
Author: snoopdave
Date: Tue Oct 24 10:34:41 2006
New Revision: 467398

URL: http://svn.apache.org/viewvc?view=rev&rev=467398
Log:
Moving Struts tag / JSTL tag local sync into its own filter

Added:
    incubator/roller/trunk/src/org/apache/roller/ui/core/filters/StrutsCharEncodingFilter.java
Modified:
    incubator/roller/trunk/metadata/xdoclet/filter-mappings.xml
    incubator/roller/trunk/src/org/apache/roller/ui/core/filters/CharEncodingFilter.java

Modified: incubator/roller/trunk/metadata/xdoclet/filter-mappings.xml
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/metadata/xdoclet/filter-mappings.xml?view=diff&rev=467398&r1=467397&r2=467398
==============================================================================
--- incubator/roller/trunk/metadata/xdoclet/filter-mappings.xml (original)
+++ incubator/roller/trunk/metadata/xdoclet/filter-mappings.xml Tue Oct 24 10:34:41 2006
@@ -16,11 +16,20 @@
     <dispatcher>REQUEST</dispatcher>
 </filter-mapping>
 -->
-<!-- Ensures character encoding set to UTF-8 and JSTL and Struts locales are in sync.
-Note: Any filters preceding this one MUST not cause request parsing. -->
+<!-- This filter ensures that the request encoding is set to UTF-8 before any 
+     other processing forces request parsing using a default encoding.
+     Note: Any filters preceding this one MUST not cause request parsing. -->
 <filter-mapping>
     <filter-name>CharEncodingFilter</filter-name>
     <url-pattern>/*</url-pattern>
+    <dispatcher>REQUEST</dispatcher>
+    <dispatcher>FORWARD</dispatcher>
+</filter-mapping>
+
+<!-- Ensures character encoding set to UTF-8 and JSTL and Struts locales are in sync.
 -->
+<filter-mapping>
+    <filter-name>StrutsCharEncodingFilter</filter-name>
+    <url-pattern>/roller-ui/*</url-pattern>
     <dispatcher>REQUEST</dispatcher>
     <dispatcher>FORWARD</dispatcher>
 </filter-mapping>

Modified: incubator/roller/trunk/src/org/apache/roller/ui/core/filters/CharEncodingFilter.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/core/filters/CharEncodingFilter.java?view=diff&rev=467398&r1=467397&r2=467398
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/core/filters/CharEncodingFilter.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/ui/core/filters/CharEncodingFilter.java Tue
Oct 24 10:34:41 2006
@@ -29,62 +29,56 @@
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
-import javax.servlet.jsp.jstl.core.Config;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.struts.Globals;
 
 /**
- * Entry point filter for all requests.  This filter ensures that the request encoding is
set to UTF-8 before any other
- * processing forces request parsing using a default encoding.  It also syncs up the Struts
and JSTL locales.  This
- * filter should normally be first and last in the chain.
+ * Entry point filter for all requests. This filter ensures that the request 
+ * encoding is set to UTF-8 before any other processing forces request parsing 
+ * using a default encoding.  It also syncs up the Struts and JSTL locales.  
+ * This filter should normally be first and last in the chain.
  *
  * @author <a href="mailto:anil@busybuddha.org">Anil Gangolli</a>
  * @web.filter name="CharEncodingFilter"
  */
-
-public class CharEncodingFilter implements Filter
-{
+public class CharEncodingFilter implements Filter {
     private FilterConfig mFilterConfig = null;
     private static Log mLogger =
-        LogFactory.getFactory().getInstance(CharEncodingFilter.class);
-
+            LogFactory.getFactory().getInstance(CharEncodingFilter.class);
+    
     /**
      * init
      */
-    public void init(FilterConfig filterConfig) throws ServletException
-    {
+    public void init(FilterConfig filterConfig) throws ServletException {
         mFilterConfig = filterConfig;
     }
-
+    
     /**
      * destroy
      */
-    public void destroy()
-    {
+    public void destroy() {
     }
-
+    
     /**
      * Set the character encoding and sync up Struts and JSTL locales.  This filter should
normally be first (and last)
      * in the chain.
      */
     public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
-        throws IOException, ServletException
-    {
+    throws IOException, ServletException {
         if (mLogger.isDebugEnabled()) mLogger.debug("Processing CharEncodingFilter");
-        try
-        {
-            req.setCharacterEncoding("UTF-8");
+        try {
+            
+            req.setCharacterEncoding("UTF-8");            
             if (mLogger.isDebugEnabled()) mLogger.debug("Set request character encoding to
UTF-8");
-        }
-        catch (UnsupportedEncodingException e)
-        {
+            
+        } catch (UnsupportedEncodingException e) {
             // This should never happen since UTF-8 is a Java-specified required encoding.
             throw new ServletException("Can't set incoming encoding to UTF-8");
         }
-
+        
         chain.doFilter(req, res);
     }
-
+    
 }

Added: incubator/roller/trunk/src/org/apache/roller/ui/core/filters/StrutsCharEncodingFilter.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/core/filters/StrutsCharEncodingFilter.java?view=auto&rev=467398
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/core/filters/StrutsCharEncodingFilter.java
(added)
+++ incubator/roller/trunk/src/org/apache/roller/ui/core/filters/StrutsCharEncodingFilter.java
Tue Oct 24 10:34:41 2006
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.ui.core.filters;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.Locale;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.servlet.jsp.jstl.core.Config;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts.Globals;
+
+/**
+ * This filter syncs up the Struts and JSTL locales. 
+ * @web.filter name="StrutsCharEncodingFilter"
+ */
+public class StrutsCharEncodingFilter implements Filter {
+    private FilterConfig mFilterConfig = null;
+    private static Log mLogger =
+            LogFactory.getFactory().getInstance(StrutsCharEncodingFilter.class);
+    
+    /**
+     * init
+     */
+    public void init(FilterConfig filterConfig) throws ServletException {
+        mFilterConfig = filterConfig;
+    }
+    
+    /**
+     * destroy
+     */
+    public void destroy() {
+    }
+    
+    /**
+     * Set the character encoding and sync up Struts and JSTL locales.  This filter should
normally be first (and last)
+     * in the chain.
+     */
+    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
+    throws IOException, ServletException {
+        if (mLogger.isDebugEnabled()) mLogger.debug("Processing CharEncodingFilter");
+        try {
+            
+            // Keep JSTL and Struts Locale's in sync
+            // NOTE: The session here will get created if it is not present.  This code was
taken from its
+            // earlier incarnation in RequestFilter, which also caused the session to be
created.
+            HttpSession session = ((HttpServletRequest) req).getSession();
+            if (mLogger.isDebugEnabled()) mLogger.debug("Synchronizing JSTL and Struts locales");
+            Locale locale = (Locale) session.getAttribute(Globals.LOCALE_KEY);
+            if (locale == null) {
+                locale = req.getLocale();
+            }
+            if (req.getParameter("locale") != null) {
+                locale = new Locale(req.getParameter("locale"));
+            }
+            session.setAttribute(Globals.LOCALE_KEY, locale);
+            Config.set(session, Config.FMT_LOCALE, locale);            
+            if (mLogger.isDebugEnabled()) mLogger.debug("Set request character encoding to
UTF-8");
+            
+        } catch (Exception e) {
+            // This should never happen
+            throw new ServletException("Can't set JSTL Config.FMT_LOCALE");
+        }
+        
+        chain.doFilter(req, res);
+    }
+    
+}



Mime
View raw message