01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/jsf/widgets/src/java/org/theospi/jsf/util/ConfigurationResource.java $
03: * $Id: ConfigurationResource.java 10835 2006-06-17 03:25:03Z lance@indiana.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.theospi.jsf.util;
21:
22: import java.util.Enumeration;
23: import java.util.Locale;
24: import java.util.ResourceBundle;
25:
26: /**
27: * Thin wrapper for lookup of configuration of resources.
28: * @author Ed Smiley
29: * @version $Id: ConfigurationResource.java 10835 2006-06-17 03:25:03Z lance@indiana.edu $
30: */
31: public class ConfigurationResource {
32: private ResourceBundle configurationBundle;
33: private final String CONFIG_PACKAGE = "org.theospi.jsf";
34:
35: /**
36: * Get resources for default locale.
37: */
38: public ConfigurationResource() {
39: configurationBundle = ResourceBundle.getBundle(CONFIG_PACKAGE
40: + "." + "Configuration");
41: }
42:
43: /**
44: * Get resources for specific locale.
45: * @param locale Locale
46: */
47: public ConfigurationResource(Locale locale) {
48: configurationBundle = ResourceBundle.getBundle(CONFIG_PACKAGE
49: + "." + "Configuration", locale);
50: }
51:
52: /**
53: * Look up key/value
54: * @param key String
55: * @return String value for key, or empty string if not found
56: */
57: public String get(String key) {
58: try {
59: return configurationBundle.getString(key);
60: } catch (Exception ex) {
61: return "";
62: }
63: }
64:
65: /**
66: * Return true only if this key exists.
67: * @param key String
68: * @return boolean
69: */
70: public boolean exists(String key) {
71: try {
72: configurationBundle.getString(key);
73: return true;
74: } catch (Exception ex) {
75: return false;
76: }
77: }
78:
79: public static void main(String[] args) {
80: ConfigurationResource cr = new ConfigurationResource();
81: Enumeration enumeration = cr.configurationBundle.getKeys();
82: while (enumeration.hasMoreElements()) {
83: String key = (String) enumeration.nextElement();
84: String value = cr.get(key);
85: System.out.println(key + "=" + value);
86: }
87: System.out.println("xxx exists" + "=" + cr.exists("xxx"));
88: System.out.println("xxx" + "=" + cr.get("xxx"));
89: System.out.println("inputRichText_none exists" + "="
90: + cr.exists("inputRichText_none"));
91: System.out.println("inputRichText_none" + "="
92: + cr.get("inputRichText_none"));
93: System.out.println("inputRichText_small exists" + "="
94: + cr.exists("inputRichText_small"));
95: System.out.println("inputRichText_small" + "="
96: + cr.get("inputRichText_small"));
97: }
98:
99: }
|