1 package org.apache.turbine.services.localization;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Locale;
23
24 import org.apache.fulcrum.localization.DefaultLocalizationService;
25 import org.apache.fulcrum.localization.LocalizationService;
26 import org.apache.logging.log4j.LogManager;
27 import org.apache.logging.log4j.Logger;
28 import org.apache.turbine.om.security.User;
29 import org.apache.turbine.util.RunData;
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public class RundataLocalizationService extends DefaultLocalizationService implements RundataLocalizationInterface {
44
45 private static final Logger log = LogManager.getLogger(RundataLocalizationService.class);
46
47 @Override
48 public Locale getLocale(RunData data) {
49 User user = data.getUser();
50 log.debug( "retrieving lang from req header :{}",
51 (user == null || user.getTemp("locale") == null ) );
52
53 if (user == null)
54 {
55 return getLocale(data.getRequest().getHeader(LocalizationService.ACCEPT_LANGUAGE));
56 }
57 else
58 {
59 try
60 {
61 Locale locale = (Locale) data.getUser().getTemp("locale");
62 if (locale == null)
63 {
64 return getLocale(data.getRequest().getHeader(LocalizationService.ACCEPT_LANGUAGE));
65 }
66 else
67 {
68 log.debug( "retrieved lang from temp(locale):{}", ()-> locale.getLanguage() );
69 return locale;
70 }
71 }
72 catch (Exception use)
73 {
74 return getLocale(data.getRequest().getHeader(LocalizationService.ACCEPT_LANGUAGE));
75 }
76 }
77 }
78
79 }