001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.shared;
034:
035: import com.flexive.shared.value.FxString;
036:
037: import java.io.Serializable;
038: import java.util.Locale;
039:
040: /**
041: * Languages
042: * Provides mapping functions between language system constants , iso codes and english descriptions.
043: *
044: * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
045: * @version $Rev
046: */
047: public class FxLanguage extends AbstractSelectableObjectWithName
048: implements Serializable, SelectableObjectWithLabel {
049: private static final long serialVersionUID = -7060915362180672721L;
050: /**
051: * language set for groups or not localized properties
052: */
053: public static final long SYSTEM_ID = 0;
054: /**
055: * default language (english)
056: */
057: public static final long DEFAULT_ID = 1;
058: /**
059: * default language ISO code
060: */
061: public static final String DEFAULT_ISO = "en";
062: /**
063: * default language object
064: */
065: public static final FxLanguage DEFAULT = new FxLanguage(DEFAULT_ID,
066: DEFAULT_ISO, new FxString("English"), true);
067:
068: private long id;
069: private String iso2digit;
070: private FxString name;
071: private boolean licensed;
072:
073: /**
074: * pre defined language english
075: */
076: public static final long ENGLISH = 1;
077:
078: /**
079: * pre defined language german
080: */
081: public static final long GERMAN = 2;
082:
083: /**
084: * pre defined language french
085: */
086: public static final long FRENCH = 3;
087:
088: /**
089: * pre defined language italian
090: */
091: public static final long ITALIAN = 4;
092:
093: /**
094: * Language constructor.
095: *
096: * @param id the language ID
097: * @param iso2digit the 2-digit ISO code (en, de, fr, ...)
098: * @param name the localized language name
099: * @param licensed if the language is licensed for the current server installation
100: */
101: public FxLanguage(long id, String iso2digit, FxString name,
102: boolean licensed) {
103: this .id = id;
104: this .iso2digit = iso2digit;
105: this .licensed = licensed;
106: this .name = name;
107: }
108:
109: public FxLanguage(String localeIso) {
110: if (localeIso.startsWith("en")) {
111: this .id = ENGLISH;
112: this .name = new FxString("English");
113: } else if (localeIso.startsWith("de")) {
114: this .id = GERMAN;
115: this .name = new FxString("German");
116: } else if (localeIso.startsWith("fr")) {
117: this .id = FRENCH;
118: this .name = new FxString("French");
119: } else if (localeIso.startsWith("it")) {
120: this .id = ITALIAN;
121: this .name = new FxString("Italian");
122: }
123: this .iso2digit = localeIso.substring(0, 2);
124: }
125:
126: public long getId() {
127: return id;
128: }
129:
130: public String getIso2digit() {
131: return iso2digit;
132: }
133:
134: public Locale getLocale() {
135: return new Locale(getIso2digit());
136: }
137:
138: /**
139: * {@inheritDoc}
140: */
141: public String getName() {
142: return name.getDefaultTranslation();
143: }
144:
145: /**
146: * {@inheritDoc}
147: */
148: public FxString getLabel() {
149: return name;
150: }
151:
152: public boolean isLicensed() {
153: return licensed;
154: }
155:
156: /**
157: * {@inheritDoc}
158: */
159: @Override
160: public String toString() {
161: return iso2digit + "(" + name + ")";
162: }
163:
164: /**
165: * {@inheritDoc}
166: */
167: @Override
168: public boolean equals(Object obj) {
169: if (!(obj instanceof FxLanguage))
170: return false;
171: FxLanguage comp = (FxLanguage) obj;
172: return (comp.getIso2digit().equals(this .getIso2digit()));
173: }
174:
175: /**
176: * {@inheritDoc}
177: */
178: @Override
179: public int hashCode() {
180: return iso2digit.hashCode();
181: }
182:
183: }
|