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 2001/12/03 21:33:15 UTC

cvs commit: jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/rt/fmt ParseDateTag.java

luehe       01/12/03 12:33:15

  Modified:    standard/conf fmt-rt.tld fmt.tld
               standard/examples/web/format FormatDateTime.jsp
               standard/src/org/apache/taglibs/standard/tag/common/fmt
                        FormatDateSupport.java ParseDateSupport.java
                        TimeZoneSupport.java
               standard/src/org/apache/taglibs/standard/tag/el/fmt
                        ParseDateTag.java
               standard/src/org/apache/taglibs/standard/tag/rt/fmt
                        ParseDateTag.java
  Log:
  Added 'timeStyle', 'dateStyle', and 'timeZone' attributes to <parseDate>
  
  Revision  Changes    Path
  1.3       +15 -0     jakarta-taglibs/standard/conf/fmt-rt.tld
  
  Index: fmt-rt.tld
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/conf/fmt-rt.tld,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- fmt-rt.tld	2001/11/21 16:17:04	1.2
  +++ fmt-rt.tld	2001/12/03 20:33:15	1.3
  @@ -328,7 +328,22 @@
           <rtexprvalue>false</rtexprvalue>
       </attribute>
       <attribute>
  +        <name>dateStyle</name>
  +        <required>false</required>
  +        <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +        <name>timeStyle</name>
  +        <required>false</required>
  +        <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
           <name>pattern</name>
  +        <required>false</required>
  +        <rtexprvalue>true</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +        <name>timeZone</name>
           <required>false</required>
           <rtexprvalue>true</rtexprvalue>
       </attribute>
  
  
  
  1.3       +15 -0     jakarta-taglibs/standard/conf/fmt.tld
  
  Index: fmt.tld
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/conf/fmt.tld,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- fmt.tld	2001/11/21 16:17:04	1.2
  +++ fmt.tld	2001/12/03 20:33:15	1.3
  @@ -367,7 +367,22 @@
           <rtexprvalue>false</rtexprvalue>
       </attribute>
       <attribute>
  +        <name>dateStyle</name>
  +        <required>false</required>
  +        <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +        <name>timeStyle</name>
  +        <required>false</required>
  +        <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
           <name>pattern</name>
  +        <required>false</required>
  +        <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +        <name>timeZone</name>
           <required>false</required>
           <rtexprvalue>false</rtexprvalue>
       </attribute>
  
  
  
  1.3       +22 -7     jakarta-taglibs/standard/examples/web/format/FormatDateTime.jsp
  
  Index: FormatDateTime.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/examples/web/format/FormatDateTime.jsp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FormatDateTime.jsp	2001/11/21 20:26:36	1.2
  +++ FormatDateTime.jsp	2001/12/03 20:33:15	1.3
  @@ -8,18 +8,33 @@
   <h3>Formatting Dates and Times</h3>
   
   <ul>
  + <li> Parsing SHORT version of current time in different time zones:<br>
  +  <fmt:formatDate type="both" timeStyle="short" var="formattedDateTime"/>
  +  <fmt:parseDate value="$formattedDateTime" type="both" timeStyle="short" timeZone="GMT"/> (parsed in &quot;GMT&quot;)<br>
  +  <fmt:parseDate value="$formattedDateTime" type="both" timeStyle="short" timeZone="GMT+1:00"/> (parsed in &quot;GMT+1:00&quot;)<br>
  +  <fmt:parseDate value="$formattedDateTime" type="both" timeStyle="short" timeZone="GMT+3:00"/> (parsed in &quot;GMT+3:00&quot;)<br>
  +  <fmt:parseDate value="$formattedDateTime" type="both" timeStyle="short" timeZone="PST"/> (parsed in &quot;PST&quot;)
  +
  + <li> Parsing FULL version of current time in different time zones (should not be affected):<br>
  +  <fmt:formatDate type="both" timeStyle="full" var="formattedDateTime"/>
  +  <fmt:parseDate value="$formattedDateTime" type="both" timeStyle="full" timeZone="GMT"/> (parsed in &quot;GMT&quot;)<br>
  +  <fmt:parseDate value="$formattedDateTime" type="both" timeStyle="full" timeZone="GMT+1:00"/> (parsed in &quot;GMT+1:00&quot;)<br>
  +  <fmt:parseDate value="$formattedDateTime" type="both" timeStyle="full" timeZone="GMT+3:00"/> (parsed in &quot;GMT+3:00&quot;)<br>
  +  <fmt:parseDate value="$formattedDateTime" type="both" timeStyle="full" timeZone="PST"/> (parsed in &quot;PST&quot;)
  +
    <li> Formatting current date as &quot;GMT&quot;: 
     <fmt:timeZone value="GMT">
  -   <fmt:formatDate type="both"/>
  +   <fmt:formatDate type="both" dateStyle="full" timeStyle="full"/>
     </fmt:timeZone>
   
  - <li> Formatting current date as &quot;GMT+1:00&quot;, and parse
  + <li> Formatting current date as &quot;GMT+1:00&quot;, and parsing
         its date and time components:<br>
  -  <fmt:timeZone value="GMT+1:00"/>
  -  <fmt:formatDate type="both" dateStyle="long" timeStyle="long" var="formattedDate"/>
  -  <fmt:parseDate value="$formattedDate" type="both" var="parsedDate"/>
  -  Parsed date: <fmt:formatDate value="$parsedDate" type="date"/><br>
  -  Parsed time: <fmt:formatDate value="$parsedDate" type="time"/>
  +  <fmt:timeZone value="GMT+1:00">
  +   <fmt:formatDate type="both" dateStyle="full" timeStyle="full" var="formattedDateTime"/>
  +   <fmt:parseDate value="$formattedDateTime" type="both" dateStyle="full" timeStyle="full" timeZone="PST" var="parsedDateTime"/>
  +   Parsed date: <fmt:formatDate value="$parsedDateTime" type="date" dateStyle="full"/><br>
  +   Parsed time: <fmt:formatDate value="$parsedDateTime" type="time" timeStyle="full"/>
  +  </fmt:timeZone>
   </ul>
   
   </body>
  
  
  
  1.2       +6 -21     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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FormatDateSupport.java	2001/11/21 07:38:59	1.1
  +++ FormatDateSupport.java	2001/12/03 20:33:15	1.2
  @@ -202,6 +202,7 @@
   	    break;
   	} // switch
   
  +	// Apply pattern, if present
   	if (pattern != null) {
   	    try {
   		((SimpleDateFormat) formatter).applyPattern(pattern);
  @@ -210,25 +211,9 @@
   	    }
   	}
   
  -	if (timeZone == null) {
  -	    Tag t = findAncestorWithClass(this, TimeZoneSupport.class);
  -	    if (t != null) {
  -		// use time zone from parent <timeZone> tag
  -		TimeZoneSupport parent = (TimeZoneSupport) t;
  -		timeZone = parent.getTimeZone();
  -	    } else {
  -		// get time zone from scoped attribute
  -		timeZone = (TimeZone) pageContext.findAttribute(
  -                    TimeZoneSupport.TIMEZONE_ATTRIBUTE);
  -		if (timeZone == null) {
  -		    String tz =
  -			pageContext.getServletContext().getInitParameter(
  -			    TimeZoneSupport.TIMEZONE_ATTRIBUTE);
  -		    if (tz != null)
  -			timeZone = TimeZone.getTimeZone(tz);
  -		}
  -	    }
  -	}
  +	// Set time zone
  +	if (timeZone == null)
  +	    timeZone = TimeZoneSupport.getTimeZone(pageContext, this);
   	if (timeZone != null)
   	    formatter.setTimeZone(timeZone);
   
  @@ -253,9 +238,9 @@
   
   
       //*********************************************************************
  -    // Private utility methods
  +    // Package-scoped utility methods
   
  -    private int getStyle(String style) {
  +    static int getStyle(String style) {
   	int ret = DateFormat.DEFAULT;
   
   	if (SHORT_STYLE.equalsIgnoreCase(style))
  
  
  
  1.2       +23 -4     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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ParseDateSupport.java	2001/11/21 07:39:01	1.1
  +++ ParseDateSupport.java	2001/12/03 20:33:15	1.2
  @@ -77,12 +77,15 @@
   
       protected String value;                      // 'value' attribute
       protected String pattern;                    // 'pattern' attribute
  +    protected TimeZone timeZone;                 // 'timeZone' attribute
   
   
       //*********************************************************************
       // Private state
   
       private int type;                            // 'type' attribute
  +    private int dateStyle;                       // 'dateStyle' attribute
  +    private int timeStyle;                       // 'timeStyle' attribute
       private String var;                          // 'var' attribute
       private int scope;                           // 'scope' attribute
   
  @@ -97,7 +100,9 @@
   
       private void init() {
   	value = pattern = var = null;
  +	timeZone = null;
   	type = FormatDateSupport.DATE_TYPE;
  +	dateStyle = timeStyle = DateFormat.DEFAULT;
   	scope = PageContext.PAGE_SCOPE;
       }
   
  @@ -112,6 +117,14 @@
   	    this.type = FormatDateSupport.DATETIME_TYPE;
       }
   
  +    public void setDateStyle(String dateStyle) {
  +        this.dateStyle = FormatDateSupport.getStyle(dateStyle);
  +    }
  +
  +    public void setTimeStyle(String timeStyle) {
  +        this.timeStyle = FormatDateSupport.getStyle(timeStyle);
  +    }
  +
       public void setVar(String var) {
           this.var = var;
       }
  @@ -134,18 +147,18 @@
   
   	switch (type) {
   	case FormatDateSupport.DATE_TYPE:
  -	    formatter = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
  +	    formatter = DateFormat.getDateInstance(dateStyle, locale);
   	    break;
   	case FormatDateSupport.TIME_TYPE:
  -	    formatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, locale);
  +	    formatter = DateFormat.getTimeInstance(timeStyle, locale);
   	    break;
   	case FormatDateSupport.DATETIME_TYPE:
  -	    formatter = DateFormat.getDateTimeInstance(DateFormat.DEFAULT,
  -						       DateFormat.DEFAULT,
  +	    formatter = DateFormat.getDateTimeInstance(dateStyle, timeStyle,
   						       locale);
   	    break;
   	} // switch
   
  +	// Apply pattern, if present
   	if (pattern != null) {
   	    try {
   		((SimpleDateFormat) formatter).applyPattern(pattern);
  @@ -153,6 +166,12 @@
   		formatter = new SimpleDateFormat(pattern, locale);
   	    }
   	}
  +
  +	// Set time zone
  +	if (timeZone == null)
  +	    timeZone = TimeZoneSupport.getTimeZone(pageContext, this);
  +	if (timeZone != null)
  +	    formatter.setTimeZone(timeZone);
   
   	Date parsed = null;
   	try {
  
  
  
  1.3       +46 -0     jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/TimeZoneSupport.java
  
  Index: TimeZoneSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/TimeZoneSupport.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TimeZoneSupport.java	2001/11/21 17:37:59	1.2
  +++ TimeZoneSupport.java	2001/12/03 20:33:15	1.3
  @@ -151,4 +151,50 @@
       public void release() {
   	init();
       }
  +
  +
  +    //*********************************************************************
  +    // Package-scoped utility methods
  +
  +    /*
  +     * Returns the time zone.
  +     *
  +     * <p> If the given action is nested inside a &lt;timeZone&gt; tag,
  +     * the time zone is taken from the enclosing &lt;timeZone&gt; tag.
  +     *
  +     * <p> Otherwise, the default time zone given by the
  +     * <tt>javax.servlet.jsp.jstl.i18n.timeZone</tt> scoped attribute is used,
  +     * which is searched in the page, request, session (if valid),
  +     * and application scope(s) (in this order).
  +     * 
  +     * <p> If still not found, the JSP container's time zone is used.
  +     *
  +     * @param pageContext the page containing the action that requires the
  +     * time zone
  +     * @param fromTag the action that requires the time zone
  +     *
  +     * @return the time zone
  +     */
  +    static TimeZone getTimeZone(PageContext pageContext, Tag fromTag) {
  +	TimeZone ret = null;
  +
  +	Tag t = findAncestorWithClass(fromTag, TimeZoneSupport.class);
  +	if (t != null) {
  +	    // use time zone from parent <timeZone> tag
  +	    TimeZoneSupport parent = (TimeZoneSupport) t;
  +	    ret = parent.getTimeZone();
  +	} else {
  +	    // get time zone from scoped attribute
  +	    ret = (TimeZone)
  +		pageContext.findAttribute(TIMEZONE_ATTRIBUTE);
  +	    if (ret == null) {
  +		String tz = pageContext.getServletContext().getInitParameter(
  +		    TIMEZONE_ATTRIBUTE);
  +		if (tz != null)
  +		    ret = TimeZone.getTimeZone(tz);
  +	    }
  +	}
  +
  +	return ret;
  +    }
   }
  
  
  
  1.2       +12 -0     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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ParseDateTag.java	2001/11/21 07:39:03	1.1
  +++ ParseDateTag.java	2001/12/03 20:33:15	1.2
  @@ -75,6 +75,7 @@
   
       private String value_;                       // stores EL-based property
       private String pattern_;		         // stores EL-based property
  +    private String timeZone_;		         // stores EL-based property
   
   
       //*********************************************************************
  @@ -124,6 +125,11 @@
           this.pattern_ = pattern_;
       }
   
  +    // for EL-based attribute
  +    public void setTimeZone(String timeZone_) {
  +        this.timeZone_ = timeZone_;
  +    }
  +
   
       //*********************************************************************
       // Private (utility) methods
  @@ -149,5 +155,11 @@
   	pattern = (String) ExpressionUtil.evalNotNull(
   	    "parseDate", "pattern", pattern_, String.class, this,
   	    pageContext);
  +
  +	String tz = (String) ExpressionUtil.evalNotNull(
  +	    "formatDate", "timeZone", timeZone_, String.class, this,
  +	    pageContext);
  +	if (tz != null)
  +	    timeZone = TimeZone.getTimeZone(tz);
       }
   }
  
  
  
  1.2       +5 -0      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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ParseDateTag.java	2001/11/21 07:38:49	1.1
  +++ ParseDateTag.java	2001/12/03 20:33:15	1.2
  @@ -81,4 +81,9 @@
       public void setPattern(String pattern) throws JspTagException {
           this.pattern = pattern;
       }
  +
  +    // for tag attribute
  +    public void setTimeZone(String timeZone) throws JspTagException {
  +        this.timeZone = TimeZone.getTimeZone(timeZone);
  +    }
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>