1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
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 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| public class LocalizedStringRender implements IRender |
35 |
| { |
36 |
| private IComponent _component; |
37 |
| |
38 |
| private String _key; |
39 |
| |
40 |
| private Map _attributes; |
41 |
| |
42 |
| private String _value; |
43 |
| |
44 |
| private boolean _raw; |
45 |
| |
46 |
28
| public LocalizedStringRender(IComponent component, LocalizationToken token)
|
47 |
| { |
48 |
28
| _component = component;
|
49 |
28
| _key = token.getKey();
|
50 |
28
| _raw = token.isRaw();
|
51 |
28
| _attributes = token.getAttributes();
|
52 |
| } |
53 |
| |
54 |
34
| public void render(IMarkupWriter writer, IRequestCycle cycle)
|
55 |
| { |
56 |
34
| if (cycle.isRewinding())
|
57 |
0
| return;
|
58 |
| |
59 |
34
| if (_attributes != null)
|
60 |
| { |
61 |
2
| writer.begin("span");
|
62 |
| |
63 |
2
| Iterator i = _attributes.entrySet().iterator();
|
64 |
| |
65 |
2
| while (i.hasNext())
|
66 |
| { |
67 |
2
| Map.Entry entry = (Map.Entry) i.next();
|
68 |
2
| String attributeName = (String) entry.getKey();
|
69 |
2
| String attributeValue = (String) entry.getValue();
|
70 |
| |
71 |
2
| writer.attribute(attributeName, attributeValue);
|
72 |
| } |
73 |
| } |
74 |
| |
75 |
34
| if (_value == null)
|
76 |
28
| _value = _component.getMessages().getMessage(_key);
|
77 |
| |
78 |
34
| writer.print(_value, _raw);
|
79 |
| |
80 |
34
| if (_attributes != null)
|
81 |
2
| writer.end();
|
82 |
| } |
83 |
| |
84 |
0
| public String toString()
|
85 |
| { |
86 |
0
| ToStringBuilder builder = new ToStringBuilder(this);
|
87 |
| |
88 |
0
| builder.append("component", _component);
|
89 |
0
| builder.append("key", _key);
|
90 |
0
| builder.append("raw", _raw);
|
91 |
0
| builder.append("attributes", _attributes);
|
92 |
| |
93 |
0
| return builder.toString();
|
94 |
| } |
95 |
| |
96 |
| } |