001: package org.tigris.scarab.tools.localization;
002:
003: import org.tigris.scarab.tools.ScarabLocalizationTool;
004:
005: /* ================================================================
006: * Copyright (c) 2000 CollabNet. All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions are
010: * met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in the
017: * documentation and/or other materials provided with the distribution.
018: *
019: * 3. The end-user documentation included with the redistribution, if
020: * any, must include the following acknowlegement: "This product includes
021: * software developed by CollabNet (http://www.collab.net/)."
022: * Alternately, this acknowlegement may appear in the software itself, if
023: * and wherever such third-party acknowlegements normally appear.
024: *
025: * 4. The hosted project names must not be used to endorse or promote
026: * products derived from this software without prior written
027: * permission. For written permission, please contact info@collab.net.
028: *
029: * 5. Products derived from this software may not use the "Tigris" name
030: * nor may "Tigris" appear in their names without prior written
031: * permission of CollabNet.
032: *
033: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
034: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
035: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
036: * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
037: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
038: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
039: * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
040: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
041: * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
042: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
043: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
044: *
045: * ====================================================================
046: *
047: * This software consists of voluntary contributions made by many
048: * individuals on behalf of CollabNet.
049: */
050:
051: /**
052: * Default implementation of a Localization Key.
053: * <p>
054: * Acts as a simple wrapper around the real key. Instances are immutable.
055: *
056: * @author <a href="mailto:dabbous@saxess.com">Hussayn Dabbous</a>
057: */
058: public final class L10NKey implements LocalizationKey, Localizable {
059:
060: /**
061: * The key.
062: * Only used internally from ScarabLocalizationTool.
063: */
064: private final String key;
065:
066: /**
067: * @return the <code>String<code> representation of the key.
068: * Only used from L10NKeySet to construct keys.
069: * @param theKey
070: */
071: public String toString() {
072: return key;
073: }
074:
075: /**
076: * Constructs a L10NKey instance using the specified key.
077: * Only used internaly from ScarabLocalizationTool.
078: * @param theKey the final <code>String<code> representation of the key
079: */
080: public L10NKey(String theKey) {
081: key = theKey;
082: }
083:
084: /*
085: * Return the string representation of this key for the DEFAULT_LOCALE
086: * @see org.tigris.scarab.tools.localization.Localizable#getMessage()
087: */
088: public String getMessage() {
089: ScarabLocalizationTool l10n = new ScarabLocalizationTool();
090: l10n.init(ScarabLocalizationTool.DEFAULT_LOCALE);
091: return getMessage(l10n);
092: }
093:
094: /*
095: * Return the string representation of this key for the goven locale.
096: * @see org.tigris.scarab.tools.localization.Localizable#getMessage(org.tigris.scarab.tools.ScarabLocalizationTool)
097: */
098: public String getMessage(ScarabLocalizationTool l10n) {
099: return l10n.get(this);
100: }
101:
102: }
|