velosurf.web.l10n
Class LocalizationFilter

java.lang.Object
  extended by velosurf.web.l10n.LocalizationFilter
All Implemented Interfaces:
javax.servlet.Filter

public class LocalizationFilter
extends java.lang.Object
implements javax.servlet.Filter

Localization filter. It's goal is to redirect or forward incoming unlocalized http requests (depending on the choosen method, FORWARD or REDIRECT) towards an address taking into account the best match between requested locales and supported locales, and also to deduce the locale from URLS (when REDIRECT is used).

Optional init parameters:

(1) for now, to find supported locales if this parameter is not provided, the filter try to use the rewrite-uri param and to check for the existence of corresponding directories (only if the rewriting string contains a pattern like '/@/', that is if you use directories to store localized sites).

(2) The different match- and rewrite- parameters pairs are mutually exclusive. All matches are case-insensitive. When using the redirect method, POST parameters are lost.

When the REDIRECT method is used, these supplementary parameters (mutually exclusive) allow the filter to know whether or not an incoming URI is localized.

Author:
Claude Brisson

Field Summary
private  javax.servlet.FilterConfig _config
           
private static java.lang.String _defaultInspectUri
           
private  java.util.Locale _defaultLocale
           
private static java.lang.String _defaultMatchUri
           
private static java.lang.String _defaultRewriteUri
           
private  java.util.regex.Pattern _inspectUri
           
private  int _l10nMethod
           
private  java.util.regex.Pattern _matchUri
           
private  java.lang.String _rewriteUri
           
private  java.util.List<java.util.Locale> _supportedLocales
           
private static int FORWARD
           
private static int REDIRECT
           
private static int SECONDS_IN_YEAR
           
 
Constructor Summary
LocalizationFilter()
           
 
Method Summary
 void destroy()
           
 void doFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain chain)
           
private  void findSupportedLocales(javax.servlet.FilterConfig config)
           
private  java.lang.String getInitParameter(java.lang.String key)
           
private  java.lang.String getInitParameter(java.lang.String key, java.lang.String defaultValue)
           
private  java.util.Locale getMatchedLocale(java.lang.String candidate)
           
private  java.util.Locale getPreferredLocale(java.util.List<java.util.Locale> requestedLocales)
           
private  java.util.List<java.util.Locale> getRequestedLocales(javax.servlet.http.HttpServletRequest request)
           
private  java.util.List<java.util.Locale> guessSupportedLocales(javax.servlet.ServletContext ctx, java.lang.String path)
           
 void init(javax.servlet.FilterConfig config)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_config

private javax.servlet.FilterConfig _config

_supportedLocales

private java.util.List<java.util.Locale> _supportedLocales

_defaultLocale

private java.util.Locale _defaultLocale

SECONDS_IN_YEAR

private static int SECONDS_IN_YEAR

_defaultMatchUri

private static java.lang.String _defaultMatchUri

_defaultRewriteUri

private static java.lang.String _defaultRewriteUri

_defaultInspectUri

private static java.lang.String _defaultInspectUri

_matchUri

private java.util.regex.Pattern _matchUri

_rewriteUri

private java.lang.String _rewriteUri

_inspectUri

private java.util.regex.Pattern _inspectUri

FORWARD

private static final int FORWARD
See Also:
Constant Field Values

REDIRECT

private static final int REDIRECT
See Also:
Constant Field Values

_l10nMethod

private int _l10nMethod
Constructor Detail

LocalizationFilter

public LocalizationFilter()
Method Detail

init

public void init(javax.servlet.FilterConfig config)
          throws javax.servlet.ServletException
Specified by:
init in interface javax.servlet.Filter
Throws:
javax.servlet.ServletException

doFilter

public void doFilter(javax.servlet.ServletRequest servletRequest,
                     javax.servlet.ServletResponse servletResponse,
                     javax.servlet.FilterChain chain)
              throws java.io.IOException,
                     javax.servlet.ServletException
Specified by:
doFilter in interface javax.servlet.Filter
Throws:
java.io.IOException
javax.servlet.ServletException

findSupportedLocales

private void findSupportedLocales(javax.servlet.FilterConfig config)

getInitParameter

private java.lang.String getInitParameter(java.lang.String key)

getInitParameter

private java.lang.String getInitParameter(java.lang.String key,
                                          java.lang.String defaultValue)

destroy

public void destroy()
Specified by:
destroy in interface javax.servlet.Filter

guessSupportedLocales

private java.util.List<java.util.Locale> guessSupportedLocales(javax.servlet.ServletContext ctx,
                                                               java.lang.String path)

getRequestedLocales

private java.util.List<java.util.Locale> getRequestedLocales(javax.servlet.http.HttpServletRequest request)

getMatchedLocale

private java.util.Locale getMatchedLocale(java.lang.String candidate)

getPreferredLocale

private java.util.Locale getPreferredLocale(java.util.List<java.util.Locale> requestedLocales)


~ooOoo~