View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/util/MessageResourcesInternal.java,v 1.9 2004/08/18 12:26:09 hkollmann Exp $
3    * $Revision: 1.9 $
4    * $Date: 2004/08/18 12:26:09 $
5    *
6    * DbForms - a Rapid Application Development Framework
7    * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8    *
9    * This library is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU Lesser General Public
11   * License as published by the Free Software Foundation; either
12   * version 2.1 of the License, or (at your option) any later version.
13   *
14   * This library is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this library; if not, write to the Free Software
21   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   */
23  
24  package org.dbforms.util;
25  
26  import java.util.Locale;
27  
28  
29  
30  /***
31   * handling of internal messages
32   *
33   * @author Henner Kollmann
34   */
35  public class MessageResourcesInternal {
36     private static String          RESOURCE = "org.dbforms.resources.messages";
37     private static MessageResource msgRes = new MessageResource(RESOURCE);
38  
39     /***
40      * Get the message from ResourceBundle.  If not present, return the
41      * defaultMsg at the place of a null.  To avoid to doing this condition
42      * everywhere in the code ...
43      *
44      * @param msgString </code> : Message key to lookup.
45      * @param localeLocale </code> : Locale object to map message with good
46      *        ResourceBundle.
47      * @param defaultMsgString </code> : String to return if the lookup message
48      *        key is not found.
49      *
50      * @return <code>String</code> : Message resolve.
51      */
52     public static String getMessage(String msg,
53                                     Locale locale,
54                                     String defaultMsg) {
55        String s = getMessage(msg, locale);
56  
57        if (Util.isNull(s)) {
58           s = defaultMsg;
59        }
60  
61        return s;
62     }
63  
64  
65     /***
66      * Retrieve message from ResourceBundle.  If the ResourceBundle is not yet
67      * cached, cache it and retreive message.
68      *
69      * @param msgString </code> : Message key to lookup.
70      * @param locLocale </code> : Locale object to map message with good
71      *        ResourceBundle.
72      *
73      * @return <code>String</code> : Message resolve, null if not found.
74      */
75     public static String getMessage(String msg,
76                                     Locale loc) {
77        // first look in custom resources
78        String res = MessageResources.getMessage(msg, loc);
79  
80        if (res == null) {
81           res = msgRes.getMessage(msg, loc);
82        }
83  
84        return res;
85     }
86  
87  
88     /***
89      * Retrieve message from ResourceBundle and replace parameter "{x}" with
90      * values in parms array.
91      *
92      * @param msgString </code> : Message key to lookup.
93      * @param locLocale </code> : Locale object to map message with good
94      *        ResourceBundle.
95      * @param parmsString[] </code> : Parameters to replace "{x}" in message .
96      *
97      * @return <code>String</code> : Message resolve with parameter replaced,
98      *         null if message key not found.
99      */
100    public static String getMessage(String   msg,
101                                    Locale   loc,
102                                    String[] parms) {
103       // first look in custom resources
104       String res = MessageResources.getMessage(msg, loc, parms);
105 
106       if (res == null) {
107          res = msgRes.getMessage(msg, loc, parms);
108       }
109 
110       return res;
111    }
112 }