Skip to content

Commit

Permalink
Fixed Encoding issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Apr 9, 2014
1 parent 81aee89 commit 61b73bd
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Copyright 2014 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.website.filter;

import java.io.IOException;

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.annotation.WebFilter;

/**
* Forces UTF-8 character encoding
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
@WebFilter(filterName = "EncodingFilter", urlPatterns = "/*")
public class CharacterEncodingFilter implements Filter
{

private String encoding = "UTF-8";

@Override
public void init(FilterConfig filterConfig) throws ServletException
{
String param = filterConfig.getInitParameter("encoding");
if (param != null)
{
encoding = param;
}
}

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
ServletException
{
request.setCharacterEncoding(encoding);
response.setCharacterEncoding(encoding);
chain.doFilter(request, response);
}

@Override
public void destroy()
{
}

}

0 comments on commit 61b73bd

Please sign in to comment.