You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2001/12/29 23:08:41 UTC
cvs commit: jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/i18n Resources.java
donaldp 01/12/29 14:08:41
Modified: src/java/org/apache/avalon/excalibur/i18n Resources.java
Log:
Add extra constructors that take a ClassLoader. If provided this will be used to load resources otherwise the old mechanism will be used.
Revision Changes Path
1.11 +46 -13 jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/i18n/Resources.java
Index: Resources.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/i18n/Resources.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Resources.java 11 Dec 2001 09:53:28 -0000 1.10
+++ Resources.java 29 Dec 2001 22:08:41 -0000 1.11
@@ -17,7 +17,7 @@
import java.util.Date;
/**
- * A class to simplify extracting localized strings, icons
+ * A class to simplify extracting localized strings, icons
* and other common resources from a ResourceBundle.
*
* Reworked to mirror behaviour of StringManager from Tomcat (format() to getString()).
@@ -37,6 +37,9 @@
///Base name of resource bundle
private String m_baseName;
+ ///ClassLoader from which to load resources
+ private ClassLoader m_classLoader;
+
/**
* Constructor that builds a manager in default locale.
*
@@ -44,7 +47,19 @@
*/
public Resources( final String baseName )
{
- this( baseName, Locale.getDefault() );
+ this( baseName, Locale.getDefault(), null );
+ }
+
+ /**
+ * Constructor that builds a manager in default locale
+ * using specified ClassLoader.
+ *
+ * @param baseName the base name of ResourceBundle
+ * @param classLoader the classLoader to load ResourceBundle from
+ */
+ public Resources( final String baseName, final ClassLoader classLoader )
+ {
+ this( baseName, Locale.getDefault(), classLoader );
}
/**
@@ -55,8 +70,23 @@
*/
public Resources( final String baseName, final Locale locale )
{
+ this( baseName, locale, null );
+ }
+
+ /**
+ * Constructor that builds a manager in specified locale.
+ *
+ * @param baseName the base name of ResourceBundle
+ * @param locale the Locale for resource bundle
+ * @param classLoader the classLoader to load ResourceBundle from
+ */
+ public Resources( final String baseName,
+ final Locale locale,
+ final ClassLoader classLoader )
+ {
m_baseName = baseName;
m_locale = locale;
+ m_classLoader = classLoader;
if( null == baseName )
{
@@ -69,7 +99,6 @@
}
}
-
/**
* Retrieve a boolean from bundle.
*
@@ -439,7 +468,7 @@
final String value = bundle.getString( key );
try
{
- final DateFormat format =
+ final DateFormat format =
DateFormat.getDateInstance( DateFormat.DEFAULT, m_locale );
return format.parse( value );
}
@@ -484,7 +513,7 @@
final String value = bundle.getString( key );
try
{
- final DateFormat format =
+ final DateFormat format =
DateFormat.getTimeInstance( DateFormat.DEFAULT, m_locale );
return format.parse( value );
}
@@ -529,7 +558,7 @@
final String value = bundle.getString( key );
try
{
- final DateFormat format =
+ final DateFormat format =
DateFormat.getDateTimeInstance( DateFormat.DEFAULT, DateFormat.DEFAULT, m_locale );
return format.parse( value );
}
@@ -590,9 +619,9 @@
* @param arg3 an arg
* @return the formatted string
*/
- public String getString( final String key,
- final Object arg1,
- final Object arg2,
+ public String getString( final String key,
+ final Object arg1,
+ final Object arg2,
final Object arg3 )
{
final Object[] args = new Object[] { arg1, arg2, arg3 };
@@ -609,9 +638,9 @@
* @param arg4 an arg
* @return the formatted string
*/
- public String getString( final String key,
- final Object arg1,
- final Object arg2,
+ public String getString( final String key,
+ final Object arg1,
+ final Object arg2,
final Object arg3,
final Object arg4 )
{
@@ -692,7 +721,11 @@
if( null == m_bundle )
{
// bundle wasn't cached, so load it, cache it, and return it.
- final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader classLoader = m_classLoader;
+ if( null == classLoader )
+ {
+ classLoader = Thread.currentThread().getContextClassLoader();
+ }
if( null != classLoader )
{
m_bundle = ResourceBundle.getBundle( m_baseName, m_locale, classLoader );
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>