01: /* Copyright 2005 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05: package org.jasig.portal.channels.adminnav;
06:
07: import java.util.Locale;
08: import java.util.ResourceBundle;
09:
10: import org.apache.commons.logging.Log;
11: import org.apache.commons.logging.LogFactory;
12: import org.jasig.portal.car.CarResources;
13:
14: /**
15: * Provides an implementation of ILabelResolver that resolves labels from
16: * ResourceBundles. A classpath located, base resource bundle property file name
17: * like "/properties/adminNav" is passed in to the constructor. Based on the
18: * user's locale, files with that name plus locale identifiers plus
19: * ".properties" will be looked for for resolving lable names. For example, if a
20: * call to getLabel passed a locale object for "de_DE" then the resource bundle
21: * searched for would be "/properties/adminNav_de_DE.properties" followed by
22: * "/properties/adminNav_de.properties" followed by
23: * "/properties/adminNav.properties".
24: *
25: * @author mboyd@sungardsct.com
26: */
27: public class ResourceBundleResolver implements ILabelResolver {
28: private static Log LOG = LogFactory.getLog(AdminNavChannel.class);
29: private String bundleBase = null;
30:
31: public ResourceBundleResolver(String bundleBase) {
32: this .bundleBase = bundleBase;
33: }
34:
35: public String getLabel(String labelId, Locale locale) {
36: if (locale == null || labelId == null)
37: return null;
38:
39: ResourceBundle rb = null;
40: rb = ResourceBundle.getBundle(bundleBase, locale, CarResources
41: .getInstance().getClassLoader());
42: return rb.getString(labelId);
43: }
44:
45: /**
46: * Return the bundle base used for this resolver.
47: *
48: * @see org.jasig.portal.channels.adminnav.ILabelResolver#getExternalForm()
49: */
50: public String getExternalForm() {
51: return "bundleBase=" + bundleBase;
52: }
53: }
|