1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.taglib.util;
24  
25  import com.liferay.portal.kernel.servlet.StringServletResponse;
26  import com.liferay.portal.model.Layout;
27  import com.liferay.taglib.portlet.ActionURLTag;
28  import com.liferay.taglib.portletext.IconBackTag;
29  import com.liferay.taglib.portletext.IconCloseTag;
30  import com.liferay.taglib.portletext.IconConfigurationTag;
31  import com.liferay.taglib.portletext.IconEditDefaultsTag;
32  import com.liferay.taglib.portletext.IconEditGuestTag;
33  import com.liferay.taglib.portletext.IconEditTag;
34  import com.liferay.taglib.portletext.IconHelpTag;
35  import com.liferay.taglib.portletext.IconMaximizeTag;
36  import com.liferay.taglib.portletext.IconMinimizeTag;
37  import com.liferay.taglib.portletext.IconPortletCssTag;
38  import com.liferay.taglib.portletext.IconPortletTag;
39  import com.liferay.taglib.portletext.IconPrintTag;
40  import com.liferay.taglib.portletext.IconRefreshTag;
41  import com.liferay.taglib.portletext.RuntimeTag;
42  import com.liferay.taglib.portletext.TitleTag;
43  import com.liferay.taglib.security.DoAsURLTag;
44  import com.liferay.taglib.security.PermissionsURLTag;
45  import com.liferay.taglib.theme.LayoutIconTag;
46  import com.liferay.taglib.theme.MetaTagsTag;
47  import com.liferay.taglib.theme.WrapPortletTag;
48  import com.liferay.taglib.ui.JournalContentSearchTag;
49  import com.liferay.taglib.ui.LanguageTag;
50  import com.liferay.taglib.ui.MyPlacesTag;
51  import com.liferay.taglib.ui.PngImageTag;
52  import com.liferay.taglib.ui.SearchTag;
53  import com.liferay.taglib.ui.ToggleTag;
54  import com.liferay.util.HttpUtil;
55  
56  import java.util.Map;
57  
58  import javax.servlet.RequestDispatcher;
59  import javax.servlet.ServletContext;
60  import javax.servlet.http.HttpServletRequest;
61  import javax.servlet.jsp.PageContext;
62  
63  /**
64   * <a href="VelocityTaglib.java.html"><b><i>View Source</i></b></a>
65   *
66   * @author Brian Wing Shun Chan
67   *
68   */
69  public class VelocityTaglib {
70  
71      public VelocityTaglib() {
72      }
73  
74      public VelocityTaglib(
75          ServletContext ctx, HttpServletRequest req, StringServletResponse res,
76          PageContext pageContext) {
77  
78          init(ctx, req, res, pageContext);
79      }
80  
81      public VelocityTaglib init(
82          ServletContext ctx, HttpServletRequest req, StringServletResponse res,
83          PageContext pageContext) {
84  
85          _ctx = ctx;
86          _req = req;
87          _res = res;
88          _pageContext = pageContext;
89  
90          return this;
91      }
92  
93      public String actionURL(
94              String windowState, String portletMode, Boolean secure,
95              String portletName, Boolean anchor, Boolean encrypt,
96              long doAsUserId, Boolean portletConfiguration, String queryString)
97          throws Exception {
98  
99          Map params = HttpUtil.parameterMapFromString(queryString);
100 
101         return ActionURLTag.doTag(
102             true, windowState, portletMode, null, null, secure, portletName,
103             anchor, encrypt, doAsUserId, portletConfiguration, params, false,
104             _pageContext);
105     }
106 
107     public String doAsURL(long doAsUserId) throws Exception {
108         return DoAsURLTag.doTag(doAsUserId, null, false, _pageContext);
109     }
110 
111     public String iconBack() throws Exception {
112         _res.recycle();
113 
114         IconBackTag.doTag(_ctx, _req, _res);
115 
116         return _res.getString();
117     }
118 
119     public String iconBack(String page) throws Exception {
120         _res.recycle();
121 
122         IconBackTag.doTag(page, _ctx, _req, _res);
123 
124         return _res.getString();
125     }
126 
127     public String iconClose() throws Exception {
128         _res.recycle();
129 
130         IconCloseTag.doTag(_ctx, _req, _res);
131 
132         return _res.getString();
133     }
134 
135     public String iconClose(String page) throws Exception {
136         _res.recycle();
137 
138         IconCloseTag.doTag(page, _ctx, _req, _res);
139 
140         return _res.getString();
141     }
142 
143     public String iconConfiguration() throws Exception {
144         _res.recycle();
145 
146         IconConfigurationTag.doTag(_ctx, _req, _res);
147 
148         return _res.getString();
149     }
150 
151     public String iconConfiguration(String page) throws Exception {
152         _res.recycle();
153 
154         IconConfigurationTag.doTag(page, _ctx, _req, _res);
155 
156         return _res.getString();
157     }
158 
159     public String iconEdit() throws Exception {
160         _res.recycle();
161 
162         IconEditTag.doTag(_ctx, _req, _res);
163 
164         return _res.getString();
165     }
166 
167     public String iconEdit(String page) throws Exception {
168         _res.recycle();
169 
170         IconEditTag.doTag(page, _ctx, _req, _res);
171 
172         return _res.getString();
173     }
174 
175     public String iconEditDefaults() throws Exception {
176         _res.recycle();
177 
178         IconEditDefaultsTag.doTag(_ctx, _req, _res);
179 
180         return _res.getString();
181     }
182 
183     public String iconEditGuest() throws Exception {
184         _res.recycle();
185 
186         IconEditGuestTag.doTag(_ctx, _req, _res);
187 
188         return _res.getString();
189     }
190 
191     public String iconEditGuest(String page) throws Exception {
192         _res.recycle();
193 
194         IconEditGuestTag.doTag(page, _ctx, _req, _res);
195 
196         return _res.getString();
197     }
198 
199     public String iconHelp() throws Exception {
200         _res.recycle();
201 
202         IconHelpTag.doTag(_ctx, _req, _res);
203 
204         return _res.getString();
205     }
206 
207     public String iconHelp(String page) throws Exception {
208         _res.recycle();
209 
210         IconHelpTag.doTag(page, _ctx, _req, _res);
211 
212         return _res.getString();
213     }
214 
215     public String iconMaximize() throws Exception {
216         _res.recycle();
217 
218         IconMaximizeTag.doTag(_ctx, _req, _res);
219 
220         return _res.getString();
221     }
222 
223     public String iconMaximize(String page) throws Exception {
224         _res.recycle();
225 
226         IconMaximizeTag.doTag(page, _ctx, _req, _res);
227 
228         return _res.getString();
229     }
230 
231     public String iconMinimize() throws Exception {
232         _res.recycle();
233 
234         IconMinimizeTag.doTag(_ctx, _req, _res);
235 
236         return _res.getString();
237     }
238 
239     public String iconMinimize(String page) throws Exception {
240         _res.recycle();
241 
242         IconMinimizeTag.doTag(page, _ctx, _req, _res);
243 
244         return _res.getString();
245     }
246 
247     public String iconPortlet() throws Exception {
248         _res.recycle();
249 
250         IconPortletTag.doTag(_ctx, _req, _res);
251 
252         return _res.getString();
253     }
254 
255     public String iconPortlet(String page) throws Exception {
256         _res.recycle();
257 
258         IconPortletTag.doTag(page, _ctx, _req, _res);
259 
260         return _res.getString();
261     }
262 
263     public String iconPortletCss() throws Exception {
264         _res.recycle();
265 
266         IconPortletCssTag.doTag(_ctx, _req, _res);
267 
268         return _res.getString();
269     }
270 
271     public String iconPortletCss(String page) throws Exception {
272         _res.recycle();
273 
274         IconPortletCssTag.doTag(page, _ctx, _req, _res);
275 
276         return _res.getString();
277     }
278 
279     public String iconPrint() throws Exception {
280         _res.recycle();
281 
282         IconPrintTag.doTag(_ctx, _req, _res);
283 
284         return _res.getString();
285     }
286 
287     public String iconPrint(String page) throws Exception {
288         _res.recycle();
289 
290         IconPrintTag.doTag(page, _ctx, _req, _res);
291 
292         return _res.getString();
293     }
294 
295     public String iconRefresh() throws Exception {
296         _res.recycle();
297 
298         IconRefreshTag.doTag(_ctx, _req, _res);
299 
300         return _res.getString();
301     }
302 
303     public String iconRefresh(String page) throws Exception {
304         _res.recycle();
305 
306         IconRefreshTag.doTag(page, _ctx, _req, _res);
307 
308         return _res.getString();
309     }
310 
311     public String include(String page) throws Exception {
312         _res.recycle();
313 
314         RequestDispatcher rd = _ctx.getRequestDispatcher(page);
315 
316         rd.include(_req, _res);
317 
318         return _res.getString();
319     }
320 
321     public String journalContentSearch() throws Exception {
322         _res.recycle();
323 
324         JournalContentSearchTag.doTag(_ctx, _req, _res);
325 
326         return _res.getString();
327     }
328 
329     public String language() throws Exception {
330         _res.recycle();
331 
332         LanguageTag.doTag(_ctx, _req, _res);
333 
334         return _res.getString();
335     }
336 
337     public String language(
338             String formName, String formAction, String name, int displayStyle)
339         throws Exception {
340 
341         _res.recycle();
342 
343         LanguageTag.doTag(
344             formName, formAction, name, null, displayStyle, _ctx, _req, _res);
345 
346         return _res.getString();
347     }
348 
349     public String language(
350             String formName, String formAction, String name,
351             String[] languageIds, int displayStyle)
352         throws Exception {
353 
354         _res.recycle();
355 
356         LanguageTag.doTag(
357             formName, formAction, name, languageIds, displayStyle, _ctx, _req,
358             _res);
359 
360         return _res.getString();
361     }
362 
363     public String language(
364             String page, String formName, String formAction, String name,
365             int displayStyle)
366         throws Exception {
367 
368         _res.recycle();
369 
370         LanguageTag.doTag(
371             page, formName, formAction, name, null, displayStyle, _ctx, _req,
372             _res);
373 
374         return _res.getString();
375     }
376 
377     public String language(
378             String page, String formName, String formAction, String name,
379             String[] languageIds, int displayStyle)
380         throws Exception {
381 
382         _res.recycle();
383 
384         LanguageTag.doTag(
385             page, formName, formAction, name, languageIds, displayStyle, _ctx,
386             _req, _res);
387 
388         return _res.getString();
389     }
390 
391     public String layoutIcon(Layout layout) throws Exception {
392         _res.recycle();
393 
394         LayoutIconTag.doTag(layout, _ctx, _req, _res);
395 
396         return _res.getString();
397     }
398 
399     public String metaTags() throws Exception {
400         _res.recycle();
401 
402         MetaTagsTag.doTag(_ctx, _req, _res);
403 
404         return _res.getString();
405     }
406 
407     public String myPlaces() throws Exception {
408         _res.recycle();
409 
410         MyPlacesTag.doTag(_ctx, _req, _res);
411 
412         return _res.getString();
413     }
414 
415     public String permissionsURL(
416             String redirect, String modelResource,
417             String modelResourceDescription, String resourcePrimKey)
418         throws Exception {
419 
420         return PermissionsURLTag.doTag(
421             redirect, modelResource, modelResourceDescription, resourcePrimKey,
422             null, false, _pageContext);
423     }
424 
425     public String pngImage(String image, String height, String width)
426         throws Exception {
427 
428         _res.recycle();
429 
430         PngImageTag.doTag(image, height, width, _ctx, _req, _res);
431 
432         return _res.getString();
433     }
434 
435     public String renderURL(
436             String windowState, String portletMode, Boolean secure,
437             String portletName, Boolean anchor, Boolean encrypt,
438             long doAsUserId, Boolean portletConfiguration, String queryString)
439         throws Exception {
440 
441         Map params = HttpUtil.parameterMapFromString(queryString);
442 
443         return ActionURLTag.doTag(
444             false, windowState, portletMode, null, null, secure, portletName,
445             anchor, encrypt, doAsUserId, portletConfiguration, params, false,
446             _pageContext);
447     }
448 
449     public String runtime(String portletName)
450         throws Exception {
451 
452         return runtime(portletName, null);
453     }
454 
455     public String runtime(String portletName, String queryString)
456         throws Exception {
457 
458         _res.recycle();
459 
460         RuntimeTag.doTag(portletName, queryString, null, _ctx, _req, _res);
461 
462         return _res.getString();
463     }
464 
465     public String runtime(
466             String portletName, String queryString, String defaultPreferences)
467         throws Exception {
468 
469         _res.recycle();
470 
471         RuntimeTag.doTag(
472             portletName, queryString, defaultPreferences, null, _ctx, _req,
473             _res);
474 
475         return _res.getString();
476     }
477 
478     public String search() throws Exception {
479         _res.recycle();
480 
481         SearchTag.doTag(_ctx, _req, _res);
482 
483         return _res.getString();
484     }
485 
486     public String title() throws Exception {
487         _res.recycle();
488 
489         TitleTag.doTag(_ctx, _req, _res);
490 
491         return _res.getString();
492     }
493 
494     public String title(boolean editable) throws Exception {
495         _res.recycle();
496 
497         TitleTag.doTag(editable, _ctx, _req, _res);
498 
499         return _res.getString();
500     }
501 
502     public String toggle(
503             String id, String onImage, String offImage, boolean defaultOn)
504         throws Exception {
505 
506         _res.recycle();
507 
508         ToggleTag.doTag(
509             id, onImage, offImage, defaultOn, null, _ctx, _req, _res);
510 
511         return _res.getString();
512     }
513 
514     public String wrapPortlet(String wrapPage, String portletPage)
515         throws Exception {
516 
517         _res.recycle();
518 
519         return WrapPortletTag.doTag(
520             wrapPage, portletPage, _ctx, _req, _res, _pageContext);
521     }
522 
523     private ServletContext _ctx;
524     private HttpServletRequest _req;
525     private StringServletResponse _res;
526     private PageContext _pageContext;
527 
528 }