@@ -0,0 +1,2627 @@
+/*%0A  $Id$%0A%0A  Copyright (C) 2009 Virginia Tech.%0A  All rights reserved.%0A%0A  SEE LICENSE FOR MORE INFORMATION%0A%0A  Author:  Middleware%0A  Email:   middleware@vt.edu%0A  Version: $Revision$%0A  Updated: $Date$%0A*/%0Apackage edu.vt.middleware.servlet.filter;%0A%0Aimport java.io.IOException;%0A%0Aimport javax.servlet.Filter;%0Aimport javax.servlet.FilterChain;%0Aimport javax.servlet.FilterConfig;%0Aimport javax.servlet.ServletException;%0Aimport javax.servlet.ServletRequest;%0Aimport javax.servlet.ServletResponse;%0A%0A/**%0A * Sets the request and/or response character encoding based on the presence%0A * of either or both of the following init params, %7B@link #REQUEST_CHARSET_NAME%7D%0A * %7B@link #RESPONSE_CHARSET_NAME%7D.%0A * %3Cp%3E%0A * %3Cstrong%3ENOTE:%3C/strong%3E this filter should be as close to the beginning of%0A * the filter chain as possible.  Any filters that obtain request parameters,%0A * e.g. %3Ccode%3Erequest.getParameter(...)%3C/code%3E, prior to setting the character%0A * set via this filter will use the platform default character set.%0A *%0A * @author Middleware%0A * @version $Revision$%0A *%0A */%0Apublic class CharacterEncodingFilter implements Filter%0A%7B%0A  /**%0A   * Name of init param for setting request character encoding.%0A   * The value should be a valid Java character set name, e.g. UTF-8.%0A   */%0A  public static final String REQUEST_CHARSET_NAME = %22requestCharsetName%22;%0A%0A  /**%0A   * Name of init param for setting response character encoding.%0A   * The value should be a valid Java character set name, e.g. UTF-8.%0A   */%0A  public static final String RESPONSE_CHARSET_NAME = %22responseCharsetName%22;%0A%0A  /** Request character set name */%0A  private String requestCharsetName;%0A%0A  /** Response character set name */%0A  private String responseCharsetName;%0A%0A%0A  /** %7B@inheritDoc%7D */%0A  public void init(final FilterConfig filterConfig) throws ServletException%0A  %7B%0A    if (filterConfig.getInitParameter(REQUEST_CHARSET_NAME) != null) %7B%0A      requestCharsetName = filterConfig.getInitParameter(REQUEST_CHARSET_NAME);%0A    %7D%0A    if (filterConfig.getInitParameter(RESPONSE_CHARSET_NAME) != null) %7B%0A      responseCharsetName =%0A        filterConfig.getInitParameter(RESPONSE_CHARSET_NAME);%0A    %7D%0A  %7D%0A%0A%0A  /** %7B@inheritDoc%7D */%0A  public void doFilter(%0A      final ServletRequest request,%0A      final ServletResponse response,%0A      final FilterChain chain) throws IOException, ServletException%0A  %7B%0A    if (requestCharsetName != null) %7B%0A      request.setCharacterEncoding(requestCharsetName);%0A    %7D%0A    if (responseCharsetName != null) %7B%0A      response.setCharacterEncoding(responseCharsetName);%0A    %7D%0A    chain.doFilter(request, response);%0A  %7D%0A%0A%0A  /** %7B@inheritDoc%7D */%0A  public void destroy() %7B%7D%0A%7D%0A

Add filter to allow changing character encoding of HTTP request/response.