KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > util > ResourceBundlePropertySource


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.util;
16
17 import java.util.MissingResourceException JavaDoc;
18 import java.util.ResourceBundle JavaDoc;
19
20 import org.apache.tapestry.engine.IPropertySource;
21
22 /**
23  * A property source that is based on a {@link java.util.ResourceBundle}.
24  *
25  * @author Howard Lewis Ship
26  * @since 3.0
27  *
28  **/

29
30 public class ResourceBundlePropertySource implements IPropertySource
31 {
32     private ResourceBundle JavaDoc _bundle;
33
34     public ResourceBundlePropertySource(ResourceBundle JavaDoc bundle)
35     {
36         _bundle = bundle;
37     }
38
39     /**
40      * Gets the value from the bundle by invoking
41      * {@link ResourceBundle#getString(java.lang.String)}. If
42      * the bundle does not contain the key (that is, it it
43      * throws {@link java.util.MissingResourceException}), then
44      * null is returned.
45      *
46      **/

47     
48     public String JavaDoc getPropertyValue(String JavaDoc propertyName)
49     {
50         try
51         {
52             return _bundle.getString(propertyName);
53         }
54         catch (MissingResourceException JavaDoc ex)
55         {
56             return null;
57         }
58     }
59
60 }
61
Popular Tags