dlr 01/09/14 13:25:27
Modified: src/tool/org/apache/turbine/tool LocalizationTool.java
Log:
Revamped sub-classing hooks.
Revision Changes Path
1.4 +21 -17
jakarta-turbine-3/src/tool/org/apache/turbine/tool/LocalizationTool.java
Index: LocalizationTool.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-3/src/tool/org/apache/turbine/tool/LocalizationTool.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -u -r1.3 -r1.4
--- LocalizationTool.java 2001/09/07 19:26:28 1.3
+++ LocalizationTool.java 2001/09/14 20:25:27 1.4
@@ -83,29 +83,16 @@
private ResourceBundle bundle;
/**
- * The default bundle for this tool.
+ * The name of the bundle for this tool to use.
*/
- private String defaultBundleName;
+ private String bundleName;
/**
* Creates a new instance. Used by <code>PullService</code>.
*/
public LocalizationTool()
{
- this(Localization.getDefaultBundle());
- }
-
- /**
- * Hook for using a different default bundle than specified in
- * configuration file. Call this ctor in your sub-class's no-args
- * constructor with your desired default bundle name.
- *
- * @param defaultBundleName The name of the bundle to use.
- */
- protected LocalizationTool(String defaultBundleName)
- {
refresh();
- this.defaultBundleName = defaultBundleName;
}
/**
@@ -125,11 +112,26 @@
{
if (bundle == null)
{
- bundle = Localization.getBundle(defaultBundleName, req);
+ // Cache bundle for use during current request.
+ bundle = Localization.getBundle(bundleName, req);
}
return bundle.getString(key);
}
+ /**
+ * The return value of this method is used to set the name of the
+ * bundle used by this tool. Useful as a hook for using a
+ * different bundle than specifed in your
+ * <code>LocalizationService</code> configuration.
+ *
+ * @param data The inputs passed from {@link #init(Object)}.
+ * (ignored by this implementation).
+ */
+ protected String getBundleName(Object data)
+ {
+ return Localization.getDefaultBundle();
+ }
+
// ApplicationTool implmentation
@@ -137,11 +139,12 @@
* Sets the request to get the <code>Accept-Language</code> header
* from.
*/
- public void init(Object data)
+ public final void init(Object data)
{
if (data instanceof RunData)
{
this.req = ((RunData) data).getRequest();
+ bundleName = getBundleName(data);
}
}
@@ -152,5 +155,6 @@
{
req = null;
bundle = null;
+ bundleName = null;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]