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 lu...@apache.org on 2002/01/09 20:51:47 UTC
cvs commit: jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/rt/fmt FormatDateTag.java ParseDateTag.java
luehe 02/01/09 11:51:47
Modified: standard/src/org/apache/taglibs/standard/resources
Resources.properties
standard/src/org/apache/taglibs/standard/tag/common/fmt
FormatDateSupport.java LocaleSupport.java
ParseDateSupport.java
standard/src/org/apache/taglibs/standard/tag/el/fmt
FormatDateTag.java ParseDateTag.java
standard/src/org/apache/taglibs/standard/tag/rt/fmt
FormatDateTag.java ParseDateTag.java
Log:
Support both java.lang.String and java.util.TimeZone for the 'timeZone' attribute in <fmt:formatDate> and <fmt:parseDate>
Revision Changes Path
1.7 +6 -0 jakarta-taglibs/standard/src/org/apache/taglibs/standard/resources/Resources.properties
Index: Resources.properties
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/resources/Resources.properties,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Resources.properties 4 Jan 2002 21:59:01 -0000 1.6
+++ Resources.properties 9 Jan 2002 19:51:47 -0000 1.7
@@ -107,6 +107,12 @@
PARSE_NUMBER_NO_VALUE=\
<parseNumber> must have "value" attribute or body
+FORMAT_DATE_BAD_TIMEZONE=\
+ In <formatDate>, "timeZone" must be an instance of java.lang.String or java.util.TimeZone
+
+PARSE_DATE_BAD_TIMEZONE=\
+ In <parseDate>, "timeZone" must be an instance of java.lang.String or java.util.TimeZone
+
PARSE_DATE_NO_VALUE=\
<parseDate> must have "value" attribute or body
1.6 +17 -5 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/FormatDateSupport.java
Index: FormatDateSupport.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/FormatDateSupport.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FormatDateSupport.java 12 Dec 2001 01:24:19 -0000 1.5
+++ FormatDateSupport.java 9 Jan 2002 19:51:47 -0000 1.6
@@ -99,7 +99,7 @@
protected Object value; // 'value' attribute
protected String pattern; // 'pattern' attribute
- protected TimeZone timeZone; // 'timeZone' attribute
+ protected Object timeZone; // 'timeZone' attribute
protected Locale parseLocale; // 'parseLocale' attribute
@@ -221,10 +221,22 @@
}
// Set time zone
- if (timeZone == null)
- timeZone = TimeZoneSupport.getTimeZone(pageContext, this);
- if (timeZone != null)
- formatter.setTimeZone(timeZone);
+ TimeZone tz = null;
+ if (timeZone != null) {
+ if (timeZone instanceof String) {
+ tz = TimeZone.getTimeZone((String) timeZone);
+ } else if (timeZone instanceof TimeZone) {
+ tz = (TimeZone) timeZone;
+ } else {
+ throw new JspTagException(
+ Resources.getMessage("FORMAT_DATE_BAD_TIMEZONE"));
+ }
+ } else {
+ tz = TimeZoneSupport.getTimeZone(pageContext, this);
+ }
+ if (tz != null) {
+ formatter.setTimeZone(tz);
+ }
String formatted = formatter.format(value);
if (var != null) {
1.7 +1 -1 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/LocaleSupport.java
Index: LocaleSupport.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/LocaleSupport.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- LocaleSupport.java 4 Jan 2002 00:29:21 -0000 1.6
+++ LocaleSupport.java 9 Jan 2002 19:51:47 -0000 1.7
@@ -309,7 +309,7 @@
String loc =
pageContext.getServletContext().getInitParameter(name);
if (loc != null) {
- ret = LocaleSupport.parseLocale(loc, null);
+ ret = parseLocale(loc, null);
}
}
1.6 +17 -5 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/ParseDateSupport.java
Index: ParseDateSupport.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/ParseDateSupport.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ParseDateSupport.java 18 Dec 2001 01:53:15 -0000 1.5
+++ ParseDateSupport.java 9 Jan 2002 19:51:47 -0000 1.6
@@ -77,7 +77,7 @@
protected String value; // 'value' attribute
protected String pattern; // 'pattern' attribute
- protected TimeZone timeZone; // 'timeZone' attribute
+ protected Object timeZone; // 'timeZone' attribute
protected Locale parseLocale; // 'parseLocale' attribute
@@ -184,10 +184,22 @@
}
// Set time zone
- if (timeZone == null)
- timeZone = TimeZoneSupport.getTimeZone(pageContext, this);
- if (timeZone != null)
- formatter.setTimeZone(timeZone);
+ TimeZone tz = null;
+ if (timeZone != null) {
+ if (timeZone instanceof String) {
+ tz = TimeZone.getTimeZone((String) timeZone);
+ } else if (timeZone instanceof TimeZone) {
+ tz = (TimeZone) timeZone;
+ } else {
+ throw new JspTagException(
+ Resources.getMessage("PARSE_DATE_BAD_TIMEZONE"));
+ }
+ } else {
+ tz = TimeZoneSupport.getTimeZone(pageContext, this);
+ }
+ if (tz != null) {
+ formatter.setTimeZone(tz);
+ }
// Parse date
Date parsed = null;
1.3 +2 -4 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/el/fmt/FormatDateTag.java
Index: FormatDateTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/el/fmt/FormatDateTag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FormatDateTag.java 3 Dec 2001 22:43:50 -0000 1.2
+++ FormatDateTag.java 9 Jan 2002 19:51:47 -0000 1.3
@@ -162,11 +162,9 @@
"formatDate", "pattern", pattern_, String.class, this,
pageContext);
- String tz = (String) ExpressionUtil.evalNotNull(
- "formatDate", "timeZone", timeZone_, String.class, this,
+ timeZone = ExpressionUtil.evalNotNull(
+ "formatDate", "timeZone", timeZone_, Object.class, this,
pageContext);
- if (tz != null)
- timeZone = TimeZone.getTimeZone(tz);
String pl = (String) ExpressionUtil.evalNotNull(
"formatDate", "parseLocale", parseLocale_, String.class, this,
1.4 +2 -4 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/el/fmt/ParseDateTag.java
Index: ParseDateTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/el/fmt/ParseDateTag.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ParseDateTag.java 3 Dec 2001 22:43:50 -0000 1.3
+++ ParseDateTag.java 9 Jan 2002 19:51:47 -0000 1.4
@@ -162,11 +162,9 @@
"parseDate", "pattern", pattern_, String.class, this,
pageContext);
- String tz = (String) ExpressionUtil.evalNotNull(
- "parseDate", "timeZone", timeZone_, String.class, this,
+ timeZone = ExpressionUtil.evalNotNull(
+ "parseDate", "timeZone", timeZone_, Object.class, this,
pageContext);
- if (tz != null)
- timeZone = TimeZone.getTimeZone(tz);
String pl = (String) ExpressionUtil.evalNotNull(
"parseDate", "parseLocale", parseLocale_, String.class, this,
1.3 +2 -2 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/rt/fmt/FormatDateTag.java
Index: FormatDateTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/rt/fmt/FormatDateTag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FormatDateTag.java 3 Dec 2001 22:43:50 -0000 1.2
+++ FormatDateTag.java 9 Jan 2002 19:51:47 -0000 1.3
@@ -83,8 +83,8 @@
}
// for tag attribute
- public void setTimeZone(String timeZone) throws JspTagException {
- this.timeZone = TimeZone.getTimeZone(timeZone);
+ public void setTimeZone(Object timeZone) throws JspTagException {
+ this.timeZone = timeZone;
}
// for tag attribute
1.4 +2 -2 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/rt/fmt/ParseDateTag.java
Index: ParseDateTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/rt/fmt/ParseDateTag.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ParseDateTag.java 3 Dec 2001 22:43:50 -0000 1.3
+++ ParseDateTag.java 9 Jan 2002 19:51:47 -0000 1.4
@@ -83,8 +83,8 @@
}
// for tag attribute
- public void setTimeZone(String timeZone) throws JspTagException {
- this.timeZone = TimeZone.getTimeZone(timeZone);
+ public void setTimeZone(Object timeZone) throws JspTagException {
+ this.timeZone = timeZone;
}
// for tag attribute
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>