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/04/16 20:17:51 UTC

cvs commit: jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt FormatDateSupport.java FormatNumberSupport.java ParseDateSupport.java ParseNumberSupport.java SetLocaleSupport.java

luehe       02/04/16 11:17:51

  Modified:    standard/src/org/apache/taglibs/standard/resources
                        Resources.properties
               standard/src/org/apache/taglibs/standard/tag/common/fmt
                        FormatDateSupport.java FormatNumberSupport.java
                        ParseDateSupport.java ParseNumberSupport.java
                        SetLocaleSupport.java
  Log:
  Formatting actions no longer use runtime's default locale as fallback, since that locale is not guaranteed to be among the supported formatting locales
  
  Revision  Changes    Path
  1.22      +14 -8     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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- Resources.properties	16 Apr 2002 00:11:07 -0000	1.21
  +++ Resources.properties	16 Apr 2002 18:17:51 -0000	1.22
  @@ -84,10 +84,10 @@
   # I18N
   
   LOCALE_NO_LANGUAGE=\
  -    Missing language component in 'value' attribute in <locale> 
  +    Missing language component in 'value' attribute in <setLocale> 
   
   LOCALE_EMPTY_COUNTRY=\
  -    Empty country component in 'value' attribute in <locale>
  +    Empty country component in 'value' attribute in <setLocale>
   
   PARAM_OUTSIDE_MESSAGE=\
       <param> outside <message>
  @@ -110,6 +110,12 @@
   PARSE_NUMBER_NO_VALUE=\
       <parseNumber> needs 'value' attribute or non-whitespace body
   
  +PARSE_NUMBER_NO_PARSE_LOCALE=\
  +    In <parseNumber>, a parse locale can not be established
  +
  +PARSE_NUMBER_PARSE_ERROR=\
  +    In <parseNumber>, 'value' attribute can not be parsed: "{0}"
  +
   FORMAT_DATE_INVALID_TYPE=\
       In <formatDate>, invalid 'type' attribute: "{0}"
   
  @@ -137,17 +143,17 @@
   PARSE_DATE_NO_VALUE=\
       <parseDate> needs 'value' attribute or non-whitespace body
   
  +PARSE_DATE_PARSE_ERROR=\
  +    In <parseDate>, 'value' attribute can not be parsed: "{0}"
  +
  +PARSE_DATE_NO_PARSE_LOCALE=\
  +    In <parseDate>, a parse locale can not be established
  +
   UNDEFINED_KEY=\
       Undefined key "{0}" in resource bundle "{1}"
   
   MISSING_RESOURCE_BUNDLE=\
       Resource bundle with base name "{0}" not found
  -
  -EXCEPTION_STACKTRACE_BOOLEAN=\
  -    In <exception>, 'stacktrace' must be "true" or "false".  Got "{0}" instead.
  -
  -EXCEPTION_NOT_IN_ERROR_PAGE=\
  -    <exception> not in error page
   
   # SQL
   
  
  
  
  1.19      +34 -25    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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- FormatDateSupport.java	15 Apr 2002 17:26:24 -0000	1.18
  +++ FormatDateSupport.java	16 Apr 2002 18:17:51 -0000	1.19
  @@ -135,6 +135,8 @@
        */
       public int doEndTag() throws JspException {
   
  +	String formatted = null;
  +
   	if (value == null) {
   	    if (var != null) {
   		pageContext.removeAttribute(var, scope);
  @@ -148,39 +150,46 @@
   	    this,
   	    true,
   	    DateFormat.getAvailableLocales());
  -	DateFormat formatter = createFormatter(locale);
   
  -	// Apply pattern, if present
  -	if (pattern != null) {
  -	    try {
  -		((SimpleDateFormat) formatter).applyPattern(pattern);
  -	    } catch (ClassCastException cce) {
  -		formatter = new SimpleDateFormat(pattern, locale);
  +	if (locale != null) {
  +	    DateFormat formatter = createFormatter(locale);
  +
  +	    // Apply pattern, if present
  +	    if (pattern != null) {
  +		try {
  +		    ((SimpleDateFormat) formatter).applyPattern(pattern);
  +		} catch (ClassCastException cce) {
  +		    formatter = new SimpleDateFormat(pattern, locale);
  +		}
   	    }
  -	}
   
  -	// Set time zone
  -	TimeZone tz = null;
  -	if ((timeZone instanceof String) && ((String) timeZone).equals("")) {
  -	    timeZone = null;
  -	}
  -	if (timeZone != null) {
  -	    if (timeZone instanceof String) {
  -		tz = TimeZone.getTimeZone((String) timeZone);
  -	    } else if (timeZone instanceof TimeZone) {
  -		tz = (TimeZone) timeZone;
  +	    // Set time zone
  +	    TimeZone tz = null;
  +	    if ((timeZone instanceof String)
  +		&& ((String) timeZone).equals("")) {
  +		timeZone = 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 {
  -		throw new JspTagException(
  -                    Resources.getMessage("FORMAT_DATE_BAD_TIMEZONE"));
  +		tz = TimeZoneSupport.getTimeZone(pageContext, this);
  +	    }
  +	    if (tz != null) {
  +		formatter.setTimeZone(tz);
   	    }
  +	    formatted = formatter.format(value);
   	} else {
  -	    tz = TimeZoneSupport.getTimeZone(pageContext, this);
  -	}
  -	if (tz != null) {
  -	    formatter.setTimeZone(tz);
  +	    // no formatting locale available, use Date.toString()
  +	    formatted = value.toString();
   	}
   
  -	String formatted = formatter.format(value);
   	if (var != null) {
   	    pageContext.setAttribute(var, formatted, scope);	
   	} else {
  
  
  
  1.17      +10 -5     jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/FormatNumberSupport.java
  
  Index: FormatNumberSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/FormatNumberSupport.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- FormatNumberSupport.java	15 Apr 2002 16:58:31 -0000	1.16
  +++ FormatNumberSupport.java	16 Apr 2002 18:17:51 -0000	1.17
  @@ -153,6 +153,8 @@
       // Tag logic
   
       public int doEndTag() throws JspException {
  +	String formatted = null;
  +
   	if (value == null) {
   	    BodyContent bc = null;
   	    String bcs = null;
  @@ -191,13 +193,16 @@
   	    this,
   	    true,
   	    NumberFormat.getAvailableLocales());
  -	NumberFormat formatter = createFormatter(locale);
   
  -	// Configure the formatter
  -	configureFormatter(formatter);
  +	if (locale != null) {
  +	    NumberFormat formatter = createFormatter(locale);
  +	    configureFormatter(formatter);
  +	    formatted = formatter.format(value);
  +	} else {
  +	    // no formatting locale available, use toString()
  +	    formatted = value.toString();
  +	}
   
  -	// Format given numeric value
  -	String formatted = formatter.format(value);
   	if (var != null) {
   	    pageContext.setAttribute(var, formatted, scope);	
   	} else {
  
  
  
  1.16      +9 -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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- ParseDateSupport.java	12 Apr 2002 19:16:49 -0000	1.15
  +++ ParseDateSupport.java	16 Apr 2002 18:17:51 -0000	1.16
  @@ -159,6 +159,10 @@
   	        this,
   		false,
   	        DateFormat.getAvailableLocales());
  +	if (locale == null) {
  +	    throw new JspException(
  +                    Resources.getMessage("PARSE_DATE_NO_PARSE_LOCALE"));
  +	}
   
   	// Create parser
   	DateFormat parser = createParser(locale);
  @@ -183,7 +187,7 @@
   	    } else if (timeZone instanceof TimeZone) {
   		tz = (TimeZone) timeZone;
   	    } else {
  -		throw new JspTagException(
  +		throw new JspException(
                       Resources.getMessage("PARSE_DATE_BAD_TIMEZONE"));
   	    }
   	} else {
  @@ -198,7 +202,9 @@
   	try {
   	    parsed = parser.parse(value);
   	} catch (ParseException pe) {
  -	    throw new JspTagException(pe.getMessage());
  +	    throw new JspException(
  +	            Resources.getMessage("PARSE_DATE_PARSE_ERROR", value),
  +		    pe);
   	}
   
   	if (var != null) {
  @@ -241,8 +247,7 @@
   		loc);
   	} else {
   	    throw new JspException(
  -                    Resources.getMessage("PARSE_DATE_INVALID_TYPE", 
  -					 type));
  +                    Resources.getMessage("PARSE_DATE_INVALID_TYPE", type));
   	}
   
   	parser.setLenient(false);
  
  
  
  1.12      +7 -1      jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/ParseNumberSupport.java
  
  Index: ParseNumberSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/ParseNumberSupport.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ParseNumberSupport.java	12 Apr 2002 19:16:49 -0000	1.11
  +++ ParseNumberSupport.java	16 Apr 2002 18:17:51 -0000	1.12
  @@ -157,6 +157,10 @@
   	        this,
   		false,
   	        NumberFormat.getAvailableLocales());
  +	if (locale == null) {
  +	    throw new JspException(
  +                    Resources.getMessage("PARSE_NUMBER_NO_PARSE_LOCALE"));
  +	}
   
   	// Create parser
   	NumberFormat parser = createParser(locale);
  @@ -170,7 +174,9 @@
   	try {
   	    parsed = parser.parse(value);
   	} catch (ParseException pe) {
  -	    throw new JspTagException(pe.getMessage());
  +	    throw new JspException(
  +	            Resources.getMessage("PARSE_NUMBER_PARSE_ERROR", value),
  +		    pe);
   	}
   
   	if (var != null) {
  
  
  
  1.5       +4 -7      jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/SetLocaleSupport.java
  
  Index: SetLocaleSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/SetLocaleSupport.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SetLocaleSupport.java	16 Apr 2002 15:49:50 -0000	1.4
  +++ SetLocaleSupport.java	16 Apr 2002 18:17:51 -0000	1.5
  @@ -259,7 +259,6 @@
   				      Tag fromTag,
   				      boolean format,
   				      Locale[] avail) {
  -	Locale match = null;
   	LocalizationContext locCtxt = null;
   	
   	// Get formatting locale from enclosing <fmt:bundle>
  @@ -292,6 +291,7 @@
   	 * (in order of preference) against the available formatting
   	 * locales, and determining the best matching locale.
   	 */
  +	Locale match = null;
   	Locale pref = getLocale(pc, Config.FMT_LOCALE);
   	if (pref != null) {
   	    // Preferred locale is application-based
  @@ -303,14 +303,11 @@
   	if (match == null) {
   	    //Use fallback locale.
   	    pref = getLocale(pc, Config.FMT_FALLBACKLOCALE);
  -	    if ((pref == null)
  -		|| ((match = findFormattingMatch(pref,
  -						 avail)) == null)) {
  -		// Use runtime's default locale.
  -		match = Locale.getDefault();
  +	    if (pref != null) {
  +		match = findFormattingMatch(pref, avail);
   	    }
   	}
  - 	if (format) {
  + 	if (format && (match != null)) {
   	    setResponseLocale(pc, match);
   	}
   
  
  
  

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