001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/model/csct/units/resources/Resources.java $ 002 /* 003 * SEAGIS - An OpenSource implementation of OpenGIS specification 004 * (C) 2002, Institut de Recherche pour le D�veloppement 005 * 006 * This library is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2.1 of the License, or (at your option) any later version. 010 * 011 * This library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software 018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 019 * 020 * 021 * Contacts: 022 * FRANCE: Surveillance de l'Environnement Assist�e par Satellite 023 * Institut de Recherche pour le D�veloppement / US-Espace 024 * mailto:seasnet@teledetection.fr 025 * 026 * CANADA: Observatoire du Saint-Laurent 027 * Institut Maurice-Lamontagne 028 * mailto:osl@osl.gc.ca 029 */ 030 package org.deegree.model.csct.units.resources; 031 032 // Miscellaneous 033 import java.util.Locale; 034 import java.util.MissingResourceException; 035 036 import org.deegree.model.csct.resources.ResourceBundle; 037 038 039 /** 040 * Base class for local-dependent resources. Instances of this class should 041 * never been created directly. Use the factory method {@link #getResources} 042 * or use static methods instead. 043 * 044 * @version 1.0 045 * @author Martin Desruisseaux 046 */ 047 public class Resources extends ResourceBundle 048 { 049 /** 050 * Construct a resource bundle using english language. 051 * This is the default when no resource are available 052 * in user language. 053 */ 054 public Resources() 055 { 056 super(// Set 'true' in front of language to use as default. 057 false ? Resources_fr.FILEPATH : 058 true ? Resources_en.FILEPATH : 059 null); 060 } 061 062 /** 063 * Construct a resource bundle 064 * using the specified UTF8 file. 065 */ 066 Resources(final String filepath) 067 {super(filepath);} 068 069 /** 070 * Returns the name of the logger to use, 071 * which is <code>javax.units</code>. 072 */ 073 protected String getLoggerName() 074 {return "javax.units";} 075 076 /** 077 * Returns resources in the given locale. 078 * 079 * @param locale The locale, or <code>null</code> for the default locale. 080 * @return Resources in the given locale. 081 * @throws MissingResourceException if resources can't be found. 082 */ 083 public static Resources getResources(Locale locale) throws MissingResourceException 084 { 085 if (locale==null) locale = Locale.getDefault(); 086 return (Resources) getBundle(Resources.class.getName(), locale); 087 /* 088 * We rely on cache capability of {@link java.util.ResourceBundle}. 089 */ 090 } 091 092 /** 093 * Gets a string for the given key from this resource bundle or one of its parents. 094 * 095 * @param key The key for the desired string. 096 * @return The string for the given key. 097 * @throws MissingResourceException If no object for the given key can be found. 098 */ 099 public static String format(final int key) throws MissingResourceException 100 {return getResources(null).getString(key);} 101 102 /** 103 * Gets a string for the given key are replace all occurence of "{0}" 104 * with values of <code>arg0</code>. 105 * 106 * @param key The key for the desired string. 107 * @param arg0 Value to substitute to "{0}". 108 * @return The formatted string for the given key. 109 * @throws MissingResourceException If no object for the given key can be found. 110 */ 111 public static String format(final int key, final Object arg0) throws MissingResourceException 112 {return getResources(null).getString(key, arg0);} 113 114 /** 115 * Gets a string for the given key are replace all occurence of "{0}", 116 * "{1}", with values of <code>arg0</code>, <code>arg1</code>. 117 * 118 * @param key The key for the desired string. 119 * @param arg0 Value to substitute to "{0}". 120 * @param arg1 Value to substitute to "{1}". 121 * @return The formatted string for the given key. 122 * @throws MissingResourceException If no object for the given key can be found. 123 */ 124 public static String format(final int key, final Object arg0, final Object arg1) throws MissingResourceException 125 {return getResources(null).getString(key, arg0, arg1);} 126 }