velosurf.web.l10n
Class LocalizationFilter
java.lang.Object
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:
- supported-locales: comma separated list of supported locales ; if not provided, there is an attempt to programatically determine it(1).
No default value provided.
- default-locale: the locale to be used by default (after four checks: the incoming URI, the session, cookies, and the request headers).
No default value provided.
- localization-method:
forward or redirect, default is redirect.
- match-host & rewrite-host: not yet implemented.(2)
- match-uri & rewrite-uri: the regular expression against which an unlocalized uri is matched, and the replacement uri, where
@ represents the locale and $1, $2, ... the matched sub-patterns. Defaults are ^/(.*)$
for match-uri and /@/$1 for rewrite-uri.(2)
- match-query-string & rewrite-query-string: not yet implemented.(2)
- match-url & rewrite-url: not yet implemented.(2)
(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.
- inspect-host: not yet implemented.
- inspect-uri: default is
^/(.+)(?:/|$).
- inspect-query-string: not yet implemented.
- inspect-url: not yet implemented.
- Author:
- Claude Brisson
|
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 |
_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
LocalizationFilter
public LocalizationFilter()
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~