KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > util > MessageUtilities


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. The ASF licenses this file to You
4  * under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License. For additional information regarding
15  * copyright in this work, please see the NOTICE file in the top level
16  * directory of this distribution.
17  */

18
19 package org.apache.roller.util;
20
21 import java.text.MessageFormat JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.ResourceBundle JavaDoc;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27
28 /**
29  * A utilities class for interacting with the Roller resource bundles.
30  */

31 public class MessageUtilities {
32     
33     private static Log log = LogFactory.getLog(MessageUtilities.class);
34     
35     private static final ResourceBundle JavaDoc bundle =
36             ResourceBundle.getBundle("ApplicationResources");
37     
38     
39     // no instantiation
40
private MessageUtilities() {
41     }
42     
43     
44     /**
45      * Get a message from the bundle.
46      */

47     public static final String JavaDoc getString(String JavaDoc key) {
48         
49         try {
50             return bundle.getString(key);
51         } catch (Exception JavaDoc e) {
52             // send a warning in the logs
53
log.warn("Error getting key "+key, e);
54             return key;
55         }
56     }
57     
58     
59     /**
60      * Get a message from the bundle and substitute the given args into
61      * the message contents.
62      */

63     public static final String JavaDoc getString(String JavaDoc key, List JavaDoc args) {
64         
65         try {
66             String JavaDoc msg = bundle.getString(key);
67             return MessageFormat.format(msg, args.toArray());
68         } catch (Exception JavaDoc e) {
69             // send a warning in the logs
70
log.warn("Error getting key "+key, e);
71             return key;
72         }
73     }
74     
75     
76     /**
77      * Get a message from the bundle and substitute the given args into
78      * the message contents.
79      */

80     public static final String JavaDoc getString(String JavaDoc key, Object JavaDoc[] args) {
81         
82         try {
83             String JavaDoc msg = bundle.getString(key);
84             return MessageFormat.format(msg, args);
85         } catch (Exception JavaDoc e) {
86             // send a warning in the logs
87
log.warn("Error getting key "+key, e);
88             return key;
89         }
90     }
91     
92 }
93
Popular Tags