Class EncodingFilter

java.lang.Object
org.codelibs.fess.filter.EncodingFilter
All Implemented Interfaces:
jakarta.servlet.Filter

public class EncodingFilter extends Object implements jakarta.servlet.Filter
Servlet filter for handling character encoding conversion and URL redirection. This filter processes requests with specific encoding requirements and converts character encodings according to configured mapping rules.

The filter intercepts requests matching configured path patterns and redirects them with proper character encoding applied to parameters.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected String
    Default character encoding to use for requests
    static final String
    Configuration key for encoding rules mapping
    protected Map<String,String>
    Map of path patterns to their corresponding character encodings
    protected jakarta.servlet.ServletContext
    Servlet context for this filter
    protected org.apache.commons.codec.net.URLCodec
    URL codec for encoding and decoding URL parameters
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor for EncodingFilter.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Cleans up resources when the filter is destroyed.
    void
    doFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain)
    Processes requests and applies character encoding conversion if needed.
    protected Map<String,String[]>
    getParameterMapFromQueryString(jakarta.servlet.http.HttpServletRequest request, String enc)
    Extracts and parses parameters from the request query string.
    void
    init(jakarta.servlet.FilterConfig config)
    Initializes the filter with configuration parameters.
    protected Map<String,String[]>
    parseQueryString(String queryString, String enc)
    Parses a query string and extracts parameter name-value pairs.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ENCODING_MAP

      public static final String ENCODING_MAP
      Configuration key for encoding rules mapping
      See Also:
    • encodingMap

      protected Map<String,String> encodingMap
      Map of path patterns to their corresponding character encodings
    • encoding

      protected String encoding
      Default character encoding to use for requests
    • servletContext

      protected jakarta.servlet.ServletContext servletContext
      Servlet context for this filter
    • urlCodec

      protected org.apache.commons.codec.net.URLCodec urlCodec
      URL codec for encoding and decoding URL parameters
  • Constructor Details

    • EncodingFilter

      public EncodingFilter()
      Default constructor for EncodingFilter.
  • Method Details

    • init

      public void init(jakarta.servlet.FilterConfig config) throws jakarta.servlet.ServletException
      Initializes the filter with configuration parameters. Sets up encoding mappings and default encoding from filter configuration.
      Specified by:
      init in interface jakarta.servlet.Filter
      Parameters:
      config - the filter configuration containing initialization parameters
      Throws:
      jakarta.servlet.ServletException - if an error occurs during initialization
    • doFilter

      public void doFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain) throws IOException, jakarta.servlet.ServletException
      Processes requests and applies character encoding conversion if needed. Checks if the request path matches any configured encoding rule and performs URL redirection with proper parameter encoding.
      Specified by:
      doFilter in interface jakarta.servlet.Filter
      Parameters:
      request - the servlet request to process
      response - the servlet response to use for redirection
      chain - the filter chain to continue processing
      Throws:
      IOException - if an I/O error occurs during processing
      jakarta.servlet.ServletException - if a servlet error occurs
    • getParameterMapFromQueryString

      protected Map<String,String[]> getParameterMapFromQueryString(jakarta.servlet.http.HttpServletRequest request, String enc) throws IOException
      Extracts and parses parameters from the request query string. Applies the specified character encoding to decode parameter values.
      Parameters:
      request - the HTTP request containing the query string
      enc - the character encoding to use for decoding
      Returns:
      a map of parameter names to their decoded values
      Throws:
      IOException - if an error occurs during parameter parsing
    • parseQueryString

      protected Map<String,String[]> parseQueryString(String queryString, String enc) throws IOException
      Parses a query string and extracts parameter name-value pairs. Applies URL decoding with the specified character encoding.
      Parameters:
      queryString - the query string to parse
      enc - the character encoding to use for URL decoding
      Returns:
      a map of parameter names to their decoded values
      Throws:
      IOException - if an error occurs during URL decoding
    • destroy

      public void destroy()
      Cleans up resources when the filter is destroyed. Currently performs no cleanup operations.
      Specified by:
      destroy in interface jakarta.servlet.Filter