KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > plugin > jfreereport > helper > PentahoResourceBundleFactory


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * 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 JavaDoc;
19 import java.util.Locale JavaDoc;
20 import java.util.ResourceBundle JavaDoc;
21
22 import org.jfree.report.ResourceBundleFactory;
23 import org.pentaho.core.session.IPentahoSession;
24 import org.pentaho.core.system.PentahoSystem;
25 import org.pentaho.messages.Messages;
26 import org.pentaho.messages.util.LocaleHelper;
27 import org.pentaho.util.logging.Logger;
28
29 /**
30  * The resource-bundle factory is responsible for loading referenced
31  * resourcebundles. The default action is to load these bundles using
32  * the standard JDK methods.
33  *
34  * If no bundle-name is given, the default name for the xaction's assigned
35  * resource-bundle is used instead.
36  */

37 public class PentahoResourceBundleFactory implements ResourceBundleFactory
38 {
39
40   private static final long serialVersionUID = -1555502100120929073L;
41
42   private String JavaDoc path;
43
44   private String JavaDoc baseName;
45
46   private ClassLoader JavaDoc loader;
47
48   public PentahoResourceBundleFactory(String JavaDoc path,
49                                       String JavaDoc baseName,
50                                       IPentahoSession session)
51   {
52     this.path = path;
53     this.baseName = baseName;
54     loader = PentahoSystem.getSolutionRepository(session).getClassLoader(path);
55   }
56
57   public Locale JavaDoc getLocale()
58   {
59     return LocaleHelper.getLocale();
60   }
61
62   public ResourceBundle JavaDoc getResourceBundle(String JavaDoc resourceName)
63   {
64     if (resourceName == null)
65     {
66       resourceName = baseName;
67     }
68     
69     try
70     {
71       return ResourceBundle.getBundle(resourceName, getLocale(), loader);
72     }
73     catch (Exception JavaDoc e)
74     {
75       Logger.error(getClass().getName(), Messages.getErrorString("JFreeReport.ERROR_0024_COULD_NOT_READ_PROPERTIES", path + File.separator + baseName), e); //$NON-NLS-1$
76
}
77     return null;
78   }
79
80 }
81
Popular Tags