1: package cz.cvut.x33eja.macosond.web.back;
2:
3: import cz.cvut.x33eja.macosond.business.util.LocaleChoiceLocal;
4: import java.util.Locale;
5: import javax.ejb.EJB;
6: import javax.faces.context.FacesContext;
7:
8: 9: 10: 11:
12: public class LocaleBack
13: {
14: @EJB
15: private LocaleChoiceLocal localeChoiceBean;
16:
17: public LocaleBack()
18: {
19: super();
20: }
21:
22: public Locale getCurrentLocale()
23: {
24: Locale current = localeChoiceBean.getCurrentLocale();
25: if(current == null) {
26: Locale preferred = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale();
27: if(!preferred.equals(LocaleChoiceLocal.CZECH) && !preferred.equals(LocaleChoiceLocal.ENGLISH)) {
28: current = LocaleChoiceLocal.CZECH;
29: }
30: setCurrentLocale(current);
31: }
32: return current;
33: }
34:
35: public void setCurrentLocale(Locale currentLocale)
36: {
37: FacesContext.getCurrentInstance().getViewRoot().setLocale(currentLocale);
38: localeChoiceBean.setCurrentLocale(currentLocale);
39: }
40:
41: public boolean isCzech()
42: {
43: if(getCurrentLocale() == null) {
44: return false;
45: }
46: return getCurrentLocale().equals(LocaleChoiceLocal.CZECH);
47: }
48:
49: public boolean isEnglish()
50: {
51: return !isCzech();
52: }
53:
54:
55: 56: 57:
58:
59: public void switchToEnglish()
60: {
61: setCurrentLocale(LocaleChoiceLocal.ENGLISH);
62: }
63:
64: public void switchToCzech()
65: {
66: setCurrentLocale(LocaleChoiceLocal.CZECH);
67: }
68:
69:
70: }
71: