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