01: /**
02: *
03: */package clime.messadmin.providers.locale;
04:
05: import java.util.ArrayList;
06: import java.util.Enumeration;
07: import java.util.List;
08: import java.util.Locale;
09:
10: import javax.servlet.http.HttpSession;
11:
12: import clime.messadmin.providers.spi.LocaleProvider;
13:
14: /**
15: * Search all attributes for a single java.util.Locale
16: * @author Cédrik LIME
17: */
18: public class AttributesIterator implements LocaleProvider {
19:
20: /**
21: *
22: */
23: public AttributesIterator() {
24: super ();
25: }
26:
27: /**
28: * {@inheritDoc}
29: */
30: public int getPriority() {
31: return 200;
32: }
33:
34: /**
35: * {@inheritDoc}
36: */
37: public Locale guessLocaleFromSession(HttpSession httpSession) {
38: Locale locale = null;
39:
40: final List localeArray = new ArrayList();
41: for (Enumeration enumeration = httpSession.getAttributeNames(); enumeration
42: .hasMoreElements();) {
43: String name = (String) enumeration.nextElement();
44: Object obj = httpSession.getAttribute(name);
45: if (null != obj && obj instanceof Locale) {
46: localeArray.add(obj);
47: }
48: }
49: if (localeArray.size() == 1) {
50: locale = (Locale) localeArray.get(0);
51: }
52:
53: return locale;
54: }
55:
56: }
|