|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object velosurf.web.l10n.LocalizationFilter
public class LocalizationFilter
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 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.
Field Summary | |
---|---|
private javax.servlet.FilterConfig |
config
filter config. |
private static java.lang.String |
defaultInspectUri
default inspect uri. |
private java.util.Locale |
defaultLocale
default locale. |
private static java.lang.String |
defaultMatchUri
default match uri. |
private static java.lang.String |
defaultRewriteUri
default rewrite uri. |
private static int |
FORWARD
forward method constant. |
private java.util.regex.Pattern |
inspectUri
inspect uri. |
private int |
l10nMethod
localization method. |
private java.util.regex.Pattern |
matchUri
match uri. |
private static int |
REDIRECT
redirect method constant. |
private java.lang.String |
rewriteUri
rewrite uri |
private static int |
SECONDS_IN_YEAR
seconds in year (for setting cookies age). |
private java.util.List<java.util.Locale> |
supportedLocales
supported locales. |
Constructor Summary | |
---|---|
LocalizationFilter()
|
Method Summary | |
---|---|
void |
destroy()
Destroy the filter. |
void |
doFilter(javax.servlet.ServletRequest servletRequest,
javax.servlet.ServletResponse servletResponse,
javax.servlet.FilterChain chain)
Filtering. |
private void |
findSupportedLocales(javax.servlet.FilterConfig config)
Find supported locales. |
private java.lang.String |
getInitParameter(java.lang.String key)
Helper function. |
private java.lang.String |
getInitParameter(java.lang.String key,
java.lang.String defaultValue)
Helper function. |
private java.util.Locale |
getMatchedLocale(java.lang.String candidate)
get matched locale. |
private java.util.Locale |
getPreferredLocale(java.util.List<java.util.Locale> requestedLocales)
Get preferred locale. |
private java.util.List<java.util.Locale> |
getRequestedLocales(javax.servlet.http.HttpServletRequest request)
get the list of requested locales. |
private java.util.List<java.util.Locale> |
guessSupportedLocales(javax.servlet.ServletContext ctx,
java.lang.String path)
Guess supported locales. |
void |
init(javax.servlet.FilterConfig config)
initialization. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private javax.servlet.FilterConfig config
private java.util.List<java.util.Locale> supportedLocales
private java.util.Locale defaultLocale
private static int SECONDS_IN_YEAR
private static java.lang.String defaultMatchUri
private static java.lang.String defaultRewriteUri
private static java.lang.String defaultInspectUri
private java.util.regex.Pattern matchUri
private java.lang.String rewriteUri
private java.util.regex.Pattern inspectUri
private static final int FORWARD
private static final int REDIRECT
private int l10nMethod
Constructor Detail |
---|
public LocalizationFilter()
Method Detail |
---|
public void init(javax.servlet.FilterConfig config) throws javax.servlet.ServletException
init
in interface javax.servlet.Filter
config
- filter config
javax.servlet.ServletException
public void doFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain chain) throws java.io.IOException, javax.servlet.ServletException
doFilter
in interface javax.servlet.Filter
servletRequest
- requestservletResponse
- responsechain
- filter chain
java.io.IOException
javax.servlet.ServletException
private void findSupportedLocales(javax.servlet.FilterConfig config)
config
- filter configprivate java.lang.String getInitParameter(java.lang.String key)
key
-
private java.lang.String getInitParameter(java.lang.String key, java.lang.String defaultValue)
key
- defaultValue
-
public void destroy()
destroy
in interface javax.servlet.Filter
private java.util.List<java.util.Locale> guessSupportedLocales(javax.servlet.ServletContext ctx, java.lang.String path)
ctx
- servlet contextpath
- path
private java.util.List<java.util.Locale> getRequestedLocales(javax.servlet.http.HttpServletRequest request)
request
- request
private java.util.Locale getMatchedLocale(java.lang.String candidate)
candidate
- candidate
private java.util.Locale getPreferredLocale(java.util.List<java.util.Locale> requestedLocales)
requestedLocales
- requested locales
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |