You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2004/06/30 17:34:51 UTC

cvs commit: jakarta-tapestry/framework/src/org/apache/tapestry IMessages.java

hlship      2004/06/30 08:34:51

  Modified:    framework/src/org/apache/tapestry/engine Tag: branch-3-0
                        ComponentMessages.java
               junit/src/org/apache/tapestry/junit Tag: branch-3-0
                        TestComponentMessages.java MockPage1.properties
               framework/src/org/apache/tapestry Tag: branch-3-0
                        IMessages.java
  Log:
  Make ComponentMessages expand exceptions into their message or class name.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.6.2.1   +23 -7     jakarta-tapestry/framework/src/org/apache/tapestry/engine/ComponentMessages.java
  
  Index: ComponentMessages.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/engine/ComponentMessages.java,v
  retrieving revision 1.6
  retrieving revision 1.6.2.1
  diff -u -r1.6 -r1.6.2.1
  --- ComponentMessages.java	19 Feb 2004 17:38:00 -0000	1.6
  +++ ComponentMessages.java	30 Jun 2004 15:34:51 -0000	1.6.2.1
  @@ -19,6 +19,7 @@
   import java.util.Properties;
   
   import org.apache.tapestry.IMessages;
  +import org.apache.tapestry.Tapestry;
   
   /**
    *  Implementation of {@link org.apache.tapestry.IMessages}.  This is basically
  @@ -27,7 +28,6 @@
    *  they don't have to be synchronized).
    *
    *  @author Howard Lewis Ship
  - *  @version $Id$
    *  @since 2.0.4
    *
    **/
  @@ -77,15 +77,31 @@
       {
           String pattern = getMessage(key);
   
  -		// This ugliness is mandated for JDK 1.3 compatibility, which has a bug 
  -		// in MessageFormat ... the
  -		// pattern is applied in the constructor, using the system default Locale,
  -		// regardless of what locale is later specified!
  -		// It appears that the problem does not exist in JDK 1.4.
  -		
  +        // This ugliness is mandated for JDK 1.3 compatibility, which has a bug 
  +        // in MessageFormat ... the
  +        // pattern is applied in the constructor, using the system default Locale,
  +        // regardless of what locale is later specified!
  +        // It appears that the problem does not exist in JDK 1.4.
  +
           MessageFormat messageFormat = new MessageFormat("");
           messageFormat.setLocale(_locale);
           messageFormat.applyPattern(pattern);
  +
  +        int count = Tapestry.size(arguments);
  +
  +        for (int i = 0; i < count; i++)
  +        {
  +            if (arguments[i] instanceof Throwable)
  +            {
  +                Throwable t = (Throwable) arguments[i];
  +                String message = t.getMessage();
  +
  +                if (Tapestry.isNonBlank(message))
  +                    arguments[i] = message;
  +                else
  +                    arguments[i] = t.getClass().getName();
  +            }
  +        }
   
           return messageFormat.format(arguments);
       }
  
  
  
  No                   revision
  No                   revision
  1.6.2.1   +20 -3     jakarta-tapestry/junit/src/org/apache/tapestry/junit/TestComponentMessages.java
  
  Index: TestComponentMessages.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/junit/src/org/apache/tapestry/junit/TestComponentMessages.java,v
  retrieving revision 1.6
  retrieving revision 1.6.2.1
  diff -u -r1.6 -r1.6.2.1
  --- TestComponentMessages.java	19 Feb 2004 17:37:56 -0000	1.6
  +++ TestComponentMessages.java	30 Jun 2004 15:34:51 -0000	1.6.2.1
  @@ -25,10 +25,8 @@
    *  Tests the class {@link org.apache.tapestry.engine.DefaultStringsSource}.
    *
    *  @author Howard Lewis Ship
  - *  @version $Id$
    *  @since 2.0.4
  - *
  - **/
  + */
   
   public class TestComponentMessages extends TapestryTestCase
   {
  @@ -142,6 +140,25 @@
           assertEquals(
               "A formatted date: 24/12/66",
               page.getMessages().format("using-date-format", d));
  +    }
  +
  +    public void testExceptionWithMessage()
  +    {
  +        IPage page = createPage(MOCK1, Locale.ENGLISH);
   
  +        assertEquals(
  +            "Exception: foo must not be null",
  +            page.getMessages().format(
  +                "exception",
  +                new NullPointerException("foo must not be null")));
  +    }
  +
  +    public void testExceptionWithBlankMessage()
  +    {
  +        IPage page = createPage(MOCK1, Locale.ENGLISH);
  +
  +        assertEquals(
  +            "Exception: java.lang.NullPointerException",
  +            page.getMessages().format("exception", new NullPointerException()));
       }
   }
  
  
  
  1.2.4.1   +3 -3      jakarta-tapestry/junit/src/org/apache/tapestry/junit/MockPage1.properties
  
  Index: MockPage1.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/junit/src/org/apache/tapestry/junit/MockPage1.properties,v
  retrieving revision 1.2
  retrieving revision 1.2.4.1
  diff -u -r1.2 -r1.2.4.1
  --- MockPage1.properties	28 May 2003 14:53:53 -0000	1.2
  +++ MockPage1.properties	30 Jun 2004 15:34:51 -0000	1.2.4.1
  @@ -1,8 +1,8 @@
  -# $Id$
  -
   only-in-base=BASE1
   overwritten-in-language=BASE2
   overwritten-in-country=BASE3
   overwritten-in-variant=BASE4
   
  -using-date-format=A formatted date: {0,date,short}
  \ No newline at end of file
  +using-date-format=A formatted date: {0,date,short}
  +
  +exception=Exception: {0}
  \ No newline at end of file
  
  
  
  No                   revision
  No                   revision
  1.4.2.1   +5 -1      jakarta-tapestry/framework/src/org/apache/tapestry/Attic/IMessages.java
  
  Index: IMessages.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/Attic/IMessages.java,v
  retrieving revision 1.4
  retrieving revision 1.4.2.1
  diff -u -r1.4 -r1.4.2.1
  --- IMessages.java	19 Feb 2004 17:37:36 -0000	1.4
  +++ IMessages.java	30 Jun 2004 15:34:51 -0000	1.4.2.1
  @@ -25,7 +25,6 @@
    * @see org.apache.tapestry.engine.IComponentMessagesSource
    * 
    * @author Howard Lewis Ship
  - * @version $Id$
    * @since 2.0.4
    *
    */
  @@ -56,6 +55,11 @@
       /**
        * Formats a string, using
        * {@link java.text.MessageFormat#format(java.lang.String, java.lang.Object[])}.
  +     * 
  +     * <p>
  +     * In addition, special processing occurs for any of the arguments that
  +     * inherit from {@link Throwable}: such arguments are replaced with the Throwable's message
  +     * (if non blank), or the Throwable's class name (if the message is blank).
        *
        * @param key the key used to obtain a localized pattern using
        * {@link #getMessage(String)}
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org