View Javadoc

1   /*
2    * Copyright 2008 FatWire Corporation. All Rights Reserved.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.fatwire.gst.foundation.facade.runtag.render;
18  
19  import COM.FutureTense.Interfaces.ICS;
20  
21  import com.fatwire.gst.foundation.facade.runtag.asset.AssetList;
22  
23  import org.apache.commons.logging.Log;
24  import org.apache.commons.logging.LogFactory;
25  
26  /**
27   * Implements the RENDER.GETTEMPLATEURL tag.
28   * <p/>
29   * &lt;render:gettemplateurl [addsession="true|false"]
30   * [assembler="uri assembler shortform"] [authority="authority value"]
31   * [c="asset type"] [cid="asset id"] [container="servlet|portlet"]
32   * [context="context override"] [deptype="exists|none"] [dynamic="true|false"]
33   * [fragment="fragment value"] outstr="theURLVariable"
34   * [packedargs="stringFromPACKARGStag"] [satellite="true|false"]
35   * [scheme="scheme value"] site="site name" slotname="name of slot"
36   * tid="caller Template or CSElement id"
37   * [tname="target Template or CSElement name"]
38   * [ttype="caller Template or CSElement"] [variant="template variant name"]
39   * [wrapperpage="name of uncached wrapper page"] /&gt;
40   * <p/>
41   * [&lt;render:argument name="variable1" value="value1"/&gt;]
42   * <p/>
43   * &lt;/render:gettemplateurl&gt;
44   * 
45   * @author Tony Field
46   * @since Nov 17, 2009
47   * @author Dolf Dijkstra
48   * @since Mar 13, 2011
49   */
50  public final class GetTemplateUrl extends TagRunnerWithArguments {
51      private static Log LOG = LogFactory.getLog(GetTemplateUrl.class);
52  
53      /**
54       * 
55       */
56      public GetTemplateUrl() {
57          super("RENDER.GETTEMPLATEURL");
58      }
59  
60      /**
61       * @param s
62       */
63      public void setAsset(String s) {
64          set("ASSET", s);
65      }
66  
67      /**
68       * @param b
69       */
70      public void setAddSession(boolean b) {
71          set("ADDSESSION", b ? "TRUE" : "FALSE");
72      }
73  
74      /**
75       * @param s
76       */
77      public void setAssembler(String s) {
78          set("ASSEMBLER", s);
79          set("assembler", s);
80      }
81  
82      /**
83       * @param s
84       */
85      public void setAuthority(String s) {
86          set("AUTHORITY", s);
87      }
88  
89      /**
90       * @param s
91       */
92      public void setC(String s) {
93          set("C", s);
94      }
95  
96      /**
97       * @param s
98       */
99      public void setCid(String s) {
100         set("CID", s);
101     }
102 
103     /**
104      * @param s
105      */
106     public void setContainer(String s) {
107         set("CONTAINER", s);
108     }
109 
110     /**
111      * @param s
112      */
113     public void setContext(String s) {
114         set("CONTEXT", s);
115     }
116 
117     /**
118      * @param s
119      */
120     public void setDeptype(String s) {
121         set("DEPTYPE", s);
122     }
123 
124     /**
125      * @param b
126      */
127     public void setDynamic(boolean b) {
128         set("DYNAMIC", b ? "TRUE" : "FALSE");
129     }
130     /**
131      * @param b
132      * @deprecated use {@link #setDynamic(boolean)}.
133      */
134     public void setDynamic(String b) {
135         set("DYNAMIC", b );
136     }
137 
138     /**
139      * @param s
140      */
141     public void setFragment(String s) {
142         set("FRAGMENT", s);
143     }
144 
145     /**
146      * @param s
147      */
148     public void setOutstr(String s) {
149         set("OUTSTR", s);
150     }
151 
152     /**
153      * @param s
154      */
155     public void setPackedargs(String s) {
156         set("PACKEDARGS", s);
157     }
158 
159     /**
160      * @param b
161      */
162     public void setSatellite(boolean b) {
163         set("SATELLITE", b ? "TRUE" : "FALSE");
164     }
165 
166     /**
167      * @param b
168      * @deprecated use {@link #setSatellite(boolean)}.
169      */
170     public void setSatellite(String b) {
171         set("SATELLITE", b );
172     }
173 
174     /**
175      * @param s
176      */
177     public void setScheme(String s) {
178         set("SCHEME", s);
179     }
180 
181     /**
182      * @param s
183      */
184     public void setSite(String s) {
185         set("SITE", s);
186     }
187 
188     /**
189      * @param s
190      */
191     public void setSlotname(String s) {
192         set("SLOTNAME", s);
193     }
194 
195     /**
196      * @param s
197      */
198     public void setTid(String s) {
199         set("TID", s);
200     }
201 
202     /**
203      * @param s
204      */
205     public void setTname(String s) {
206         set("TNAME", s);
207     }
208 
209     /**
210      * @param s
211      */
212     public void setTtype(String s) {
213         set("TTYPE", s);
214     }
215 
216     /**
217      * @param s
218      */
219     public void setVariant(String s) {
220         set("VARIANT", s);
221     }
222 
223     /**
224      * @param s
225      */
226     public void setWrapperpage(String s) {
227         LOG.trace("Setting wrapper to :" + s);
228         set("wrapperpage", s);
229         set("WRAPPERPAGE", s);
230     }
231 
232     /**
233      * Shortcut constructor that sets intelligent default values. Not all values
234      * are required. Site and TID/TTYPE are auto-detected if not explicitly
235      * specified.
236      * 
237      * Outstr still needs to be set, and any nested parameters need to be set as
238      * well prior to calling execute.
239      * 
240      * @param ics
241      * @param c
242      * @param cid
243      * @param tname
244      * @param wrapper
245      * @param slotname
246      * @param site
247      * @param context
248      * @param ttype
249      * @param tid
250      * @param assembler
251      * @param authority
252      * @param container
253      * @param deptype
254      * @param dynamic
255      * @param fragment
256      * @param packedargs
257      * @param satellite
258      * @param scheme
259      * @param variant
260      */
261     public GetTemplateUrl(ICS ics, String c, String cid, String tname, String wrapper, String slotname, String site,
262             String context, String ttype, String tid, String assembler, String authority, String container,
263             String deptype, String dynamic, String fragment, String packedargs, String satellite, String scheme,
264             String variant) {
265         super("RENDER.GETTEMPLATEURL");
266 
267         setC(c);
268 
269         setCid(cid);
270 
271         setTname(tname);
272 
273         if (wrapper != null) {
274             setWrapperpage(wrapper);
275         }
276         setSlotname(slotname);
277 
278         if (site == null) {
279             site = ics.GetVar("site");
280         }
281         setSite(site);
282 
283         // too bad this can't be nuked automatically
284         setContext(context);
285 
286         if (tid == null) {
287             ttype = "Template";
288             tid = ics.GetVar("tid");
289             if (!AssetList.assetExists(ics, ttype, tid)) {
290                 ttype = "CSElement";
291                 tid = ics.GetVar("eid");
292                 if (!AssetList.assetExists(ics, ttype, tid)) {
293                     throw new IllegalArgumentException(
294                             "tid was not specified and neither tid nor eid were found valid in the variable scope");
295                 }
296             }
297         }
298 
299         setTtype(ttype);
300         setTid(tid);
301 
302         if (assembler != null) {
303             setAssembler(assembler);
304         }
305 
306         if (authority != null) {
307             setAuthority(authority);
308         }
309 
310         if (container != null) {
311             setContainer(container);
312         }
313 
314         if (deptype != null) {
315             setDeptype(deptype);
316         }
317 
318         if (dynamic != null) {
319             setDynamic("false".equalsIgnoreCase(dynamic));
320         }
321 
322         if (fragment != null) {
323             setFragment(fragment);
324         }
325 
326         if (packedargs != null) {
327             setPackedargs(packedargs);
328         }
329 
330         if (satellite != null) {
331             setSatellite("false".equalsIgnoreCase(satellite));
332         }
333 
334         if (scheme != null) {
335             setScheme(scheme);
336         }
337 
338         if (variant != null) {
339             setVariant(variant);
340         }
341     }
342 
343     /**
344      * Creates a GetTemplateUrl tag facade instance that is ready to execute
345      * unless any parameters need to be passed (like p, for instance). Note that
346      * this will auto-discover tid/ttype, and site, and it sets context to an
347      * empty string.
348      * 
349      * @param ics
350      * @param c
351      * @param cid
352      * @param tname
353      * @param wrapper optional wrapper
354      * @param slotname
355      */
356     public GetTemplateUrl(ICS ics, String c, String cid, String tname, String wrapper, String slotname) {
357         this(ics, c, cid, tname, wrapper, slotname, null, "", null, null, null, null, null, null, null, null, null,
358                 null, null, null);
359     }
360 }