1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.fatwire.gst.foundation.wra;
18
19 import COM.FutureTense.Interfaces.ICS;
20
21 import com.fatwire.assetapi.data.AssetId;
22 import com.fatwire.gst.foundation.facade.runtag.asset.AssetList;
23 import com.fatwire.gst.foundation.facade.runtag.render.GetTemplateUrl;
24
25 import org.apache.commons.lang.StringUtils;
26
27
28
29
30
31 public class WraUriBuilder {
32
33 private final GetTemplateUrl tag = new GetTemplateUrl();
34 private String tid = null;
35 private String slotname = null;
36 private String site = null;
37
38
39
40
41
42
43 public WraUriBuilder(AssetId id) {
44 this(id, "GST/Dispatcher");
45
46 }
47
48
49
50
51
52
53
54 private WraUriBuilder(AssetId id, String wrapper) {
55 tag.setWrapperpage(wrapper);
56 tag.setC(id.getType());
57 tag.setCid(Long.toString(id.getId()));
58 tag.setAssembler("wrapath");
59
60 }
61
62 public WraUriBuilder(VanityAsset wra, String wrapper) {
63 this(wra.getId(), wrapper);
64 if (StringUtils.isBlank(wra.getTemplate()))
65 throw new IllegalArgumentException("The template attribute for asset " + wra.getId().getType() + ":"
66 + wra.getId().getId() + " is not provided.");
67 tag.setTname(wra.getTemplate());
68 }
69
70
71
72
73
74
75
76
77
78 public String toURI(ICS ics) {
79 ensureTid(ics);
80 ensureSlotname();
81 ensureSite(ics);
82 ics.RemoveVar("uri__");
83 tag.setOutstr("uri__");
84 tag.execute(ics);
85 String uri = ics.GetVar("uri__");
86 ics.RemoveVar("uri__");
87 return uri;
88 }
89
90 private void ensureTid(ICS ics) {
91 String _ttype = null;
92 String _tid = null;
93 if (tid == null) {
94 _ttype = "Template";
95 _tid = ics.GetVar("tid");
96 if (!AssetList.assetExists(ics, _ttype, _tid)) {
97 _ttype = "CSElement";
98 _tid = ics.GetVar("eid");
99 if (!AssetList.assetExists(ics, _ttype, _tid)) {
100 throw new IllegalArgumentException(
101 "tid was not specified and neither tid nor eid were found valid in the variable scope");
102 }
103 }
104 }
105 ttype(_ttype);
106 tid(_tid);
107 }
108
109 private void ensureSlotname() {
110 if (slotname == null) {
111
112
113
114
115 slotname("WraUriBuilderLink");
116 }
117 }
118
119 private void ensureSite(ICS ics) {
120 if (site == null) {
121 site(ics.GetVar("site"));
122 }
123 }
124
125
126
127
128
129
130
131 public WraUriBuilder argument(String name, String value) {
132 tag.setArgument(name, value);
133 return this;
134 }
135
136
137
138
139
140 public WraUriBuilder assembler(String s) {
141 tag.setAssembler(s);
142 return this;
143 }
144
145
146
147
148
149 public WraUriBuilder authority(String s) {
150 tag.setAuthority(s);
151 return this;
152 }
153
154
155
156
157
158 public WraUriBuilder container(String s) {
159 tag.setContainer(s);
160 return this;
161 }
162
163
164
165
166
167 public WraUriBuilder dynamic(boolean s) {
168 tag.setDynamic(s);
169 return this;
170 }
171
172
173
174
175
176 public WraUriBuilder fragment(String s) {
177 tag.setFragment(s);
178 return this;
179 }
180
181
182
183
184
185 public WraUriBuilder packedargs(String s) {
186 tag.setPackedargs(s);
187 return this;
188 }
189
190
191
192
193
194 public WraUriBuilder satellite(String s) {
195 tag.setSatellite("TRUE".equalsIgnoreCase(s));
196 return this;
197 }
198
199
200
201
202
203 public WraUriBuilder scheme(String s) {
204 tag.setScheme(s);
205 return this;
206 }
207
208
209
210
211
212 public WraUriBuilder wrapper(String s) {
213 tag.setWrapperpage(s);
214 return this;
215 }
216
217 public WraUriBuilder template(String template) {
218 tag.setTname(template);
219 return this;
220 }
221
222 public WraUriBuilder tid(String tid) {
223 this.tid = tid;
224 tag.setTid(tid);
225 return this;
226 }
227
228 public WraUriBuilder ttype(String ttype) {
229 tag.setTtype(ttype);
230 return this;
231 }
232
233 public WraUriBuilder slotname(String slotname) {
234 this.slotname = slotname;
235 tag.setSlotname(slotname);
236 return this;
237 }
238
239 public WraUriBuilder site(String site) {
240 this.site = site;
241 tag.setSite(site);
242 return this;
243 }
244
245 }