diff options
author | kstranacher <kstranacher@d688527b-c9ab-4aba-bd8d-4036d912da1d> | 2012-02-20 11:21:24 +0000 |
---|---|---|
committer | kstranacher <kstranacher@d688527b-c9ab-4aba-bd8d-4036d912da1d> | 2012-02-20 11:21:24 +0000 |
commit | d3352bc9db1891c8f90f8c542eac65da64a234d3 (patch) | |
tree | f7b7c932e39e201d22ef5232bf90081c2d357885 /common/src/main/java/at/gv/egovernment/moa/util/ResourceBundleChain.java | |
parent | 9b1af165432c82d64f49d3e3730534b224230b53 (diff) | |
parent | b858a62942137068394790a22c10b968e1c41e0f (diff) | |
download | moa-id-spss-d3352bc9db1891c8f90f8c542eac65da64a234d3.tar.gz moa-id-spss-d3352bc9db1891c8f90f8c542eac65da64a234d3.tar.bz2 moa-id-spss-d3352bc9db1891c8f90f8c542eac65da64a234d3.zip |
MOA-IDSPSS Release 1.5.1.tags/1.5.1
git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/tags/1.5.1@1271 d688527b-c9ab-4aba-bd8d-4036d912da1d
Diffstat (limited to 'common/src/main/java/at/gv/egovernment/moa/util/ResourceBundleChain.java')
-rw-r--r-- | common/src/main/java/at/gv/egovernment/moa/util/ResourceBundleChain.java | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/common/src/main/java/at/gv/egovernment/moa/util/ResourceBundleChain.java b/common/src/main/java/at/gv/egovernment/moa/util/ResourceBundleChain.java new file mode 100644 index 000000000..234ed89df --- /dev/null +++ b/common/src/main/java/at/gv/egovernment/moa/util/ResourceBundleChain.java @@ -0,0 +1,90 @@ +/* + * Copyright 2003 Federal Chancellery Austria + * MOA-ID has been developed in a cooperation between BRZ, the Federal + * Chancellery Austria - ICT staff unit, and Graz University of Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ + + +package at.gv.egovernment.moa.util; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** + * A class to chain <code>ResourceBundle</code>s. + * + * @author Patrick Peck + * @version $Id$ + */ +public class ResourceBundleChain { + /** Error message indicating the resource is not available. */ + private static final String ERROR_MISSING_RESOURCE = "Missing resource"; + /** The <code>ResourceBundle</code>s contained in this chain. */ + private List resourceBundles = new ArrayList(); + + /** + * Add a <code>ResourceBundle</code> to the chain. + * + * @param resourceBundle The <code>ResourceBundle</code> to add. + */ + public void addResourceBundle(ResourceBundle resourceBundle) { + resourceBundles.add(resourceBundle); + } + + /** + * Return the value of the resource. + * + * @param key The key to access the <code>String</code> resource. + * @return The resource value. All the registered <code>ResourceBundle</code>s + * are searched in the order in which they have previously been added to this + * <code>ResourceBundleChain</code>. + * @throws MissingResourceException The resource coult not be found in any of + * the bundles. + */ + public String getString(String key) throws MissingResourceException { + MissingResourceException lastException = null; + Iterator iter; + + // handle case where no resource bundles have been added + if (resourceBundles.size() == 0) { + throw new MissingResourceException( + ERROR_MISSING_RESOURCE, + this.getClass().getName(), + key); + } + + // try to find the resource in one of the bundles; if it cannot be found, + // return the exception thrown by the last bundle in the list + for (iter = resourceBundles.iterator(); iter.hasNext();) { + ResourceBundle resourceBundle = (ResourceBundle) iter.next(); + try { + String value = resourceBundle.getString(key); + return value; + } catch (MissingResourceException e) { + lastException = e; + } + } + throw lastException; + } + +} |