1 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 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 public LocalizedStringRender(IComponent component, LocalizationToken token) 48 { 49 _component = component; 50 _key = token.getKey(); 51 _raw = token.isRaw(); 52 _attributes = token.getAttributes(); 53 } 54 55 public void render(IMarkupWriter writer, IRequestCycle cycle) 56 { 57 if (cycle.isRewinding()) 58 return; 59 60 if (_attributes != null) 61 { 62 writer.begin("span"); 63 64 Iterator i = _attributes.entrySet().iterator(); 65 66 while (i.hasNext()) 67 { 68 Map.Entry entry = (Map.Entry ) i.next(); 69 String attributeName = (String ) entry.getKey(); 70 String attributeValue = (String ) entry.getValue(); 71 72 writer.attribute(attributeName, attributeValue); 73 } 74 } 75 76 if (_value == null) 77 _value = _component.getMessages().getMessage(_key); 78 79 writer.print(_value, _raw); 80 81 if (_attributes != null) 82 writer.end(); 83 } 84 85 public String toString() 86 { 87 ToStringBuilder builder = new ToStringBuilder(this); 88 89 builder.append("component", _component); 90 builder.append("key", _key); 91 builder.append("raw", _raw); 92 builder.append("attributes", _attributes); 93 94 return builder.toString(); 95 } 96 97 } | Popular Tags |