01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. The ASF licenses this file to You
04: * under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
22: import java.util.List;
23: import java.util.ResourceBundle;
24: import org.apache.commons.logging.Log;
25: import org.apache.commons.logging.LogFactory;
26:
27: /**
28: * A utilities class for interacting with the Roller resource bundles.
29: */
30: public class MessageUtilities {
31:
32: private static Log log = LogFactory.getLog(MessageUtilities.class);
33:
34: private static final ResourceBundle bundle = ResourceBundle
35: .getBundle("ApplicationResources");
36:
37: // no instantiation
38: private MessageUtilities() {
39: }
40:
41: /**
42: * Get a message from the bundle.
43: */
44: public static final String getString(String key) {
45:
46: try {
47: return bundle.getString(key);
48: } catch (Exception e) {
49: // send a warning in the logs
50: log.warn("Error getting key " + key, e);
51: return key;
52: }
53: }
54:
55: /**
56: * Get a message from the bundle and substitute the given args into
57: * the message contents.
58: */
59: public static final String getString(String key, List args) {
60:
61: try {
62: String msg = bundle.getString(key);
63: return MessageFormat.format(msg, args.toArray());
64: } catch (Exception e) {
65: // send a warning in the logs
66: log.warn("Error getting key " + key, e);
67: return key;
68: }
69: }
70:
71: /**
72: * Get a message from the bundle and substitute the given args into
73: * the message contents.
74: */
75: public static final String getString(String key, Object[] args) {
76:
77: try {
78: String msg = bundle.getString(key);
79: return MessageFormat.format(msg, args);
80: } catch (Exception e) {
81: // send a warning in the logs
82: log.warn("Error getting key " + key, e);
83: return key;
84: }
85: }
86:
87: }
|