You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by cr...@apache.org on 2001/08/07 00:36:27 UTC

cvs commit: jakarta-struts/src/share/org/apache/struts/util MessageResources.java

craigmcc    01/08/06 15:36:27

  Modified:    src/share/org/apache/struts/util MessageResources.java
  Log:
  Fix for Bugzilla #2233 (single quotes in application resources do not show
  up even though they are properly escaped with "\").
  
  The underlying problem is that the messages strings in your application
  resources files are processed twice -- once when loaded by Property.load()
  and once when the message is formatted with MessageFormat.format().  The
  first call converts occurrences of "\'" to "'" in the format string; but
  MessageFormat has an undocumented requirement that single quotes be
  escaped by an extra single quote (not by a backslash).  The patch escapes
  the format string as expected by MessageFormat so that this actually
  happens.
  
  This affects the lookup and display of message strings in all of the
  following tags:
    <html:errors>
    <html:image>
    <html:img>
    <html:messages>
    <html:option
  
  PR: Bugzilla #2233
  Submitted by:	rmatteodg@infinito.it
  
  Revision  Changes    Path
  1.11      +28 -5     jakarta-struts/src/share/org/apache/struts/util/MessageResources.java
  
  Index: MessageResources.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/MessageResources.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- MessageResources.java	2001/04/18 23:32:35	1.10
  +++ MessageResources.java	2001/08/06 22:36:27	1.11
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/MessageResources.java,v 1.10 2001/04/18 23:32:35 craigmcc Exp $
  - * $Revision: 1.10 $
  - * $Date: 2001/04/18 23:32:35 $
  + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/MessageResources.java,v 1.11 2001/08/06 22:36:27 craigmcc Exp $
  + * $Revision: 1.11 $
  + * $Date: 2001/08/06 22:36:27 $
    *
    * ====================================================================
    * 
  @@ -89,7 +89,7 @@
    * application server environments.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.10 $ $Date: 2001/04/18 23:32:35 $
  + * @version $Revision: 1.11 $ $Date: 2001/08/06 22:36:27 $
    */
   
   public abstract class MessageResources implements Serializable {
  @@ -317,7 +317,7 @@
   		    else
   			return ("???" + formatKey + "???");
   		}
  -		format = new MessageFormat(formatString);
  +		format = new MessageFormat(escape(formatString));
   		formats.put(formatKey, format);
   	    }
   
  @@ -455,6 +455,29 @@
   
   
       // ------------------------------------------------------ Protected Methods
  +
  +
  +    /**
  +     * Escape any single quote characters that are included in the specified
  +     * message string.
  +     *
  +     * @param string The string to be escaped
  +     */
  +    protected String escape(String string) {
  +
  +        if ((string == null) || (string.indexOf('\'') < 0))
  +            return (string);
  +        int n = string.length();
  +        StringBuffer sb = new StringBuffer(n);
  +        for (int i = 0; i < n; i++) {
  +            char ch = string.charAt(i);
  +            if (ch == '\'')
  +                sb.append('\'');
  +            sb.append(ch);
  +        }
  +        return (sb.toString());
  +
  +    }
   
   
       /**