/*
* (C) Copyright 2000 - 2006 Nabh Information Systems, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
package com.nabhinc.portal.model;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import com.nabhinc.util.StringUtil;
/**
*
*
* @author Padmanabh Dabke
* (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
*/
@XmlRootElement(name = "user-preferences")
public class UserPreferences {
public static class PortletPreferenceEntry {
public String name = null;
public String[] values = null;
public PortletPreferenceEntry() {}
public PortletPreferenceEntry(String n, String[] v) {
this.name = n;
this.values = v;
}
}
public static class PortletPreference {
public String portletWindowId = null;
public List<PortletPreferenceEntry> prefList = new ArrayList<PortletPreferenceEntry>();
}
@XmlAttribute(name = "name")
private String name = null;
@XmlElement(name = "preferred-lang")
private String preferredLang = null;
@XmlElement(name = "preferred-country")
private String preferredCountry = null;
@XmlElement(name = "timezone")
private String timezone = null;
@XmlElement(name = "show-name")
private boolean showName = false;
@XmlElement(name = "show-email")
private boolean showEmail = false;
@XmlElement(name="portlet-preference")
private List<PortletPreference> preferenceList = new ArrayList<PortletPreference>();
private transient Locale preferredLocale = null;
@XmlTransient
public Locale getPreferredLocale() {
return this.preferredLocale;
}
public void setPreferredLocale(Locale l) {
if (l == null) {
this.preferredLang = null;
this.preferredCountry = null;
this.preferredLocale = null;
} else {
this.preferredCountry = l.getCountry();
this.preferredLang = l.getLanguage();
this.preferredLocale = l;
}
}
@XmlTransient
public String getName() {
return this.name;
}
public void setName(String n) {
this.name = n;
}
@XmlTransient
public String getPreferredCountry() {
return preferredCountry;
}
public void setPreferredCountry(String preferredCountry) {
this.preferredCountry = preferredCountry;
}
@XmlTransient
public String getPreferredLang() {
return preferredLang;
}
public void setPreferredLang(String preferredLang) {
this.preferredLang = preferredLang;
}
@XmlTransient
public boolean isShowEmail() {
return showEmail;
}
public void setShowEmail(boolean showEmail) {
this.showEmail = showEmail;
}
@XmlTransient
public boolean isShowName() {
return showName;
}
public void setShowName(boolean showName) {
this.showName = showName;
}
/**
* Returns Timezone ID
* @return String representing the timezone ID.
*/
@XmlTransient
public String getTimezone() {
return timezone;
}
public void setTimezone(String timezone) {
this.timezone = timezone;
}
public void afterUnmarshal(Unmarshaller um, Object parent) {
if (this.preferredLang != null) {
if (StringUtil.isNullOrEmpty(preferredCountry))
this.preferredLocale = new Locale(this.preferredLang);
else
this.preferredLocale = new Locale(this.preferredLang,
this.preferredCountry);
}
}
public void addPortletPreference(PortletPreference pref) {
// Delete old one
removePortletPreference(pref.portletWindowId);
this.preferenceList.add(pref);
}
public void removePortletPreference(String windowId) {
for (int i=0; i<this.preferenceList.size(); i++) {
if (this.preferenceList.get(i).portletWindowId.equals(windowId)) {
this.preferenceList.remove(i);
return;
}
}
}
public PortletPreference getPortletPreference(String windowId) {
for (int i=0; i<this.preferenceList.size(); i++) {
if (this.preferenceList.get(i).portletWindowId.equals(windowId)) {
return this.preferenceList.get(i);
}
}
return null;
}
}
|