001: /*
002: * (C) Copyright 2000 - 2006 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019: package com.nabhinc.portal.model;
020:
021: import java.util.ArrayList;
022: import java.util.List;
023: import java.util.Locale;
024:
025: import javax.xml.bind.Unmarshaller;
026: import javax.xml.bind.annotation.XmlAttribute;
027: import javax.xml.bind.annotation.XmlElement;
028: import javax.xml.bind.annotation.XmlRootElement;
029: import javax.xml.bind.annotation.XmlTransient;
030:
031: import com.nabhinc.util.StringUtil;
032:
033: /**
034: *
035: *
036: * @author Padmanabh Dabke
037: * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
038: */
039: @XmlRootElement(name="user-preferences")
040: public class UserPreferences {
041:
042: public static class PortletPreferenceEntry {
043: public String name = null;
044: public String[] values = null;
045:
046: public PortletPreferenceEntry() {
047: }
048:
049: public PortletPreferenceEntry(String n, String[] v) {
050: this .name = n;
051: this .values = v;
052: }
053: }
054:
055: public static class PortletPreference {
056: public String portletWindowId = null;
057: public List<PortletPreferenceEntry> prefList = new ArrayList<PortletPreferenceEntry>();
058: }
059:
060: @XmlAttribute(name="name")
061: private String name = null;
062:
063: @XmlElement(name="preferred-lang")
064: private String preferredLang = null;
065:
066: @XmlElement(name="preferred-country")
067: private String preferredCountry = null;
068:
069: @XmlElement(name="timezone")
070: private String timezone = null;
071:
072: @XmlElement(name="show-name")
073: private boolean showName = false;
074:
075: @XmlElement(name="show-email")
076: private boolean showEmail = false;
077:
078: @XmlElement(name="portlet-preference")
079: private List<PortletPreference> preferenceList = new ArrayList<PortletPreference>();
080:
081: private transient Locale preferredLocale = null;
082:
083: @XmlTransient
084: public Locale getPreferredLocale() {
085: return this .preferredLocale;
086: }
087:
088: public void setPreferredLocale(Locale l) {
089: if (l == null) {
090: this .preferredLang = null;
091: this .preferredCountry = null;
092: this .preferredLocale = null;
093: } else {
094: this .preferredCountry = l.getCountry();
095: this .preferredLang = l.getLanguage();
096: this .preferredLocale = l;
097: }
098: }
099:
100: @XmlTransient
101: public String getName() {
102: return this .name;
103: }
104:
105: public void setName(String n) {
106: this .name = n;
107: }
108:
109: @XmlTransient
110: public String getPreferredCountry() {
111: return preferredCountry;
112: }
113:
114: public void setPreferredCountry(String preferredCountry) {
115: this .preferredCountry = preferredCountry;
116: }
117:
118: @XmlTransient
119: public String getPreferredLang() {
120: return preferredLang;
121: }
122:
123: public void setPreferredLang(String preferredLang) {
124: this .preferredLang = preferredLang;
125: }
126:
127: @XmlTransient
128: public boolean isShowEmail() {
129: return showEmail;
130: }
131:
132: public void setShowEmail(boolean showEmail) {
133: this .showEmail = showEmail;
134: }
135:
136: @XmlTransient
137: public boolean isShowName() {
138: return showName;
139: }
140:
141: public void setShowName(boolean showName) {
142: this .showName = showName;
143: }
144:
145: /**
146: * Returns Timezone ID
147: * @return String representing the timezone ID.
148: */
149: @XmlTransient
150: public String getTimezone() {
151: return timezone;
152: }
153:
154: public void setTimezone(String timezone) {
155: this .timezone = timezone;
156: }
157:
158: public void afterUnmarshal(Unmarshaller um, Object parent) {
159: if (this .preferredLang != null) {
160: if (StringUtil.isNullOrEmpty(preferredCountry))
161: this .preferredLocale = new Locale(this .preferredLang);
162: else
163: this .preferredLocale = new Locale(this .preferredLang,
164: this .preferredCountry);
165: }
166: }
167:
168: public void addPortletPreference(PortletPreference pref) {
169: // Delete old one
170: removePortletPreference(pref.portletWindowId);
171: this .preferenceList.add(pref);
172: }
173:
174: public void removePortletPreference(String windowId) {
175: for (int i = 0; i < this .preferenceList.size(); i++) {
176: if (this .preferenceList.get(i).portletWindowId
177: .equals(windowId)) {
178: this .preferenceList.remove(i);
179: return;
180: }
181: }
182: }
183:
184: public PortletPreference getPortletPreference(String windowId) {
185: for (int i = 0; i < this.preferenceList.size(); i++) {
186: if (this.preferenceList.get(i).portletWindowId
187: .equals(windowId)) {
188: return this.preferenceList.get(i);
189: }
190: }
191: return null;
192: }
193:
194: }
|