01: /*
02: * Copyright 2006 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11: * the license for the specific language governing your rights and limitations.
12: *
13: * @created Jan 23, 2006
14: * @author James Dixon
15: */
16: package org.pentaho.plugin.jfreereport.helper;
17:
18: import java.io.File;
19: import java.util.Locale;
20: import java.util.ResourceBundle;
21: import org.jfree.report.ResourceBundleFactory;
22: import org.pentaho.core.session.IPentahoSession;
23: import org.pentaho.core.system.PentahoSystem;
24: import org.pentaho.messages.Messages;
25: import org.pentaho.messages.util.LocaleHelper;
26: import org.pentaho.util.logging.Logger;
27:
28: /**
29: * The resource-bundle factory is responsible for loading referenced resourcebundles. The default action is to load these bundles using the standard JDK methods. If no bundle-name is given, the default name for the xaction's assigned resource-bundle is used instead.
30: */
31: public class PentahoResourceBundleFactory implements
32: ResourceBundleFactory {
33: private static final long serialVersionUID = -1555502100120929073L;
34:
35: private String path;
36:
37: private String baseName;
38:
39: private ClassLoader loader;
40:
41: public PentahoResourceBundleFactory(final String inPath,
42: final String inBaseName, final IPentahoSession inSession) {
43: path = inPath;
44: baseName = inBaseName;
45: loader = PentahoSystem.getSolutionRepository(inSession)
46: .getClassLoader(path);
47: }
48:
49: public Locale getLocale() {
50: return LocaleHelper.getLocale();
51: }
52:
53: public ResourceBundle getResourceBundle(String resourceName) {
54: if (resourceName == null) {
55: resourceName = baseName;
56: }
57: try {
58: return ResourceBundle.getBundle(resourceName, getLocale(),
59: loader);
60: } catch (Exception e) {
61: Logger
62: .error(
63: getClass().getName(),
64: Messages
65: .getErrorString(
66: "JFreeReport.ERROR_0024_COULD_NOT_READ_PROPERTIES", path + File.separator + baseName), e); //$NON-NLS-1$
67: }
68: return null;
69: }
70: }
|