01: /*
02: * Copyright ? 2006 Sun Microsystems, Inc. All rights reserved.
03: *
04: * Sun Microsystems, Inc. has intellectual property rights relating to
05: * technology embodied in the product that is described in this document.
06: * In particular, and without limitation, these intellectual property
07: * rights may include one or more of the U.S. patents listed at
08: * http://www.sun.com/patents and one or more additional patents or
09: * pending patent applications in the U.S. and in other countries.
10: *
11: * U.S. Government Rights - Commercial software. Government users are subject
12: * to the Sun Microsystems, Inc. standard license agreement and applicable
13: * provisions of the FAR and its supplements. Use is subject to license terms.
14: * This distribution may include materials developed by third parties.
15: * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
16: * trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
17: */
18: package com.sun.portal.app.blog.env;
19:
20: import java.util.Locale;
21: import java.util.Map;
22: import java.util.TimeZone;
23: import javax.faces.context.ExternalContext;
24: import javax.faces.context.FacesContext;
25: import javax.portlet.PortletRequest;
26:
27: /**
28: * Implementation of User running in a portlet environment.
29: */
30: public class PortletUser extends User {
31: public static class AttrKeys {
32: public static final String TIMEZONE = "timezone";
33: public static final String LOCALE = "locale";
34: }
35:
36: private String getAttribute(String key) {
37: ExternalContext econtext = FacesContext.getCurrentInstance()
38: .getExternalContext();
39: PortletRequest preq = (PortletRequest) econtext.getRequest();
40: Map attrs = (Map) preq.getAttribute(PortletRequest.USER_INFO);
41:
42: if (attrs == null) {
43: return null;
44: }
45:
46: String attr = (String) attrs.get(key);
47: return attr;
48: }
49:
50: public TimeZone getTimeZone() {
51: TimeZone timezone;
52:
53: String tz = getAttribute(AttrKeys.TIMEZONE);
54: if (tz == null) {
55: timezone = TimeZone.getDefault();
56: } else {
57: timezone = TimeZone.getTimeZone(tz);
58: }
59:
60: return timezone;
61: }
62:
63: public Locale getLocale() {
64: Locale locale;
65:
66: String l = getAttribute(AttrKeys.LOCALE);
67: if (l == null) {
68: ExternalContext econtext = FacesContext
69: .getCurrentInstance().getExternalContext();
70: PortletRequest preq = (PortletRequest) econtext
71: .getRequest();
72: locale = preq.getLocale();
73: } else {
74: locale = new Locale(l);
75: }
76:
77: return locale;
78: }
79: }
|