You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by td...@apache.org on 2002/01/19 08:43:52 UTC
cvs commit: jakarta-taglibs/i18n/src/org/apache/taglibs/i18n BundleTag.java
tdawson 02/01/18 23:43:52
Modified: i18n/src/org/apache/taglibs/i18n BundleTag.java
Log:
added scope attribute to bundle tag
fixed bug noted by Stephen Drye - in BundleTag's release() method, _debug should be set to false, not true (line 171).
fixed bug noted by Stephen Drye - There's a System.out.println on line 304 that isn't protected with a if (_debug)
fixed bug noted by Stephen Drye - the else clause on line 277 uses sc.log() without wrapping a if(_debug) around it
Revision Changes Path
1.6 +50 -13 jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/BundleTag.java
Index: BundleTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/BundleTag.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- BundleTag.java 18 Oct 2001 13:28:18 -0000 1.5
+++ BundleTag.java 19 Jan 2002 07:43:52 -0000 1.6
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/BundleTag.java,v 1.5 2001/10/18 13:28:18 tdawson Exp $
- * $Revision: 1.5 $
- * $Date: 2001/10/18 13:28:18 $
+ * $Header: /home/cvs/jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/BundleTag.java,v 1.6 2002/01/19 07:43:52 tdawson Exp $
+ * $Revision: 1.6 $
+ * $Date: 2002/01/19 07:43:52 $
*
* ====================================================================
*
@@ -97,12 +97,13 @@
*/
public class BundleTag extends TagSupport
{
- private String _baseName = null;
- private String _localeAttribute = null;
- private Locale _locale = null;
- private boolean _changeResponseLocale = true;
+ private String _baseName = null;
+ private String _localeAttribute = null;
+ private Locale _locale = null;
+ private boolean _changeResponseLocale = true;
private ResourceBundle _bundle = null;
- private boolean _debug = false;
+ private int _scope = PageContext.PAGE_SCOPE;
+ private boolean _debug = false;
/**
* Sets the baseName of the bundle that the MessageTags will use when
@@ -152,6 +153,38 @@
}
/**
+ * Sets the scope that the bundle will be available to message tags.
+ * By default page scope is used.
+ */
+ public void setScope(String value)
+ {
+ if (value == null)
+ {
+ throw new NullPointerException("setScope requires a non-null value");
+ }
+ else if (value.toLowerCase().equals("application"))
+ {
+ _scope = PageContext.APPLICATION_SCOPE;
+ }
+ else if (value.toLowerCase().equals("session"))
+ {
+ _scope = PageContext.SESSION_SCOPE;
+ }
+ else if (value.toLowerCase().equals("request"))
+ {
+ _scope = PageContext.REQUEST_SCOPE;
+ }
+ else if (value.toLowerCase().equals("page"))
+ {
+ _scope = PageContext.PAGE_SCOPE;
+ }
+ else
+ {
+ throw new RuntimeException("bundle tag received invalid scope");
+ }
+ }
+
+ /**
* Specifies whether or not the response locale should be changed to match
* the locale used by this tag.
*/
@@ -168,7 +201,8 @@
_locale = null;
_changeResponseLocale = true;
_bundle = null;
- _debug = true;
+ _scope = PageContext.PAGE_SCOPE;
+ _debug = false;
}
/**
@@ -274,7 +308,7 @@
continue;
}
}
- else
+ else if (_debug)
{
ServletContext sc = pageContext.getServletContext();
sc.log("i18n: requested locale not available: " + _locale);
@@ -301,7 +335,6 @@
{
HttpSession session = pageContext.getSession();
session.setAttribute(_localeAttribute,_bundle.getLocale());
- System.out.println("set locale " + _bundle.getLocale() + " for attribute " +_localeAttribute);
}
}
@@ -340,7 +373,11 @@
if (_changeResponseLocale)
{
// set the locale for the response
- pageContext.getResponse().setLocale(_bundle.getLocale());
+ Locale bundleLocale = _bundle.getLocale();
+ if ((bundleLocale != null) && !("".equals(bundleLocale.getLanguage())))
+ {
+ pageContext.getResponse().setLocale(bundleLocale);
+ }
}
// different handling is necessary if multiple bundle tags are in use
@@ -348,7 +385,7 @@
if (firstBundle == null)
{
// cache the bundle for use by message tags within this request
- ResourceHelper.setBundle(pageContext,_bundle);
+ ResourceHelper.setBundle(pageContext,_bundle,_scope);
}
return EVAL_PAGE;
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>