001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.gwt.shared; 029 030import org.opencms.xml.content.CmsXmlContentProperty; 031 032import java.util.Collections; 033import java.util.HashMap; 034import java.util.HashSet; 035import java.util.LinkedHashMap; 036import java.util.Map; 037import java.util.Set; 038 039import com.google.gwt.user.client.rpc.IsSerializable; 040 041/** 042 * Bean for transferring user preference information between the client and the server.<p> 043 */ 044public class CmsUserSettingsBean implements IsSerializable { 045 046 /** Map of property definitions corresponding to the user settings. */ 047 private LinkedHashMap<String, CmsXmlContentProperty> m_settingConfiguration = new LinkedHashMap<String, CmsXmlContentProperty>(); 048 049 /** Map of the current values of the user settings. */ 050 private Map<String, String> m_values = new HashMap<String, String>(); 051 052 /** Set of keys of the "basic" (as opposed to "extended") options. */ 053 private Set<String> m_basicOptions = new HashSet<String>(); 054 055 /** 056 * Default constructor.<p> 057 */ 058 public CmsUserSettingsBean() { 059 060 // do nothing 061 062 } 063 064 /** 065 * Adds a user setting.<p> 066 * 067 * @param value the current value of the user setting 068 * @param config the configuration for the user setting 069 * 070 * @param basic true if this is a basic user setting 071 */ 072 public void addSetting(String value, CmsXmlContentProperty config, boolean basic) { 073 074 m_values.put(config.getName(), value); 075 m_settingConfiguration.put(config.getName(), config); 076 if (basic) { 077 m_basicOptions.add(config.getName()); 078 } 079 } 080 081 /** 082 * Gets the map with the configurations for the individual user settings.<p> 083 * 084 * @return the user setting configurations, indexed by user setting name 085 */ 086 public Map<String, CmsXmlContentProperty> getConfiguration() { 087 088 return Collections.unmodifiableMap(m_settingConfiguration); 089 } 090 091 /** 092 * Gets the value for a given user setting.<p> 093 * 094 * @param key the user setting key 095 * 096 * @return the current value of the user setting 097 */ 098 public String getValue(String key) { 099 100 return m_values.get(key); 101 } 102 103 /** 104 * Returns true if the user setting with the given name is a basic setting 105 * 106 * @param name the user setting name 107 * 108 * @return true if this is a basic setting 109 */ 110 public boolean isBasic(String name) { 111 112 return m_basicOptions.contains(name); 113 } 114 115}