1 package com.atlassian.core.filters;
2
3 import com.atlassian.core.filters.cache.CachingStrategy;
4 import com.atlassian.core.filters.cache.JspCachingStrategy;
5 import com.atlassian.core.filters.legacy.WordCurlyQuotesRequestWrapper;
6 import com.atlassian.core.filters.legacy.NoContentLocationHeaderResponseWrapper;
7 import com.atlassian.core.filters.encoding.FixedHtmlEncodingResponseWrapper;
8
9 import javax.servlet.*;
10 import javax.servlet.http.HttpServletRequest;
11 import javax.servlet.http.HttpServletResponse;
12 import java.io.IOException;
13
14 public abstract class AbstractEncodingFilter extends AbstractHttpFilter
15 {
16 private final CachingStrategy jspCachingStrategy = new JspCachingStrategy();
17
18 public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException
19 {
20 request.setCharacterEncoding(getEncoding());
21 response.setContentType(getContentType());
22
23
24 if (isNonCachableUri(request))
25 setNonCachingHeaders(response);
26
27 filterChain.doFilter(
28 new WordCurlyQuotesRequestWrapper(request, getEncoding()),
29 new FixedHtmlEncodingResponseWrapper(new NoContentLocationHeaderResponseWrapper(response)));
30 }
31
32 protected void setNonCachingHeaders(HttpServletResponse response)
33 {
34 jspCachingStrategy.setCachingHeaders(response);
35 }
36
37
38 protected boolean isNonCachableUri(HttpServletRequest request)
39 {
40 return jspCachingStrategy.matches(request);
41 }
42
43 protected abstract String getEncoding();
44
45 protected abstract String getContentType();
46
47 }