Clover coverage report - Code Coverage for tapestry release 4.0-beta-12
Coverage timestamp: Sun Oct 30 2005 16:22:01 EST
file stats: LOC: 72   Methods: 2
NCLOC: 26   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
LocalizedPropertySource.java 100% 100% 100% 100%
coverage
 1    // Copyright 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.services.impl;
 16   
 17    import java.util.Locale;
 18   
 19    import org.apache.hivemind.util.Defense;
 20    import org.apache.hivemind.util.LocalizedNameGenerator;
 21    import org.apache.tapestry.engine.IPropertySource;
 22   
 23    /**
 24    * Wraps around a {@link org.apache.tapestry.engine.IPropertySource}to query a series of localized
 25    * keys.
 26    * <p>
 27    * This is much simpler than the old {@link org.apache.tapestry.util.LocalizedPropertySource}, and
 28    * allows the locale to be specified on a thread-safe, per-invocation basis.
 29    *
 30    * @author Howard M. Lewis Ship
 31    * @since 4.0
 32    */
 33    public class LocalizedPropertySource
 34    {
 35    private IPropertySource _source;
 36   
 37  150 public LocalizedPropertySource(IPropertySource source)
 38    {
 39  150 Defense.notNull(source, "source");
 40   
 41  150 _source = source;
 42    }
 43   
 44    /**
 45    * Get the property from the source, trying different variations of propertyName (adding
 46    * suffixes).
 47    *
 48    * @param propertyName
 49    * the base property name to search with.
 50    * @param local
 51    * the Locale used to generate suffixes (may be null).
 52    */
 53   
 54  221 public String getPropertyValue(String propertyName, Locale locale)
 55    {
 56  221 Defense.notNull(propertyName, "propertyName");
 57   
 58  221 LocalizedNameGenerator g = new LocalizedNameGenerator(propertyName, locale, "");
 59   
 60  221 while (g.more())
 61    {
 62  265 String localizedName = g.next();
 63   
 64  265 String result = _source.getPropertyValue(localizedName);
 65   
 66  265 if (result != null)
 67  13 return result;
 68    }
 69   
 70  208 return null;
 71    }
 72    }