Package org.codelibs.fess.filter
Class EncodingFilter
java.lang.Object
org.codelibs.fess.filter.EncodingFilter
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptionprotected StringDefault character encoding to use for requestsstatic final StringConfiguration key for encoding rules mappingMap of path patterns to their corresponding character encodingsprotected jakarta.servlet.ServletContextServlet context for this filterprotected org.apache.commons.codec.net.URLCodecURL codec for encoding and decoding URL parameters -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Cleans up resources when the filter is destroyed.voiddoFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain) Processes requests and applies character encoding conversion if needed.getParameterMapFromQueryString(jakarta.servlet.http.HttpServletRequest request, String enc) Extracts and parses parameters from the request query string.voidinit(jakarta.servlet.FilterConfig config) Initializes the filter with configuration parameters.parseQueryString(String queryString, String enc) Parses a query string and extracts parameter name-value pairs.
-
Field Details
-
ENCODING_MAP
Configuration key for encoding rules mapping- See Also:
-
encodingMap
Map of path patterns to their corresponding character encodings -
encoding
Default character encoding to use for requests -
servletContext
protected jakarta.servlet.ServletContext servletContextServlet context for this filter -
urlCodec
protected org.apache.commons.codec.net.URLCodec urlCodecURL 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:
initin interfacejakarta.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:
doFilterin interfacejakarta.servlet.Filter- Parameters:
request- the servlet request to processresponse- the servlet response to use for redirectionchain- the filter chain to continue processing- Throws:
IOException- if an I/O error occurs during processingjakarta.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 stringenc- 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
Parses a query string and extracts parameter name-value pairs. Applies URL decoding with the specified character encoding.- Parameters:
queryString- the query string to parseenc- 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:
destroyin interfacejakarta.servlet.Filter
-