Coverage Report - org.apache.tapestry.services.impl.LocalizedStringRender
 
Classes in this File Line Coverage Branch Coverage Complexity
LocalizedStringRender
0%
0/30
0%
0/12
3.333
 
 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.services.impl;
 16  
 
 17  
 import java.util.Iterator;
 18  
 import java.util.Map;
 19  
 
 20  
 import org.apache.hivemind.util.ToStringBuilder;
 21  
 import org.apache.tapestry.IComponent;
 22  
 import org.apache.tapestry.IMarkupWriter;
 23  
 import org.apache.tapestry.IRender;
 24  
 import org.apache.tapestry.IRequestCycle;
 25  
 import org.apache.tapestry.parse.LocalizationToken;
 26  
 import org.apache.tapestry.parse.TextToken;
 27  
 
 28  
 /**
 29  
  * A class used with invisible localizations. Constructed from a {@link TextToken}.
 30  
  * 
 31  
  * @author Howard Lewis Ship
 32  
  * @since 3.0
 33  
  */
 34  
 
 35  
 public class LocalizedStringRender implements IRender
 36  
 {
 37  
     private IComponent _component;
 38  
 
 39  
     private String _key;
 40  
 
 41  
     private Map _attributes;
 42  
 
 43  
     private String _value;
 44  
 
 45  
     private boolean _raw;
 46  
     
 47  
     private String _tag;
 48  
 
 49  
     public LocalizedStringRender(IComponent component, LocalizationToken token)
 50  0
     {
 51  0
         _component = component;
 52  0
         _key = token.getKey();
 53  0
         _raw = token.isRaw();
 54  0
         _tag = token.getTag();
 55  0
         _attributes = token.getAttributes();
 56  0
     }
 57  
 
 58  
     public void render(IMarkupWriter writer, IRequestCycle cycle)
 59  
     {
 60  0
         if (cycle.isRewinding())
 61  0
             return;
 62  
 
 63  0
         if (_attributes != null)
 64  
         {
 65  0
             writer.begin(_tag == null ? "span" : _tag);
 66  
             
 67  0
             Iterator i = _attributes.entrySet().iterator();
 68  
 
 69  0
             while (i.hasNext())
 70  
             {
 71  0
                 Map.Entry entry = (Map.Entry) i.next();
 72  0
                 String attributeName = (String) entry.getKey();
 73  0
                 String attributeValue = (String) entry.getValue();
 74  
 
 75  0
                 writer.attribute(attributeName, attributeValue);
 76  0
             }
 77  
         }
 78  
 
 79  0
         if (_value == null)
 80  0
             _value = _component.getMessages().getMessage(_key);
 81  
 
 82  0
         writer.print(_value, _raw);
 83  
         
 84  0
         if (_attributes != null)
 85  0
             writer.end();
 86  0
     }
 87  
 
 88  
     public String toString()
 89  
     {
 90  0
         ToStringBuilder builder = new ToStringBuilder(this);
 91  
 
 92  0
         builder.append("component", _component);
 93  0
         builder.append("key", _key);
 94  0
         builder.append("raw", _raw);
 95  0
         builder.append("attributes", _attributes);
 96  
 
 97  0
         return builder.toString();
 98  
     }
 99  
 
 100  
 }