KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > tools > localization > L10NKey


1 package org.tigris.scarab.tools.localization;
2
3 import org.tigris.scarab.tools.ScarabLocalizationTool;
4
5
6 /* ================================================================
7  * Copyright (c) 2000 CollabNet. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are
11  * met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in the
18  * documentation and/or other materials provided with the distribution.
19  *
20  * 3. The end-user documentation included with the redistribution, if
21  * any, must include the following acknowlegement: "This product includes
22  * software developed by CollabNet (http://www.collab.net/)."
23  * Alternately, this acknowlegement may appear in the software itself, if
24  * and wherever such third-party acknowlegements normally appear.
25  *
26  * 4. The hosted project names must not be used to endorse or promote
27  * products derived from this software without prior written
28  * permission. For written permission, please contact info@collab.net.
29  *
30  * 5. Products derived from this software may not use the "Tigris" name
31  * nor may "Tigris" appear in their names without prior written
32  * permission of CollabNet.
33  *
34  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
35  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
36  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
37  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
38  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
40  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
41  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
42  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
43  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
44  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45  *
46  * ====================================================================
47  *
48  * This software consists of voluntary contributions made by many
49  * individuals on behalf of CollabNet.
50  */

51
52 /**
53  * Default implementation of a Localization Key.
54  * <p>
55  * Acts as a simple wrapper around the real key. Instances are immutable.
56  *
57  * @author <a HREF="mailto:dabbous@saxess.com">Hussayn Dabbous</a>
58  */

59 public final class L10NKey implements LocalizationKey, Localizable
60 {
61     
62
63     /**
64      * The key.
65      * Only used internally from ScarabLocalizationTool.
66      */

67     private final String JavaDoc key;
68
69     /**
70      * @return the <code>String<code> representation of the key.
71      * Only used from L10NKeySet to construct keys.
72      * @param theKey
73      */

74     public String JavaDoc toString()
75     {
76         return key;
77     }
78
79     /**
80      * Constructs a L10NKey instance using the specified key.
81      * Only used internaly from ScarabLocalizationTool.
82      * @param theKey the final <code>String<code> representation of the key
83      */

84     public L10NKey(String JavaDoc theKey)
85     {
86         key = theKey;
87     }
88
89     /*
90      * Return the string representation of this key for the DEFAULT_LOCALE
91      * @see org.tigris.scarab.tools.localization.Localizable#getMessage()
92      */

93     public String JavaDoc getMessage()
94     {
95         ScarabLocalizationTool l10n = new ScarabLocalizationTool();
96         l10n.init(ScarabLocalizationTool.DEFAULT_LOCALE);
97         return getMessage(l10n);
98     }
99
100     /*
101      * Return the string representation of this key for the goven locale.
102      * @see org.tigris.scarab.tools.localization.Localizable#getMessage(org.tigris.scarab.tools.ScarabLocalizationTool)
103      */

104     public String JavaDoc getMessage(ScarabLocalizationTool l10n)
105     {
106         return l10n.get(this);
107     }
108
109 }
110
Popular Tags