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/26 21:59:21 UTC

cvs commit: jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt BundleSupport.java MessageSupport.java SetBundleSupport.java SetLocaleSupport.java

luehe       02/04/26 12:59:21

  Modified:    standard/src/javax/servlet/jsp/jstl/fmt LocaleSupport.java
               standard/src/org/apache/taglibs/standard/tag/common/fmt
                        BundleSupport.java MessageSupport.java
                        SetBundleSupport.java SetLocaleSupport.java
  Log:
  - Use locale from localization context instead of resource bundle locale
  - Don't set response locale if localization context locale is null
  
  Revision  Changes    Path
  1.7       +3 -1      jakarta-taglibs/standard/src/javax/servlet/jsp/jstl/fmt/LocaleSupport.java
  
  Index: LocaleSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/javax/servlet/jsp/jstl/fmt/LocaleSupport.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- LocaleSupport.java	17 Apr 2002 20:51:18 -0000	1.6
  +++ LocaleSupport.java	26 Apr 2002 19:59:21 -0000	1.7
  @@ -188,7 +188,9 @@
   		    message = bundle.getString(key);
   		    if (args != null) {
   			MessageFormat formatter = new MessageFormat("");
  -			formatter.setLocale(bundle.getLocale());
  +			if (locCtxt.getLocale() != null) {
  +			    formatter.setLocale(locCtxt.getLocale());
  +			}
   			formatter.applyPattern(message);
   			message = formatter.format(args);
   		    }
  
  
  
  1.25      +18 -17    jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/BundleSupport.java
  
  Index: BundleSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/BundleSupport.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- BundleSupport.java	17 Apr 2002 20:48:03 -0000	1.24
  +++ BundleSupport.java	26 Apr 2002 19:59:21 -0000	1.25
  @@ -125,10 +125,7 @@
       // Tag logic
   
       public int doStartTag() throws JspException {
  -	if ((basename != null) && !basename.equals("")) {
  -	    locCtxt = getLocalizationContext(pageContext, basename);
  -	}
  -
  +	locCtxt = getLocalizationContext(pageContext, basename);
   	return EVAL_BODY_BUFFERED;
       }
   
  @@ -183,30 +180,32 @@
        * Check if a match exists between the ordered set of preferred
        * locales and the available locales, for the given base name.
        * The set of preferred locales consists of a single locale
  -     * (if the <tt>javax.servlet.jsp.jstl.fmt.locale</tt> scoped attribute or
  -     * context init parameter is present) or is equal to the client's preferred
  -     * locales determined from the client's browser settings.
  +     * (if the <tt>javax.servlet.jsp.jstl.fmt.locale</tt> configuration
  +     * setting is present) or is equal to the client's preferred locales
  +     * determined from the client's browser settings.
        *
        * <p> If no match was found in the previous step, check if a match
        * exists between the fallback locale (given by the
  -     * <tt>javax.servlet.jsp.jstl.fmt.fallbackLocale</tt> scoped attribute
  -     * or context init parameter) and the available locales, for the given
  -     * base name.
  +     * <tt>javax.servlet.jsp.jstl.fmt.fallbackLocale</tt> configuration
  +     * setting) and the available locales, for the given base name.
        *
        * @param pageContext Page in which the resource bundle with the
        * given base name is requested
        * @param basename Resource bundle base name
        *
        * @return Localization context containing the resource bundle with the
  -     * given base name for which a match between the preferred (or fallback)
  -     * and available locales exists, or null if no resource bundle match was
  -     * found
  +     * given base name and the locale that led to the resource bundle match,
  +     * or the empty localization context if no resource bundle match was found
        */
       public static LocalizationContext getLocalizationContext(PageContext pc,
   							     String basename) {
   	LocalizationContext locCtxt = null;
   	ResourceBundle bundle = null;
   
  +	if ((basename == null) || basename.equals("")) {
  +	    return new LocalizationContext();
  +	}
  +
   	// Try preferred locales
   	Locale pref = SetLocaleSupport.getLocale(pc, Config.FMT_LOCALE);
   	if (pref != null) {
  @@ -244,11 +243,13 @@
   	}
   		 
   	if (locCtxt != null) {
  -	    bundle = locCtxt.getResourceBundle();
  -	    if (bundle != null) {
  -		// set response locale
  -		SetLocaleSupport.setResponseLocale(pc, bundle.getLocale());
  +	    // set response locale
  +	    if (locCtxt.getLocale() != null) {
  +		SetLocaleSupport.setResponseLocale(pc, locCtxt.getLocale());
   	    }
  +	} else {
  +	    // create empty localization context
  +	    locCtxt = new LocalizationContext();
   	}
   
   	return locCtxt;
  
  
  
  1.18      +24 -26    jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/MessageSupport.java
  
  Index: MessageSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/MessageSupport.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- MessageSupport.java	17 Apr 2002 18:55:07 -0000	1.17
  +++ MessageSupport.java	26 Apr 2002 19:59:21 -0000	1.18
  @@ -147,9 +147,6 @@
   
       public int doEndTag() throws JspException {
   
  -	String message = null;
  -	ResourceBundle bundle = null;
  -
   	if (key == null) {
   	    BodyContent bc = null;
   	    String bcs = null;
  @@ -179,34 +176,35 @@
   		locCtxt = BundleSupport.getLocalizationContext(pageContext);
   	    }
   	} else {
  -	    if (locCtxt.getResourceBundle() != null) {
  -		SetLocaleSupport.setResponseLocale(
  -                                pageContext,
  -				locCtxt.getResourceBundle().getLocale());
  +	    // localization context taken from 'bundle' attribute
  +	    if (locCtxt.getLocale() != null) {
  +		SetLocaleSupport.setResponseLocale(pageContext,
  +						   locCtxt.getLocale());
   	    }
   	}
   
  +	String message = UNDEFINED_KEY + key + UNDEFINED_KEY;
   	if (locCtxt != null) {
  -	    bundle = locCtxt.getResourceBundle();
  -	}
  -	if (bundle == null) {
  -	    message = UNDEFINED_KEY + key + UNDEFINED_KEY;
  -	} else {
  -	    try {
  -		// prepend 'prefix' attribute from parent bundle
  -		if (prefix != null)
  -		    key = prefix + key;
  -		message = bundle.getString(key);
  -		// Perform parametric replacement if required
  -		if (!params.isEmpty()) {
  -		    Object[] messageArgs = params.toArray();
  -		    MessageFormat formatter = new MessageFormat("");
  -		    formatter.setLocale(bundle.getLocale());
  -		    formatter.applyPattern(message);
  -		    message = formatter.format(messageArgs);
  +	    ResourceBundle bundle = locCtxt.getResourceBundle();
  +	    if (bundle != null) {
  +		try {
  +		    // prepend 'prefix' attribute from parent bundle
  +		    if (prefix != null)
  +			key = prefix + key;
  +		    message = bundle.getString(key);
  +		    // Perform parametric replacement if required
  +		    if (!params.isEmpty()) {
  +			Object[] messageArgs = params.toArray();
  +			MessageFormat formatter = new MessageFormat("");
  +			if (locCtxt.getLocale() != null) {
  +			    formatter.setLocale(locCtxt.getLocale());
  +			}
  +			formatter.applyPattern(message);
  +			message = formatter.format(messageArgs);
  +		    }
  +		} catch (MissingResourceException mre) {
  +		    message = UNDEFINED_KEY + key + UNDEFINED_KEY;
   		}
  -	    } catch (MissingResourceException mre) {
  -		message = UNDEFINED_KEY + key + UNDEFINED_KEY;
   	    }
   	}
   
  
  
  
  1.7       +2 -11     jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/SetBundleSupport.java
  
  Index: SetBundleSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/SetBundleSupport.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SetBundleSupport.java	18 Apr 2002 22:53:51 -0000	1.6
  +++ SetBundleSupport.java	26 Apr 2002 19:59:21 -0000	1.7
  @@ -117,17 +117,8 @@
       // Tag logic
   
       public int doEndTag() throws JspException {
  -	LocalizationContext locCtxt = null;
  -
  -	if ((basename != null) && !basename.equals("")) {
  -	    locCtxt = BundleSupport.getLocalizationContext(pageContext,
  -							   basename);
  -	}
  -
  -	if (locCtxt == null) {
  -	    // create empty localization context
  -	    locCtxt = new LocalizationContext();
  -	}
  +	LocalizationContext locCtxt =
  +	    BundleSupport.getLocalizationContext(pageContext, basename);
   
   	if (var != null) {
   	    pageContext.setAttribute(var, locCtxt, scope);
  
  
  
  1.8       +14 -14    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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SetLocaleSupport.java	18 Apr 2002 22:53:51 -0000	1.7
  +++ SetLocaleSupport.java	26 Apr 2002 19:59:21 -0000	1.8
  @@ -258,32 +258,32 @@
   				      Tag fromTag,
   				      boolean format,
   				      Locale[] avail) {
  +
   	LocalizationContext locCtxt = null;
   	
   	// Get formatting locale from enclosing <fmt:bundle>
   	Tag parent = findAncestorWithClass(fromTag, BundleSupport.class);
   	if (parent != null) {
  -	    // use locale from parent <fmt:bundle> tag
  -	    if ((locCtxt = ((BundleSupport) parent).getLocalizationContext())
  -		                                                != null) {
  -		ResourceBundle bundle = locCtxt.getResourceBundle();
  -		if (bundle != null) {
  -		    if (format) {
  -			setResponseLocale(pc, bundle.getLocale());
  -		    }
  -		    return bundle.getLocale();
  +	    /*
  +	     * use locale from localization context established by parent
  +	     * <fmt:bundle> action, unless that locale is null
  +	     */
  +	    locCtxt = ((BundleSupport) parent).getLocalizationContext();
  +	    if (locCtxt.getLocale() != null) {
  +		if (format) {
  +		    setResponseLocale(pc, locCtxt.getLocale());
   		}
  +		return locCtxt.getLocale();
   	    }
   	}
   
  -	// Get formatting locale from default I18N localization context
  +	// Use locale from default I18N localization context, unless it is null
   	if ((locCtxt = BundleSupport.getLocalizationContext(pc)) != null) {
  -	    ResourceBundle bundle = locCtxt.getResourceBundle();
  -	    if (bundle != null) {
  +	    if (locCtxt.getLocale() != null) {
   		if (format) {
  -		    setResponseLocale(pc, bundle.getLocale());
  +		    setResponseLocale(pc, locCtxt.getLocale());
   		}
  -		return bundle.getLocale();
  +		return locCtxt.getLocale();
   	    }
   	}
   
  
  
  

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