01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /**
19: * @author Dennis Ushakov
20: * @version $Revision$
21: */package javax.accessibility;
22:
23: import java.util.Locale;
24: import java.util.MissingResourceException;
25: import java.util.ResourceBundle;
26:
27: public abstract class AccessibleBundle {
28: protected String key;
29: private final String ACCESSIBLE_RESOURSE_BUNDLE = "javax.accessibility.AccessibleResourceBundle"; //$NON-NLS-1$
30:
31: public String toDisplayString() {
32: return displayString(ACCESSIBLE_RESOURSE_BUNDLE, null);
33: }
34:
35: public String toDisplayString(final Locale locale) {
36: return displayString(ACCESSIBLE_RESOURSE_BUNDLE, locale);
37: }
38:
39: protected String toDisplayString(final String resourceBundleName,
40: final Locale locale) {
41: return displayString(resourceBundleName, locale);
42: }
43:
44: @Override
45: public String toString() {
46: return toDisplayString();
47: }
48:
49: private String displayString(final String bundleName,
50: final Locale locale) {
51: try {
52: if (locale == null) {
53: return ResourceBundle.getBundle(bundleName).getString(
54: key);
55: }
56: return ResourceBundle.getBundle(bundleName, locale)
57: .getString(key);
58: } catch (MissingResourceException e) {
59: return key;
60: }
61: }
62: }
|