Coverage Report - org.apache.tapestry5.corelib.pages.PropertyDisplayBlocks
 
Classes in this File Line Coverage Branch Coverage Complexity
PropertyDisplayBlocks
100%
8/8
50%
1/2
0
PropertyDisplayBlocks$1
100%
5/5
75%
3/4
0
 
 1  
 // Copyright 2007, 2008 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.tapestry5.corelib.pages;
 16  
 
 17  
 import org.apache.tapestry5.MarkupWriter;
 18  
 import org.apache.tapestry5.Renderable;
 19  
 import org.apache.tapestry5.annotations.Environmental;
 20  
 import org.apache.tapestry5.internal.TapestryInternalUtils;
 21  
 import org.apache.tapestry5.ioc.annotations.Inject;
 22  
 import org.apache.tapestry5.services.PropertyOutputContext;
 23  
 
 24  
 import java.text.DateFormat;
 25  
 import java.util.Locale;
 26  
 
 27  8
 public class PropertyDisplayBlocks
 28  
 {
 29  
     @Environmental
 30  
     private PropertyOutputContext context;
 31  
 
 32  
     @Inject
 33  
     private Locale locale;
 34  
 
 35  2
     private final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
 36  
 
 37  
     public String getConvertedEnumValue()
 38  
     {
 39  292
         Enum value = (Enum) context.getPropertyValue();
 40  
 
 41  292
         if (value == null) return null;
 42  
 
 43  292
         return TapestryInternalUtils.getLabelForEnum(context.getMessages(), value);
 44  
     }
 45  
 
 46  
     public DateFormat getDateFormat()
 47  
     {
 48  2
         return dateFormat;
 49  
     }
 50  
 
 51  
     public PropertyOutputContext getContext()
 52  
     {
 53  8
         return context;
 54  
     }
 55  
 
 56  
     public Renderable getPasswordRenderer()
 57  
     {
 58  6
         return new Renderable()
 59  
         {
 60  6
             public void render(MarkupWriter writer)
 61  
             {
 62  
 
 63  6
                 Object value = context.getPropertyValue();
 64  
 
 65  6
                 int length = value == null ? 0 : value.toString().length();
 66  
 
 67  6
                 for (int i = 0; i < length; i++) writer.write("*");
 68  6
             }
 69  
         };
 70  
     }
 71  
 }