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 gl...@apache.org on 2001/07/13 16:56:22 UTC
cvs commit: jakarta-taglibs/datetime/src/org/apache/taglibs/datetime FormatTag.java ParseTag.java
glenn 01/07/13 07:56:19
Modified: datetime/xml datetime.xml
datetime/examples/web setzone.jsp
datetime/src/org/apache/taglibs/datetime FormatTag.java
ParseTag.java
Log:
Add patternId attribute to parse and format tags
Revision Changes Path
1.4 +38 -1 jakarta-taglibs/datetime/xml/datetime.xml
Index: datetime.xml
===================================================================
RCS file: /home/cvs/jakarta-taglibs/datetime/xml/datetime.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- datetime.xml 2001/07/13 00:32:13 1.3
+++ datetime.xml 2001/07/13 14:55:55 1.4
@@ -247,6 +247,22 @@
</attribute>
<attribute>
+ <name>patternId</name>
+ <required>no</required>
+ <rtexprvalue>no</rtexprvalue>
+ <!-- Used for JSP 1.2 TLD and generating HTML docs -->
+ <description>
+ Name of a script variable which contains a
+ <a href="#pattern">Date Time Pattern Format</a>
+ string to use for formatting the date.
+ </description>
+ <!-- Used for the HTML documentation only.
+ Version of taglib when this attribute became available,
+ deprecated is a possible value. -->
+ <availability>1.0</availability>
+ </attribute>
+
+ <attribute>
<name>timeZone</name>
<required>no</required>
<rtexprvalue>no</rtexprvalue>
@@ -374,6 +390,22 @@
</attribute>
<attribute>
+ <name>patternId</name>
+ <required>no</required>
+ <rtexprvalue>no</rtexprvalue>
+ <!-- Used for JSP 1.2 TLD and generating HTML docs -->
+ <description>
+ Name of a script variable which contains a
+ <a href="#pattern">Date Time Pattern Format</a>
+ string to use when parsing the date.
+ </description>
+ <!-- Used for the HTML documentation only.
+ Version of taglib when this attribute became available,
+ deprecated is a possible value. -->
+ <availability>1.0</availability>
+ </attribute>
+
+ <attribute>
<name>timeZone</name>
<required>no</required>
<rtexprvalue>no</rtexprvalue>
@@ -418,7 +450,8 @@
</comment>
<code>
<![CDATA[
-<dt:parse pattern="yyyy MM dd">2000 11 5</dt:parse>
+<req:setAttribute name="pattern"/>yyyy MM dd</req:setAttribute>
+<dt:parse patternId="pattern">2000 11 5</dt:parse>
]]>
</code>
</usage>
@@ -1068,6 +1101,10 @@
<item>
Changed the name of the <b>format</b> tag <b>timezone</b>
attribute to <b>timeZone</b>.
+ </item>
+ <item>
+ Added the <b>patternId</b> attribute to the <b>format</b>
+ and <b>parse</b> tags.
</item>
</section>
</revision>
1.3 +2 -1 jakarta-taglibs/datetime/examples/web/setzone.jsp
Index: setzone.jsp
===================================================================
RCS file: /home/cvs/jakarta-taglibs/datetime/examples/web/setzone.jsp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- setzone.jsp 2001/07/07 20:41:33 1.2
+++ setzone.jsp 2001/07/13 14:56:04 1.3
@@ -27,8 +27,9 @@
The current time at <req:parameter name="timezone"/> in a different format:
<dt:format timeZone="tz" pattern="yyyy.MM.dd G 'at' hh:mm:ss a zzz"><dt:currentTime/></dt:format><br><br>
+<req:setAttribute name="pattern">yyyy MM dd</req:setAttribute>
Parse the date you selected using the <b>parse</b> tag:<br><br>
-<dt:parse timeZone="tz" pattern="yyyy MM dd"><req:parameter name="year"/> <req:parameter name="month"/> <req:parameter name="day"/></dt:parse><br><br>
+<dt:parse timeZone="tz" patternId="pattern"><req:parameter name="year"/> <req:parameter name="month"/> <req:parameter name="day"/></dt:parse><br><br>
The date you selected was:
<dt:format timeZone="tz" pattern="MM/dd/yyyy"><dt:parse timeZone="tz" pattern="yyyy MM dd"><req:parameter name="year"/> <req:parameter name="month"/> <req:parameter name="day"/></dt:parse></dt:format><br><br>
</body>
1.7 +34 -9 jakarta-taglibs/datetime/src/org/apache/taglibs/datetime/FormatTag.java
Index: FormatTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/datetime/src/org/apache/taglibs/datetime/FormatTag.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- FormatTag.java 2001/07/08 02:31:57 1.6
+++ FormatTag.java 2001/07/13 14:56:10 1.7
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-taglibs/datetime/src/org/apache/taglibs/datetime/FormatTag.java,v 1.6 2001/07/08 02:31:57 glenn Exp $
- * $Revision: 1.6 $
- * $Date: 2001/07/08 02:31:57 $
+ * $Header: /home/cvs/jakarta-taglibs/datetime/src/org/apache/taglibs/datetime/FormatTag.java,v 1.7 2001/07/13 14:56:10 glenn Exp $
+ * $Revision: 1.7 $
+ * $Date: 2001/07/13 14:56:10 $
*
* ====================================================================
*
@@ -104,6 +104,11 @@
* <rtexprvalue>false</rtexprvalue>
* </attribute>
* <attribute>
+ * <name>patternId</name>
+ * <required>false</required>
+ * <rtexprvalue>false</rtexprvalue>
+ * </attribute>
+ * <attribute>
* <name>timeZone</name>
* <required>false</required>
* <rtexprvalue>false</rtexprvalue>
@@ -135,6 +140,8 @@
private boolean locale_flag = false;
// Optional attribute, time pattern string to use when formatting date
private String pattern = null;
+ // Optional attribute, name of script variable to use as pattern
+ private String patternid = null;
// Optional attribute, timeZone script variable id to use when formatting date
private String timeZone_string;
private TimeZone timeZone = null;
@@ -185,18 +192,26 @@
date = new Date(time);
}
- SimpleDateFormat sdf;
- // Get the default pattern if none defined
- if( pattern == null ) {
+ // Get the pattern to use
+ SimpleDateFormat sdf;
+ String pat = pattern;
+
+ if( pat == null && patternid != null ) {
+ Object attr = pageContext.findAttribute(patternid);
+ if( attr != null )
+ pat = attr.toString();
+ }
+
+ if( pat == null ) {
sdf = new SimpleDateFormat();
- pattern = sdf.toPattern();
+ pat = sdf.toPattern();
}
// Get a SimpleDateFormat using locale if necessary
if( !locale_flag )
- sdf = new SimpleDateFormat(pattern);
+ sdf = new SimpleDateFormat(pat);
else
- sdf = new SimpleDateFormat(pattern,
+ sdf = new SimpleDateFormat(pat,
(Locale)pageContext.getRequest().getLocale());
// See if there is a timeZone
@@ -266,6 +281,16 @@
pattern = str;
}
+ /**
+ * Set the pattern to use when parsing Date using a script variable
+ * attribute.
+ *
+ * @param String name of script variable attribute id
+ */
+ public final void setPatternId(String str)
+ {
+ patternid = str;
+ }
/**
* Set the date to use (overrides tag body) for formatting
1.5 +38 -11 jakarta-taglibs/datetime/src/org/apache/taglibs/datetime/ParseTag.java
Index: ParseTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/datetime/src/org/apache/taglibs/datetime/ParseTag.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ParseTag.java 2001/07/08 02:31:57 1.4
+++ ParseTag.java 2001/07/13 14:56:13 1.5
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-taglibs/datetime/src/org/apache/taglibs/datetime/ParseTag.java,v 1.4 2001/07/08 02:31:57 glenn Exp $
- * $Revision: 1.4 $
- * $Date: 2001/07/08 02:31:57 $
+ * $Header: /home/cvs/jakarta-taglibs/datetime/src/org/apache/taglibs/datetime/ParseTag.java,v 1.5 2001/07/13 14:56:13 glenn Exp $
+ * $Revision: 1.5 $
+ * $Date: 2001/07/13 14:56:13 $
*
* ====================================================================
*
@@ -98,6 +98,11 @@
* <rtexprvalue>false</rtexprvalue>
* </attribute>
* <attribute>
+ * <name>patternId</name>
+ * <required>false</required>
+ * <rtexprvalue>false</rtexprvalue>
+ * </attribute>
+ * <attribute>
* <name>timeZone</name>
* <sessuired>false</sessuired>
* <rtexprvalue>false</rtexprvalue>
@@ -118,6 +123,8 @@
private boolean locale_flag = false;
// Optional attribute, time pattern string to use when formatting date
private String pattern = null;
+ // Optional attribute, name of script variable to use as pattern
+ private String patternid = null;
// Optional attribute, timeZone script variable id to use when
// formatting date
private String timeZone_string;
@@ -148,17 +155,26 @@
// Clear the body since we will output only the parseted date
body.clearBody();
- SimpleDateFormat sdf;
- // Get the default pattern if none defined
- if( pattern == null ) {
- sdf = new SimpleDateFormat();
- pattern = sdf.toPattern();
- }
+ // Get the pattern to use
+ SimpleDateFormat sdf;
+ String pat = pattern;
+
+ if( pat == null && patternid != null ) {
+ Object attr = pageContext.findAttribute(patternid);
+ if( attr != null )
+ pat = attr.toString();
+ }
+
+ if( pat == null ) {
+ sdf = new SimpleDateFormat();
+ pat = sdf.toPattern();
+ }
+
// Get a SimpleDateFormat using locale if necessary
if( !locale_flag )
- sdf = new SimpleDateFormat(pattern);
+ sdf = new SimpleDateFormat(pat);
else
- sdf = new SimpleDateFormat(pattern,
+ sdf = new SimpleDateFormat(pat,
(Locale)pageContext.getRequest().getLocale());
// See if there is a timeZone
@@ -233,5 +249,16 @@
public final void setPattern(String str)
{
pattern = str;
+ }
+
+ /**
+ * Set the pattern to use when parsing Date using a script variable
+ * attribute.
+ *
+ * @param String name of script variable attribute id
+ */
+ public final void setPatternId(String str)
+ {
+ patternid = str;
}
}