001// Copyright 2004, 2005 The Apache Software Foundation 002// 003// Licensed under the Apache License, Version 2.0 (the "License"); 004// you may not use this file except in compliance with the License. 005// You may obtain a copy of the License at 006// 007// http://www.apache.org/licenses/LICENSE-2.0 008// 009// Unless required by applicable law or agreed to in writing, software 010// distributed under the License is distributed on an "AS IS" BASIS, 011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012// See the License for the specific language governing permissions and 013// limitations under the License. 014 015package org.apache.tapestry.util; 016 017import java.util.MissingResourceException; 018import java.util.ResourceBundle; 019 020import org.apache.tapestry.engine.IPropertySource; 021 022/** 023 * A property source that is based on a {@link java.util.ResourceBundle}. 024 * 025 * @author Howard Lewis Ship 026 * @since 3.0 027 * 028 **/ 029 030public class ResourceBundlePropertySource implements IPropertySource 031{ 032 private ResourceBundle _bundle; 033 034 public ResourceBundlePropertySource(ResourceBundle bundle) 035 { 036 _bundle = bundle; 037 } 038 039 /** 040 * Gets the value from the bundle by invoking 041 * {@link ResourceBundle#getString(java.lang.String)}. If 042 * the bundle does not contain the key (that is, it it 043 * throws {@link java.util.MissingResourceException}), then 044 * null is returned. 045 * 046 **/ 047 048 public String getPropertyValue(String propertyName) 049 { 050 try 051 { 052 return _bundle.getString(propertyName); 053 } 054 catch (MissingResourceException ex) 055 { 056 return null; 057 } 058 } 059 060}