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: // Geotools dependencies
024: import org.geotools.resources.ResourceBundle;
025:
026: /**
027: * Base class for locale-dependent resources. Instances of this class should
028: * never been created directly. Use the factory method {@link #getResources}
029: * or use static convenience methods instead.
030: *
031: * @since 2.2
032: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/main/java/org/geotools/resources/i18n/Descriptions.java $
033: * @version $Id: Descriptions.java 22443 2006-10-27 20:47:22Z desruisseaux $
034: * @author Martin Desruisseaux
035: */
036: public class Descriptions extends ResourceBundle {
037: /**
038: * Returns resources in the given locale.
039: *
040: * @param locale The locale, or {@code null} for the default locale.
041: * @return Resources in the given locale.
042: * @throws MissingResourceException if resources can't be found.
043: */
044: public static Descriptions getResources(Locale locale)
045: throws MissingResourceException {
046: if (locale == null) {
047: locale = Locale.getDefault();
048: }
049: return (Descriptions) getBundle(Descriptions.class.getName(),
050: locale);
051: /*
052: * We rely on cache capability of ResourceBundle.
053: */
054: }
055:
056: /**
057: * Gets a string for the given key from this resource bundle or one of its parents.
058: *
059: * @param key The key for the desired string.
060: * @return The string for the given key.
061: * @throws MissingResourceException If no object for the given key can be found.
062: */
063: public static String format(final int key)
064: throws MissingResourceException {
065: return getResources(null).getString(key);
066: }
067:
068: /**
069: * Gets a string for the given key are replace all occurence of "{0}"
070: * with values of {@code arg0}.
071: *
072: * @param key The key for the desired string.
073: * @param arg0 Value to substitute to "{0}".
074: * @return The formatted string for the given key.
075: * @throws MissingResourceException If no object for the given key can be found.
076: */
077: public static String format(final int key, final Object arg0)
078: throws MissingResourceException {
079: return getResources(null).getString(key, arg0);
080: }
081:
082: /**
083: * Gets a string for the given key are replace all occurence of "{0}",
084: * "{1}", with values of {@code arg0}, {@code arg1}.
085: *
086: * @param key The key for the desired string.
087: * @param arg0 Value to substitute to "{0}".
088: * @param arg1 Value to substitute to "{1}".
089: * @return The formatted string for the given key.
090: * @throws MissingResourceException If no object for the given key can be found.
091: */
092: public static String format(final int key, final Object arg0,
093: final Object arg1) throws MissingResourceException {
094: return getResources(null).getString(key, arg0, arg1);
095: }
096:
097: /**
098: * Gets a string for the given key are replace all occurence of "{0}",
099: * "{1}", with values of {@code arg0}, {@code arg1}, etc.
100: *
101: * @param key The key for the desired string.
102: * @param arg0 Value to substitute to "{0}".
103: * @param arg1 Value to substitute to "{1}".
104: * @param arg2 Value to substitute to "{2}".
105: * @return The formatted string for the given key.
106: * @throws MissingResourceException If no object for the given key can be found.
107: */
108: public static String format(final int key, final Object arg0,
109: final Object arg1, final Object arg2)
110: throws MissingResourceException {
111: return getResources(null).getString(key, arg0, arg1, arg2);
112: }
113: }
|