001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
005: * (C) 2001, Institut de Recherche pour le Développement
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: package org.geotools.resources.i18n;
018:
019: // J2SE dependencies
020: import java.util.Locale;
021: import java.util.MissingResourceException;
022:
023: // OpenGIS dependencies
024: import org.opengis.util.InternationalString;
025:
026: // Geotools dependencies
027: import org.geotools.resources.ResourceBundle;
028: import org.geotools.util.ResourceInternationalString;
029:
030: /**
031: * Base class for locale-dependent resources. Instances of this class should
032: * never been created directly. Use the factory method {@link #getResources}
033: * or use static convenience methods instead.
034: *
035: * @since 2.2
036: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/main/java/org/geotools/resources/i18n/Vocabulary.java $
037: * @version $Id: Vocabulary.java 22482 2006-10-31 02:58:00Z desruisseaux $
038: * @author Martin Desruisseaux
039: */
040: public class Vocabulary extends ResourceBundle {
041: /**
042: * Returns resources in the given locale.
043: *
044: * @param locale The locale, or {@code null} for the default locale.
045: * @return Resources in the given locale.
046: * @throws MissingResourceException if resources can't be found.
047: */
048: public static Vocabulary getResources(Locale locale)
049: throws MissingResourceException {
050: if (locale == null) {
051: locale = Locale.getDefault();
052: }
053: return (Vocabulary) getBundle(Vocabulary.class.getName(),
054: locale);
055: /*
056: * We rely on cache capability of ResourceBundle.
057: */
058: }
059:
060: /**
061: * Gets an international string for the given key. This method does not check for the key
062: * validity. If the key is invalid, then a {@link MissingResourceException} may be thrown
063: * when a {@link InternationalString#toString} method is invoked.
064: *
065: * @param key The key for the desired string.
066: * @return An international string for the given key.
067: */
068: public static InternationalString formatInternational(final int key) {
069: return new ResourceInternationalString(Vocabulary.class
070: .getName(), String.valueOf(key));
071: }
072:
073: /**
074: * Gets an international string for the given key. This method does not check for the key
075: * validity. If the key is invalid, then a {@link MissingResourceException} may be thrown
076: * when a {@link InternationalString#toString} method is invoked.
077: *
078: * @param key The key for the desired string.
079: * @param arg0 Value to substitute to "{0}".
080: * @return An international string for the given key.
081: *
082: * @todo Current implementation just invokes {@link #format}. Need to format only when
083: * {@code toString(Locale)} is invoked.
084: */
085: public static InternationalString formatInternational(
086: final int key, final Object arg0) {
087: return new org.geotools.util.SimpleInternationalString(format(
088: key, arg0));
089: }
090:
091: /**
092: * Gets an international string for the given key. This method does not check for the key
093: * validity. If the key is invalid, then a {@link MissingResourceException} may be thrown
094: * when a {@link InternationalString#toString} method is invoked.
095: *
096: * @param key The key for the desired string.
097: * @param arg0 Value to substitute to "{0}".
098: * @param arg1 Value to substitute to "{1}".
099: * @return An international string for the given key.
100: *
101: * @todo Current implementation just invokes {@link #format}. Need to format only when
102: * {@code toString(Locale)} is invoked.
103: */
104: public static InternationalString formatInternational(
105: final int key, final Object arg0, final Object arg1) {
106: return new org.geotools.util.SimpleInternationalString(format(
107: key, arg0, arg1));
108: }
109:
110: /**
111: * Gets an international string for the given key. This method does not check for the key
112: * validity. If the key is invalid, then a {@link MissingResourceException} may be thrown
113: * when a {@link InternationalString#toString} method is invoked.
114: *
115: * @param key The key for the desired string.
116: * @param arg0 Value to substitute to "{0}".
117: * @param arg1 Value to substitute to "{1}".
118: * @param arg2 Value to substitute to "{2}".
119: * @return An international string for the given key.
120: *
121: * @todo Current implementation just invokes {@link #format}. Need to format only when
122: * {@code toString(Locale)} is invoked.
123: */
124: public static InternationalString formatInternational(
125: final int key, final Object arg0, final Object arg1,
126: final Object arg2) {
127: return new org.geotools.util.SimpleInternationalString(format(
128: key, arg0, arg1, arg2));
129: }
130:
131: /**
132: * Gets a string for the given key from this resource bundle or one of its parents.
133: *
134: * @param key The key for the desired string.
135: * @return The string for the given key.
136: * @throws MissingResourceException If no object for the given key can be found.
137: */
138: public static String format(final int key)
139: throws MissingResourceException {
140: return getResources(null).getString(key);
141: }
142:
143: /**
144: * Gets a string for the given key are replace all occurence of "{0}"
145: * with values of {@code arg0}.
146: *
147: * @param key The key for the desired string.
148: * @param arg0 Value to substitute to "{0}".
149: * @return The formatted string for the given key.
150: * @throws MissingResourceException If no object for the given key can be found.
151: */
152: public static String format(final int key, final Object arg0)
153: throws MissingResourceException {
154: return getResources(null).getString(key, arg0);
155: }
156:
157: /**
158: * Gets a string for the given key are replace all occurence of "{0}",
159: * "{1}", with values of {@code arg0}, {@code arg1}.
160: *
161: * @param key The key for the desired string.
162: * @param arg0 Value to substitute to "{0}".
163: * @param arg1 Value to substitute to "{1}".
164: * @return The formatted string for the given key.
165: * @throws MissingResourceException If no object for the given key can be found.
166: */
167: public static String format(final int key, final Object arg0,
168: final Object arg1) throws MissingResourceException {
169: return getResources(null).getString(key, arg0, arg1);
170: }
171:
172: /**
173: * Gets a string for the given key are replace all occurence of "{0}",
174: * "{1}", with values of {@code arg0}, {@code arg1}, etc.
175: *
176: * @param key The key for the desired string.
177: * @param arg0 Value to substitute to "{0}".
178: * @param arg1 Value to substitute to "{1}".
179: * @param arg2 Value to substitute to "{2}".
180: * @return The formatted string for the given key.
181: * @throws MissingResourceException If no object for the given key can be found.
182: */
183: public static String format(final int key, final Object arg0,
184: final Object arg1, final Object arg2)
185: throws MissingResourceException {
186: return getResources(null).getString(key, arg0, arg1, arg2);
187: }
188: }
|