001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.base.category;
019:
020: import java.util.HashMap;
021: import java.util.Locale;
022: import java.util.Map;
023: import java.util.StringTokenizer;
024: import java.util.logging.Logger;
025:
026: import de.finix.contelligent.client.base.Description;
027: import de.finix.contelligent.client.modules.preferences.PreferencesModule;
028:
029: public class DefaultContelligentCategory implements
030: ContelligentCategory {
031: private static Logger logger = Logger
032: .getLogger(DefaultContelligentCategory.class.getName());
033:
034: private String name, defaultValue;
035:
036: private Map<String, String> supportedValues = new HashMap<String, String>(); // contains supportedValue /
037: // fallbackValue (both of
038: // type String)
039:
040: /** Contains all descriptions in all languages. Language is the key */
041: private Map<String, Description> descriptionMap = new HashMap<String, Description>();
042:
043: public DefaultContelligentCategory(String name, String defaultValue) {
044: this (name);
045: this .defaultValue = defaultValue;
046: }
047:
048: public DefaultContelligentCategory(String name) {
049: this .name = name;
050: }
051:
052: public void setName(String name) {
053: this .name = name;
054: }
055:
056: public String getName() {
057: return name;
058: }
059:
060: public void setSupportedValuesList(String supportedValues) {
061: for (StringTokenizer tokenizer = new StringTokenizer(
062: supportedValues, ","); tokenizer.hasMoreTokens();) {
063: String supportedValue = tokenizer.nextToken();
064: addValue(supportedValue);
065: }
066: }
067:
068: public void addValue(String value) {
069: supportedValues.put(value, null);
070: }
071:
072: public void addValue(String value, String fallback) {
073: supportedValues.put(value, fallback);
074: }
075:
076: public String getDefaultValue() {
077: return defaultValue;
078: }
079:
080: public String getFallbackValue(String value) {
081: return (String) supportedValues.get(value);
082: }
083:
084: public String[] getSupportedValues() {
085: return (String[]) supportedValues.keySet().toArray(
086: new String[] {});
087: }
088:
089: public boolean isValueSupported(String value) {
090: return supportedValues.containsKey(value);
091: }
092:
093: public void addDescription(String lang, String title, String text,
094: String helpURL) {
095: descriptionMap.put(lang, new Description(lang, title, text,
096: helpURL));
097: }
098:
099: public Description getDescription(String lang) {
100: if (descriptionMap.containsKey(lang)) {
101: return (Description) descriptionMap.get(lang);
102: } else if (descriptionMap.containsKey(PreferencesModule
103: .getDefaultLanguage())) {
104: return (Description) descriptionMap.get(PreferencesModule
105: .getDefaultLanguage());
106: }
107: return null;
108: }
109:
110: public Description getDescription(Locale locale) {
111: return getDescription(locale.getLanguage());
112: }
113:
114: public boolean equals(Object category) {
115: if (category instanceof String) {
116: return name.equals(category);
117: }
118: if (category instanceof ContelligentCategory) {
119: return name.equals(((ContelligentCategory) category)
120: .getName());
121: }
122: return false;
123: }
124:
125: public int hashCode() {
126: return -1;
127: }
128:
129: }
|