-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
src/main/java/org/jboss/forge/website/filter/CharacterEncodingFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
{ | ||
} | ||
|
||
} |