//# 0 errors, 46 messages
//#
/*
    //#CharEncodingFilter.java:1:1: class: org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter
 * 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.weblogger.ui.core.filters;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
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 org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


/**
 * 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>
 */
public class CharEncodingFilter implements Filter {
    //#CharEncodingFilter.java:41: method: void org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter.org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter()
    //#input(void org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter()): this
    //#output(void org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter()): this.mFilterConfig
    //#post(void org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter()): this.mFilterConfig == null
    
    private FilterConfig mFilterConfig = null;
    //#CharEncodingFilter.java:43: end of method: void org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter.org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter()
    private static Log mLogger =
    //#CharEncodingFilter.java:44: method: org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter.org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter__static_init
    //#CharEncodingFilter.java:44: Warning: method not available
    //#    -- call on LogFactory org.apache.commons.logging.LogFactory:getFactory()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter
    //#    method: org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter__static_init
    //#    unanalyzed callee: LogFactory org.apache.commons.logging.LogFactory:getFactory()
    //#CharEncodingFilter.java:44: Warning: method not available
    //#    -- call on Log org.apache.commons.logging.LogFactory:getInstance(Class)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter
    //#    method: org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter__static_init
    //#    unanalyzed callee: Log org.apache.commons.logging.LogFactory:getInstance(Class)
    //#output(org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/core/filters/CharEncodingFilter]
    //#output(org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter__static_init): __Dispatch_Table.destroy()V
    //#output(org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter__static_init): __Dispatch_Table.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V
    //#output(org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter__static_init): __Dispatch_Table.init(Ljavax/servlet/FilterConfig;)V
    //#output(org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter__static_init): mLogger
    //#presumption(org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter__static_init): org.apache.commons.logging.LogFactory:getFactory(...)@44 != null
    //#post(org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/core/filters/CharEncodingFilter] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter__static_init): __Dispatch_Table.destroy()V == &destroy
    //#post(org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter__static_init): __Dispatch_Table.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V == &doFilter
    //#post(org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter__static_init): __Dispatch_Table.init(Ljavax/servlet/FilterConfig;)V == &init
    //#post(org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter__static_init): init'ed(mLogger)
    //#CharEncodingFilter.java:44: end of method: org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter.org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter__static_init
            LogFactory.getFactory().getInstance(CharEncodingFilter.class);
    
    /**
     * init
     */
    public void init(FilterConfig filterConfig) throws ServletException {
        mFilterConfig = filterConfig;
    //#CharEncodingFilter.java:51: method: void org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter.init(FilterConfig)
    //#input(void init(FilterConfig)): filterConfig
    //#input(void init(FilterConfig)): this
    //#output(void init(FilterConfig)): this.mFilterConfig
    //#post(void init(FilterConfig)): this.mFilterConfig == filterConfig
    //#post(void init(FilterConfig)): init'ed(this.mFilterConfig)
    }
    //#CharEncodingFilter.java:52: end of method: void org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter.init(FilterConfig)
    
    /**
     * destroy
     */
    public void destroy() {
    }
    //#CharEncodingFilter.java:58: method: void org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter.destroy()
    //#CharEncodingFilter.java:58: end of method: void org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter.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");
    //#CharEncodingFilter.java:66: method: void org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter.doFilter(ServletRequest, ServletResponse, FilterChain)
    //#CharEncodingFilter.java:66: Warning: method not available
    //#    -- call on bool org.apache.commons.logging.Log:isDebugEnabled()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter
    //#    method: void doFilter(ServletRequest, ServletResponse, FilterChain)
    //#    unanalyzed callee: bool org.apache.commons.logging.Log:isDebugEnabled()
    //#CharEncodingFilter.java:66: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:debug(Object)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter
    //#    method: void doFilter(ServletRequest, ServletResponse, FilterChain)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:debug(Object)
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): chain
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): mLogger
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): req
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): res
    //#pre[1] (void doFilter(ServletRequest, ServletResponse, FilterChain)): chain != null
    //#pre[2] (void doFilter(ServletRequest, ServletResponse, FilterChain)): mLogger != null
    //#pre[3] (void doFilter(ServletRequest, ServletResponse, FilterChain)): req != null
    //#test_vector(void doFilter(ServletRequest, ServletResponse, FilterChain)): org.apache.commons.logging.Log:isDebugEnabled(...)@66: {0}, {1}
    //#test_vector(void doFilter(ServletRequest, ServletResponse, FilterChain)): org.apache.commons.logging.Log:isDebugEnabled(...)@70: {0}, {1}
        try {
            
            req.setCharacterEncoding("UTF-8");            
            if (mLogger.isDebugEnabled()) mLogger.debug("Set request character encoding to UTF-8");
    //#CharEncodingFilter.java:70: Warning: method not available
    //#    -- call on bool org.apache.commons.logging.Log:isDebugEnabled()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter
    //#    method: void doFilter(ServletRequest, ServletResponse, FilterChain)
    //#    unanalyzed callee: bool org.apache.commons.logging.Log:isDebugEnabled()
    //#CharEncodingFilter.java:70: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:debug(Object)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter
    //#    method: void doFilter(ServletRequest, ServletResponse, FilterChain)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:debug(Object)
            
        } 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);
    }
    //#CharEncodingFilter.java:78: end of method: void org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter.doFilter(ServletRequest, ServletResponse, FilterChain)
    
}
    //#CharEncodingFilter.java:: end of class: org.apache.roller.weblogger.ui.core.filters.CharEncodingFilter
