1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.cms.i18n;
35
36 import info.magnolia.cms.core.AggregationState;
37 import info.magnolia.cms.filters.AbstractMgnlFilter;
38 import info.magnolia.context.MgnlContext;
39 import info.magnolia.objectfactory.Components;
40
41 import java.io.IOException;
42 import java.util.Locale;
43
44 import javax.inject.Inject;
45 import javax.servlet.FilterChain;
46 import javax.servlet.ServletException;
47 import javax.servlet.http.HttpServletRequest;
48 import javax.servlet.http.HttpServletResponse;
49 import javax.servlet.jsp.jstl.core.Config;
50
51
52
53
54 public class I18nContentSupportFilter extends AbstractMgnlFilter {
55
56 private final I18nContentSupport i18nContentSupport;
57
58
59
60
61 @Deprecated
62 public I18nContentSupportFilter() {
63 this(Components.getComponent(I18nContentSupport.class));
64 }
65
66 @Inject
67 public I18nContentSupportFilter(I18nContentSupport i18nContentSupport) {
68 this.i18nContentSupport = i18nContentSupport;
69 }
70 @Override
71 public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
72 if (i18nContentSupport != null) {
73
74 final Locale locale = i18nContentSupport.determineLocale();
75 i18nContentSupport.setLocale(locale);
76
77 AggregationState aggregationState = MgnlContext.getAggregationState();
78 String currentUri = aggregationState.getCurrentURI();
79 String newUri = i18nContentSupport.toRawURI(currentUri);
80
81 if (!currentUri.equals(newUri)) {
82 aggregationState.setCurrentURI(newUri);
83 }
84
85
86 Config.set(request, Config.FMT_LOCALE, locale);
87 }
88
89 chain.doFilter(request, response);
90 }
91 }