1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.imca.web.backingbeans;
17
18 import java.io.IOException;
19 import java.util.Iterator;
20 import java.util.Locale;
21 import java.util.Properties;
22 import java.util.Vector;
23
24 import javax.faces.FactoryFinder;
25 import javax.faces.application.Application;
26 import javax.faces.application.ApplicationFactory;
27 import javax.faces.model.SelectItem;
28
29 import net.sf.imca.model.ImcaUtils;
30 import net.sf.imca.model.PersonBO;
31 import net.sf.imca.model.entities.MembershipEntity;
32 import net.sf.imca.services.CommitteeService;
33
34
35
36
37
38
39 public class WebUser {
40
41 private static String footer = null;
42
43 private PersonBO person = new PersonBO();
44
45 private boolean logedIn = false;
46
47 public boolean getLogedIn() {
48 return logedIn;
49 }
50
51 public void setLogedIn(boolean logedIn) {
52 this.logedIn = logedIn;
53 }
54
55 public String getName() {
56 return person.getName();
57 }
58
59 public String getEmail() {
60 if (person.getEntity() == null) {
61 return "";
62 }
63 return person.getEntity().getEmail();
64 }
65
66 public PersonBO getPerson() {
67 return person;
68 }
69
70 public void setPerson(PersonBO person) {
71 this.person = person;
72 }
73
74 public boolean getOnImcaCommittee() {
75 CommitteeService service = new CommitteeService();
76 return service.getOnImcaCommittee(Utils.getWebUser().getPerson());
77 }
78
79 public SelectItem[] getCurrencyCodeItems() {
80
81 String[] keys = ImcaUtils.getCurrencyCodes();
82 SelectItem[] items = new SelectItem[keys.length];
83
84 for (int i = 0; i < keys.length; i++) {
85 items[i] = new SelectItem(keys[i], keys[i]);
86 }
87
88 return items;
89 }
90
91 public SelectItem[] getCountryItems() {
92
93 String[] keys = ImcaUtils.getCountryCodes();
94 SelectItem[] items = new SelectItem[keys.length];
95
96 for (int i = 0; i < keys.length; i++) {
97 Locale loc = new Locale("", keys[i]);
98 items[i] = new SelectItem(keys[i], keys[i] + " - "
99 + loc.getDisplayCountry(Utils.getWebAppLocale()));
100 }
101
102 return items;
103 }
104
105 @SuppressWarnings("unchecked")
106 public SelectItem[] getLanguageItems() {
107
108 ApplicationFactory appFactory = (ApplicationFactory) FactoryFinder
109 .getFactory(FactoryFinder.APPLICATION_FACTORY);
110 Application application = appFactory.getApplication();
111 Iterator<Locale> iter = application.getSupportedLocales();
112 Vector<Locale> locales = new Vector<Locale>();
113
114 while (iter.hasNext()) {
115 locales.add(iter.next());
116 }
117
118 SelectItem[] items = new SelectItem[locales.size()];
119 for (int i = 0; i < locales.size(); i++) {
120 items[i] = new SelectItem(locales.get(i).getLanguage(),
121 locales.get(i).getDisplayLanguage(Utils.getWebAppLocale()));
122 }
123
124 return items;
125 }
126
127 public String getDatePattern() {
128 return ImcaUtils.IMCA_DATE_PATTERN;
129 }
130
131 public String getFooter(){
132 if (footer == null){
133 Properties props = new Properties();
134 try {
135 props.load(this.getClass().getClassLoader().getResourceAsStream(
136 "imca_config.properties"));
137 footer = props.getProperty("application.name") + ", " +
138 props.getProperty("application.version");
139 } catch (IOException e) {
140 footer = e.getMessage();
141 }
142 }
143 return footer;
144 }
145
146 }