|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.link; |
|
16 |
| |
|
17 |
| import org.apache.hivemind.ApplicationRuntimeException; |
|
18 |
| import org.apache.hivemind.HiveMind; |
|
19 |
| import org.apache.tapestry.IMarkupWriter; |
|
20 |
| import org.apache.tapestry.IRequestCycle; |
|
21 |
| import org.apache.tapestry.Tapestry; |
|
22 |
| import org.apache.tapestry.components.ILinkComponent; |
|
23 |
| import org.apache.tapestry.engine.ILink; |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| public class DefaultLinkRenderer implements ILinkRenderer |
|
34 |
| { |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| public static final ILinkRenderer SHARED_INSTANCE = new DefaultLinkRenderer(); |
|
40 |
| |
|
41 |
237
| public void renderLink(IMarkupWriter writer, IRequestCycle cycle, ILinkComponent linkComponent)
|
|
42 |
| { |
|
43 |
237
| IMarkupWriter wrappedWriter = null;
|
|
44 |
| |
|
45 |
237
| if (cycle.getAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME) != null)
|
|
46 |
3
| throw new ApplicationRuntimeException(LinkMessages.noNesting(), linkComponent, null,
|
|
47 |
| null); |
|
48 |
| |
|
49 |
234
| cycle.setAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME, linkComponent);
|
|
50 |
| |
|
51 |
234
| boolean hasBody = getHasBody();
|
|
52 |
| |
|
53 |
234
| boolean disabled = linkComponent.isDisabled() || cycle.isRewinding();
|
|
54 |
| |
|
55 |
234
| if (!disabled)
|
|
56 |
| { |
|
57 |
213
| if (hasBody)
|
|
58 |
201
| writer.begin(getElement());
|
|
59 |
| else |
|
60 |
12
| writer.beginEmpty(getElement());
|
|
61 |
| |
|
62 |
213
| writer.attribute(getUrlAttribute(), constructURL(linkComponent, cycle));
|
|
63 |
| |
|
64 |
213
| String target = linkComponent.getTarget();
|
|
65 |
| |
|
66 |
213
| if (HiveMind.isNonBlank(target))
|
|
67 |
9
| writer.attribute(getTargetAttribute(), target);
|
|
68 |
| |
|
69 |
213
| beforeBodyRender(writer, cycle, linkComponent);
|
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
213
| wrappedWriter = writer.getNestedWriter();
|
|
76 |
| } |
|
77 |
| else |
|
78 |
21
| wrappedWriter = writer;
|
|
79 |
| |
|
80 |
234
| if (hasBody)
|
|
81 |
216
| linkComponent.renderBody(wrappedWriter, cycle);
|
|
82 |
| |
|
83 |
234
| if (!disabled)
|
|
84 |
| { |
|
85 |
213
| afterBodyRender(writer, cycle, linkComponent);
|
|
86 |
| |
|
87 |
213
| linkComponent.renderAdditionalAttributes(writer, cycle);
|
|
88 |
| |
|
89 |
213
| if (hasBody)
|
|
90 |
| { |
|
91 |
201
| wrappedWriter.close();
|
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
201
| writer.end();
|
|
96 |
| } |
|
97 |
| else |
|
98 |
12
| writer.closeTag();
|
|
99 |
| } |
|
100 |
| |
|
101 |
234
| cycle.removeAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME);
|
|
102 |
| } |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
| |
|
109 |
| |
|
110 |
213
| protected String constructURL(ILinkComponent component, IRequestCycle cycle)
|
|
111 |
| { |
|
112 |
213
| ILink link = component.getLink(cycle);
|
|
113 |
| |
|
114 |
213
| String scheme = component.getScheme();
|
|
115 |
213
| Integer port = component.getPort();
|
|
116 |
213
| int portI = (port == null) ? 0 : port.intValue();
|
|
117 |
213
| String anchor = component.getAnchor();
|
|
118 |
| |
|
119 |
213
| return link.getURL(scheme, null, portI, anchor, true);
|
|
120 |
| } |
|
121 |
| |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
207
| protected void beforeBodyRender(IMarkupWriter writer, IRequestCycle cycle, ILinkComponent link)
|
|
130 |
| { |
|
131 |
| } |
|
132 |
| |
|
133 |
| |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
207
| protected void afterBodyRender(IMarkupWriter writer, IRequestCycle cycle, ILinkComponent link)
|
|
142 |
| { |
|
143 |
| } |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
192
| protected String getElement()
|
|
148 |
| { |
|
149 |
192
| return "a";
|
|
150 |
| } |
|
151 |
| |
|
152 |
201
| protected String getUrlAttribute()
|
|
153 |
| { |
|
154 |
201
| return "href";
|
|
155 |
| } |
|
156 |
| |
|
157 |
3
| protected String getTargetAttribute()
|
|
158 |
| { |
|
159 |
3
| return "target";
|
|
160 |
| } |
|
161 |
| |
|
162 |
210
| protected boolean getHasBody()
|
|
163 |
| { |
|
164 |
210
| return true;
|
|
165 |
| } |
|
166 |
| } |