From 43e57a42832ea8b4ceb0317f3c9028a4174ffa7b Mon Sep 17 00:00:00 2001 From: mcentner Date: Wed, 8 Aug 2007 07:25:32 +0000 Subject: Adapted project directory structure to suit the new maven based build process. git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@909 d688527b-c9ab-4aba-bd8d-4036d912da1d --- .../egovernment/moa/util/ResourceBundleChain.java | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 common/src/main/java/at/gv/egovernment/moa/util/ResourceBundleChain.java (limited to 'common/src/main/java/at/gv/egovernment/moa/util/ResourceBundleChain.java') 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..90b28548a --- /dev/null +++ b/common/src/main/java/at/gv/egovernment/moa/util/ResourceBundleChain.java @@ -0,0 +1,66 @@ +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 ResourceBundles. + * + * @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 ResourceBundles contained in this chain. */ + private List resourceBundles = new ArrayList(); + + /** + * Add a ResourceBundle to the chain. + * + * @param resourceBundle The ResourceBundle to add. + */ + public void addResourceBundle(ResourceBundle resourceBundle) { + resourceBundles.add(resourceBundle); + } + + /** + * Return the value of the resource. + * + * @param key The key to access the String resource. + * @return The resource value. All the registered ResourceBundles + * are searched in the order in which they have previously been added to this + * ResourceBundleChain. + * @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; + } + +} -- cgit v1.2.3 From afcd856e186b9fd5d8dfcb0f3e6f3599ca920b51 Mon Sep 17 00:00:00 2001 From: mcentner Date: Thu, 28 Aug 2008 07:55:59 +0000 Subject: Added copyright and license header to all java source files. git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@1087 d688527b-c9ab-4aba-bd8d-4036d912da1d --- .../at/gv/egovernment/moa/util/ResourceBundleChain.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'common/src/main/java/at/gv/egovernment/moa/util/ResourceBundleChain.java') 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 index 90b28548a..609c873ff 100644 --- a/common/src/main/java/at/gv/egovernment/moa/util/ResourceBundleChain.java +++ b/common/src/main/java/at/gv/egovernment/moa/util/ResourceBundleChain.java @@ -1,3 +1,18 @@ +/* +* Copyright 2003 Federal Chancellery Austria +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ package at.gv.egovernment.moa.util; import java.util.ArrayList; -- cgit v1.2.3