1   /**
2    * Copyright 2005-2006 the original author or authors.
3    *
4    * Licensed under the Gnu General Pubic License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    *
8    *      http://www.opensource.org/licenses/gpl-license.php
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13   * See the Gnu General Public License for more details.
14   */
15  package org.figure8.join.util;
16  
17  import org.apache.struts.util.MessageResources;
18  
19  import java.util.Locale;
20  /**
21   * This is a stub implementation of Struts <code>MessageResources</code>
22   * resources bundle. This stub is useful for quick test of Join Strus forms
23   * validation (so we don't need to launch the Struts machinery for testing !)
24   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
25   * @version $Revision: 1.2 $
26   */
27  public class MessageResourcesStub extends MessageResources{
28  
29     // Attributes ---------------------------------------------------------------
30  
31     /** This resource bundle name */
32     private String name;
33  
34  
35     // Constructors -------------------------------------------------------------
36  
37     /**
38      * Creates a new instance of MessageResourcesStub with a name
39      * @param name The name of this resource bundle.
40      */
41     public MessageResourcesStub(String name){
42        // Call super() with null as factory.
43        super(null, name);
44        this.name = name;
45     }
46  
47  
48     // Public -------------------------------------------------------------------
49  
50     /** @return The name of this resource bundle stub */
51     public String getName(){
52        return name;
53     }
54  
55  
56     // Implementation of MessageResources ---------------------------------------
57  
58     /**
59      * Returns a text message for the specified key, for the default Locale.
60      * As a stub implementation, this method just return the key as is if the key
61      * is denoting a Gui label resource and <code>key:{0}</code> if key is denoting
62      * an error message resource. This allow assertions to check error type against
63      * Gui label resource.
64      * @param locale The requested message Locale, or <code>null</code> for
65      * the system default Locale
66      * @param key The message key to look up
67      */
68     public String getMessage(Locale locale, String key){
69        if (key.equals("pattern.date.stringtodate"))
70           return "dd/MM/yyyy";
71        if (key.startsWith("errors."))
72           return key + ":{0}";
73        return key;
74     }
75  }