Clover coverage report - Code Coverage for tapestry release 3.1-alpha-1
Coverage timestamp: Mon Feb 21 2005 09:16:14 EST
file stats: LOC: 108   Methods: 7
NCLOC: 46   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
LocalizedPropertySource.java 0% 0% 0% 0%
coverage
 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.Locale;
 18   
 
 19   
 import org.apache.hivemind.util.LocalizedNameGenerator;
 20   
 import org.apache.tapestry.engine.IPropertySource;
 21   
 
 22   
 /**
 23   
  *  A PropertySource extending the DelegatingPropertySources and adding the 
 24   
  *  capability of searching for localized versions of the desired property.
 25   
  *  Useful when peoperties related to localization are needed.
 26   
  * 
 27   
  *  @author mindbridge
 28   
  *  @since 3.0
 29   
  */
 30   
 public class LocalizedPropertySource extends DelegatingPropertySource
 31   
 {
 32   
     private Locale _locale;
 33   
     
 34   
     /**
 35   
      *  Creates a LocalizedPropertySource with the default locale
 36   
      */
 37  0
     public LocalizedPropertySource()
 38   
     {
 39  0
         this(Locale.getDefault());
 40   
     }
 41   
 
 42   
     /**
 43   
      *  Creates a LocalizedPropertySource with the provided locale
 44   
      */
 45  0
     public LocalizedPropertySource(Locale locale)
 46   
     {
 47  0
         super();
 48  0
         setLocale(locale);
 49   
     }
 50   
 
 51   
     /**
 52   
      *  Creates a LocalizedPropertySource with the default locale and the provided delegate
 53   
      */
 54  0
     public LocalizedPropertySource(IPropertySource delegate)
 55   
     {
 56  0
         this(Locale.getDefault(), delegate);
 57   
     }
 58   
 
 59   
     /**
 60   
      *  Creates a LocalizedPropertySource with the provided locale and delegate
 61   
      */
 62  0
     public LocalizedPropertySource(Locale locale, IPropertySource delegate)
 63   
     {
 64  0
         super(delegate);
 65  0
         setLocale(locale);
 66   
     }
 67   
 
 68   
 
 69   
     /**
 70   
      * @return the locale currently used 
 71   
      */
 72  0
     public Locale getLocale()
 73   
     {
 74  0
         return _locale;
 75   
     }
 76   
 
 77   
     /**
 78   
      * @param locale the locale currently used
 79   
      */
 80  0
     public void setLocale(Locale locale)
 81   
     {
 82  0
         _locale = locale;
 83   
     }
 84   
 
 85   
     
 86   
     /**
 87   
      *  Examines the properties localized using the provided locale in the order
 88   
      *  of more specific to more general and returns the first that has a value. 
 89   
      *  @see org.apache.tapestry.util.DelegatingPropertySource#getPropertyValue(java.lang.String)
 90   
      */
 91  0
     public String getPropertyValue(String propertyName)
 92   
     {
 93  0
         LocalizedNameGenerator generator = new LocalizedNameGenerator(propertyName, getLocale(), "");
 94   
 
 95  0
         while (generator.more())
 96   
         {
 97  0
             String candidateName = generator.next();
 98   
 
 99  0
             String value = super.getPropertyValue(candidateName); 
 100  0
             if (value != null)
 101  0
                 return value;
 102   
         }
 103   
 
 104  0
         return null;
 105   
     }
 106   
 
 107   
 }
 108