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/Errors.java $
033: * @version $Id: Errors.java 22443 2006-10-27 20:47:22Z desruisseaux $
034: * @author Martin Desruisseaux
035: */
036: public class Errors 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 Errors getResources(Locale locale)
045: throws MissingResourceException {
046: if (locale == null) {
047: locale = Locale.getDefault();
048: }
049: return (Errors) getBundle(Errors.class.getName(), locale);
050: /*
051: * We rely on cache capability of ResourceBundle.
052: */
053: }
054:
055: /**
056: * Gets a string for the given key from this resource bundle or one of its parents.
057: *
058: * @param key The key for the desired string.
059: * @return The string for the given key.
060: * @throws MissingResourceException If no object for the given key can be found.
061: */
062: public static String format(final int key)
063: throws MissingResourceException {
064: return getResources(null).getString(key);
065: }
066:
067: /**
068: * Gets a string for the given key are replace all occurence of "{0}"
069: * with values of {@code arg0}.
070: *
071: * @param key The key for the desired string.
072: * @param arg0 Value to substitute to "{0}".
073: * @return The formatted string for the given key.
074: * @throws MissingResourceException If no object for the given key can be found.
075: */
076: public static String format(final int key, final Object arg0)
077: throws MissingResourceException {
078: return getResources(null).getString(key, arg0);
079: }
080:
081: /**
082: * Gets a string for the given key are replace all occurence of "{0}",
083: * "{1}", with values of {@code arg0}, {@code arg1}.
084: *
085: * @param key The key for the desired string.
086: * @param arg0 Value to substitute to "{0}".
087: * @param arg1 Value to substitute to "{1}".
088: * @return The formatted string for the given key.
089: * @throws MissingResourceException If no object for the given key can be found.
090: */
091: public static String format(final int key, final Object arg0,
092: final Object arg1) throws MissingResourceException {
093: return getResources(null).getString(key, arg0, arg1);
094: }
095:
096: /**
097: * Gets a string for the given key are replace all occurence of "{0}",
098: * "{1}", with values of {@code arg0}, {@code arg1}, etc.
099: *
100: * @param key The key for the desired string.
101: * @param arg0 Value to substitute to "{0}".
102: * @param arg1 Value to substitute to "{1}".
103: * @param arg2 Value to substitute to "{2}".
104: * @return The formatted string for the given key.
105: * @throws MissingResourceException If no object for the given key can be found.
106: */
107: public static String format(final int key, final Object arg0,
108: final Object arg1, final Object arg2)
109: throws MissingResourceException {
110: return getResources(null).getString(key, arg0, arg1, arg2);
111: }
112:
113: /**
114: * Gets a string for the given key are replace all occurence of "{0}",
115: * "{1}", with values of {@code arg0}, {@code arg1}, etc.
116: *
117: * @param key The key for the desired string.
118: * @param arg0 Value to substitute to "{0}".
119: * @param arg1 Value to substitute to "{1}".
120: * @param arg2 Value to substitute to "{2}".
121: * @param arg3 Value to substitute to "{3}".
122: * @return The formatted string for the given key.
123: * @throws MissingResourceException If no object for the given key can be found.
124: */
125: public static String format(final int key, final Object arg0,
126: final Object arg1, final Object arg2, final Object arg3)
127: throws MissingResourceException {
128: return getResources(null)
129: .getString(key, arg0, arg1, arg2, arg3);
130: }
131: }
|