01: /**
02: * $Id: Resources.java,v 1.2 2006/04/17 20:08:41 jtb Exp $
03: * Copyright 2003 Sun Microsystems, Inc. All
04: * rights reserved. Use of this product is subject
05: * to license terms. Federal Acquisitions:
06: * Commercial Software -- Government Users
07: * Subject to Standard License Terms and
08: * Conditions.
09: *
10: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
11: * are trademarks or registered trademarks of Sun Microsystems,
12: * Inc. in the United States and other countries.
13: */package com.sun.portal.rssportlet;
14:
15: import java.util.Locale;
16: import java.util.MissingResourceException;
17: import java.util.ResourceBundle;
18:
19: /**
20: * This class is a wrapper around the Java <code>ResourceBundle</code>
21: * mechanism. It catches the missing resource exception that would
22: * normally result from a missing resource and instead returns the
23: * string key.This allows the application to function with a missing
24: * resource string, but still allows the problem to be identified.
25: *
26: * This class does not catch the missing resource exception that results
27: * from a non-existent reosurce bundle.
28: */
29: public class Resources {
30: private ResourceBundle rb;
31:
32: /**
33: * Construct a new Resources object.
34: *
35: * @throws MissingResourceException if the named bundle
36: * is not found.
37: */
38: public Resources(String bundleName, Locale locale) {
39: init(bundleName, locale);
40: }
41:
42: private void init(String bundleName, Locale locale) {
43: rb = ResourceBundle.getBundle(bundleName, locale);
44: }
45:
46: /**
47: * Get a resource string from this resource object.
48: * If the resource string identified by the key argument
49: * is not found, the key itself is returned.
50: */
51: public String get(String key) {
52: try {
53: return rb.getString(key);
54: } catch (MissingResourceException mre) {
55: return key;
56: }
57: }
58: }
|