1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.taglib.util;
21  
22  import com.liferay.portal.kernel.servlet.StringServletResponse;
23  import com.liferay.portal.kernel.util.HttpUtil;
24  import com.liferay.portal.model.Layout;
25  import com.liferay.portal.model.Portlet;
26  import com.liferay.taglib.portlet.ActionURLTag;
27  import com.liferay.taglib.portletext.IconBackTag;
28  import com.liferay.taglib.portletext.IconCloseTag;
29  import com.liferay.taglib.portletext.IconConfigurationTag;
30  import com.liferay.taglib.portletext.IconEditDefaultsTag;
31  import com.liferay.taglib.portletext.IconEditGuestTag;
32  import com.liferay.taglib.portletext.IconEditTag;
33  import com.liferay.taglib.portletext.IconHelpTag;
34  import com.liferay.taglib.portletext.IconMaximizeTag;
35  import com.liferay.taglib.portletext.IconMinimizeTag;
36  import com.liferay.taglib.portletext.IconOptionsTag;
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.security.DoAsURLTag;
43  import com.liferay.taglib.security.PermissionsURLTag;
44  import com.liferay.taglib.theme.LayoutIconTag;
45  import com.liferay.taglib.theme.MetaTagsTag;
46  import com.liferay.taglib.theme.WrapPortletTag;
47  import com.liferay.taglib.ui.JournalContentSearchTag;
48  import com.liferay.taglib.ui.LanguageTag;
49  import com.liferay.taglib.ui.MyPlacesTag;
50  import com.liferay.taglib.ui.PngImageTag;
51  import com.liferay.taglib.ui.SearchTag;
52  import com.liferay.taglib.ui.StagingTag;
53  import com.liferay.taglib.ui.ToggleTag;
54  
55  import java.util.Map;
56  
57  import javax.portlet.PortletMode;
58  import javax.portlet.PortletRequest;
59  import javax.portlet.WindowState;
60  
61  import javax.servlet.RequestDispatcher;
62  import javax.servlet.ServletContext;
63  import javax.servlet.http.HttpServletRequest;
64  import javax.servlet.jsp.PageContext;
65  
66  /**
67   * <a href="VelocityTaglib.java.html"><b><i>View Source</i></b></a>
68   *
69   * @author Brian Wing Shun Chan
70   *
71   */
72  public class VelocityTaglib {
73  
74      public VelocityTaglib() {
75      }
76  
77      public VelocityTaglib(
78          ServletContext servletContext, HttpServletRequest request,
79          StringServletResponse stringResponse, PageContext pageContext) {
80  
81          init(servletContext, request, stringResponse, pageContext);
82      }
83  
84      public VelocityTaglib init(
85          ServletContext servletContext, HttpServletRequest request,
86          StringServletResponse stringResponse, PageContext pageContext) {
87  
88          _servletContext = servletContext;
89          _request = request;
90          _stringResponse = stringResponse;
91          _pageContext = pageContext;
92  
93          return this;
94      }
95  
96      public String actionURL(String portletName, String queryString)
97          throws Exception {
98  
99          String windowState = WindowState.NORMAL.toString();
100         String portletMode = PortletMode.VIEW.toString();
101 
102         return actionURL(windowState, portletMode, portletName, queryString);
103     }
104 
105     public String actionURL(
106             String windowState, String portletMode, String portletName,
107             String queryString)
108         throws Exception {
109 
110         Boolean secure = null;
111         Boolean copyCurrentRenderParameters = null;
112         Boolean escapeXml = null;
113         String name = null;
114         Boolean anchor = null;
115         Boolean encrypt = null;
116         long doAsUserId = 0;
117         Boolean portletConfiguration = null;
118 
119         return actionURL(
120             windowState, portletMode, secure, copyCurrentRenderParameters,
121             escapeXml, name, portletName, anchor, encrypt, doAsUserId,
122             portletConfiguration, queryString);
123     }
124 
125     public String actionURL(
126             String windowState, String portletMode, Boolean secure,
127             Boolean copyCurrentRenderParameters, Boolean escapeXml, String name,
128             String portletName, Boolean anchor, Boolean encrypt,
129             long doAsUserId, Boolean portletConfiguration, String queryString)
130         throws Exception {
131 
132         String var = null;
133         String varImpl = null;
134         String resourceID = null;
135         String cacheability = null;
136         Map<String, String[]> params = HttpUtil.parameterMapFromString(
137             queryString);
138         boolean writeOutput = false;
139 
140         return ActionURLTag.doTag(
141             PortletRequest.ACTION_PHASE, windowState, portletMode, var, varImpl,
142             secure, copyCurrentRenderParameters, escapeXml, name, resourceID,
143             cacheability, portletName, anchor, encrypt, doAsUserId,
144             portletConfiguration, params, writeOutput, _pageContext);
145     }
146 
147     public String doAsURL(long doAsUserId) throws Exception {
148         return DoAsURLTag.doTag(doAsUserId, null, false, _pageContext);
149     }
150 
151     public String iconBack() throws Exception {
152         _stringResponse.recycle();
153 
154         IconBackTag.doTag(_servletContext, _request, _stringResponse);
155 
156         return _stringResponse.getString();
157     }
158 
159     public String iconBack(String page) throws Exception {
160         _stringResponse.recycle();
161 
162         IconBackTag.doTag(page, _servletContext, _request, _stringResponse);
163 
164         return _stringResponse.getString();
165     }
166 
167     public String iconClose() throws Exception {
168         _stringResponse.recycle();
169 
170         IconCloseTag.doTag(_servletContext, _request, _stringResponse);
171 
172         return _stringResponse.getString();
173     }
174 
175     public String iconClose(String page) throws Exception {
176         _stringResponse.recycle();
177 
178         IconCloseTag.doTag(page, _servletContext, _request, _stringResponse);
179 
180         return _stringResponse.getString();
181     }
182 
183     public String iconConfiguration() throws Exception {
184         _stringResponse.recycle();
185 
186         IconConfigurationTag.doTag(_servletContext, _request, _stringResponse);
187 
188         return _stringResponse.getString();
189     }
190 
191     public String iconConfiguration(String page) throws Exception {
192         _stringResponse.recycle();
193 
194         IconConfigurationTag.doTag(
195             page, _servletContext, _request, _stringResponse);
196 
197         return _stringResponse.getString();
198     }
199 
200     public String iconEdit() throws Exception {
201         _stringResponse.recycle();
202 
203         IconEditTag.doTag(_servletContext, _request, _stringResponse);
204 
205         return _stringResponse.getString();
206     }
207 
208     public String iconEdit(String page) throws Exception {
209         _stringResponse.recycle();
210 
211         IconEditTag.doTag(page, _servletContext, _request, _stringResponse);
212 
213         return _stringResponse.getString();
214     }
215 
216     public String iconEditDefaults() throws Exception {
217         _stringResponse.recycle();
218 
219         IconEditDefaultsTag.doTag(_servletContext, _request, _stringResponse);
220 
221         return _stringResponse.getString();
222     }
223 
224     public String iconEditGuest() throws Exception {
225         _stringResponse.recycle();
226 
227         IconEditGuestTag.doTag(_servletContext, _request, _stringResponse);
228 
229         return _stringResponse.getString();
230     }
231 
232     public String iconEditGuest(String page) throws Exception {
233         _stringResponse.recycle();
234 
235         IconEditGuestTag.doTag(
236             page, _servletContext, _request, _stringResponse);
237 
238         return _stringResponse.getString();
239     }
240 
241     public String iconHelp() throws Exception {
242         _stringResponse.recycle();
243 
244         IconHelpTag.doTag(_servletContext, _request, _stringResponse);
245 
246         return _stringResponse.getString();
247     }
248 
249     public String iconHelp(String page) throws Exception {
250         _stringResponse.recycle();
251 
252         IconHelpTag.doTag(page, _servletContext, _request, _stringResponse);
253 
254         return _stringResponse.getString();
255     }
256 
257     public String iconMaximize() throws Exception {
258         _stringResponse.recycle();
259 
260         IconMaximizeTag.doTag(_servletContext, _request, _stringResponse);
261 
262         return _stringResponse.getString();
263     }
264 
265     public String iconMaximize(String page) throws Exception {
266         _stringResponse.recycle();
267 
268         IconMaximizeTag.doTag(page, _servletContext, _request, _stringResponse);
269 
270         return _stringResponse.getString();
271     }
272 
273     public String iconMinimize() throws Exception {
274         _stringResponse.recycle();
275 
276         IconMinimizeTag.doTag(_servletContext, _request, _stringResponse);
277 
278         return _stringResponse.getString();
279     }
280 
281     public String iconMinimize(String page) throws Exception {
282         _stringResponse.recycle();
283 
284         IconMinimizeTag.doTag(page, _servletContext, _request, _stringResponse);
285 
286         return _stringResponse.getString();
287     }
288 
289     public String iconOptions() throws Exception {
290         _stringResponse.recycle();
291 
292         IconOptionsTag.doTag(_servletContext, _request, _stringResponse);
293 
294         return _stringResponse.getString();
295     }
296 
297     public String iconOptions(String page) throws Exception {
298         _stringResponse.recycle();
299 
300         IconOptionsTag.doTag(page, _servletContext, _request, _stringResponse);
301 
302         return _stringResponse.getString();
303     }
304 
305     public String iconPortlet() throws Exception {
306         _stringResponse.recycle();
307 
308         IconPortletTag.doTag(_servletContext, _request, _stringResponse);
309 
310         return _stringResponse.getString();
311     }
312 
313     public String iconPortlet(String page, Portlet portlet) throws Exception {
314         _stringResponse.recycle();
315 
316         IconPortletTag.doTag(
317             page, portlet, _servletContext, _request, _stringResponse);
318 
319         return _stringResponse.getString();
320     }
321 
322     public String iconPortletCss() throws Exception {
323         _stringResponse.recycle();
324 
325         IconPortletCssTag.doTag(_servletContext, _request, _stringResponse);
326 
327         return _stringResponse.getString();
328     }
329 
330     public String iconPortletCss(String page) throws Exception {
331         _stringResponse.recycle();
332 
333         IconPortletCssTag.doTag(
334             page, _servletContext, _request, _stringResponse);
335 
336         return _stringResponse.getString();
337     }
338 
339     public String iconPrint() throws Exception {
340         _stringResponse.recycle();
341 
342         IconPrintTag.doTag(_servletContext, _request, _stringResponse);
343 
344         return _stringResponse.getString();
345     }
346 
347     public String iconPrint(String page) throws Exception {
348         _stringResponse.recycle();
349 
350         IconPrintTag.doTag(page, _servletContext, _request, _stringResponse);
351 
352         return _stringResponse.getString();
353     }
354 
355     public String iconRefresh() throws Exception {
356         _stringResponse.recycle();
357 
358         IconRefreshTag.doTag(_servletContext, _request, _stringResponse);
359 
360         return _stringResponse.getString();
361     }
362 
363     public String iconRefresh(String page) throws Exception {
364         _stringResponse.recycle();
365 
366         IconRefreshTag.doTag(page, _servletContext, _request, _stringResponse);
367 
368         return _stringResponse.getString();
369     }
370 
371     public String include(String page) throws Exception {
372         _stringResponse.recycle();
373 
374         RequestDispatcher requestDispatcher =
375             _servletContext.getRequestDispatcher(page);
376 
377         requestDispatcher.include(_request, _stringResponse);
378 
379         return _stringResponse.getString();
380     }
381 
382     public String include(ServletContext servletContext, String page)
383         throws Exception {
384 
385         _stringResponse.recycle();
386 
387         RequestDispatcher requestDispatcher =
388             servletContext.getRequestDispatcher(page);
389 
390         requestDispatcher.include(_request, _stringResponse);
391 
392         return _stringResponse.getString();
393     }
394 
395     public String journalContentSearch() throws Exception {
396         _stringResponse.recycle();
397 
398         JournalContentSearchTag.doTag(
399             _servletContext, _request, _stringResponse);
400 
401         return _stringResponse.getString();
402     }
403 
404     public String language() throws Exception {
405         _stringResponse.recycle();
406 
407         LanguageTag.doTag(_servletContext, _request, _stringResponse);
408 
409         return _stringResponse.getString();
410     }
411 
412     public String language(
413             String formName, String formAction, String name, int displayStyle)
414         throws Exception {
415 
416         _stringResponse.recycle();
417 
418         LanguageTag.doTag(
419             formName, formAction, name, null, displayStyle, _servletContext,
420             _request, _stringResponse);
421 
422         return _stringResponse.getString();
423     }
424 
425     public String language(
426             String formName, String formAction, String name,
427             String[] languageIds, int displayStyle)
428         throws Exception {
429 
430         _stringResponse.recycle();
431 
432         LanguageTag.doTag(
433             formName, formAction, name, languageIds, displayStyle,
434             _servletContext, _request, _stringResponse);
435 
436         return _stringResponse.getString();
437     }
438 
439     public String language(
440             String page, String formName, String formAction, String name,
441             int displayStyle)
442         throws Exception {
443 
444         _stringResponse.recycle();
445 
446         LanguageTag.doTag(
447             page, formName, formAction, name, null, displayStyle,
448             _servletContext, _request, _stringResponse);
449 
450         return _stringResponse.getString();
451     }
452 
453     public String language(
454             String page, String formName, String formAction, String name,
455             String[] languageIds, int displayStyle)
456         throws Exception {
457 
458         _stringResponse.recycle();
459 
460         LanguageTag.doTag(
461             page, formName, formAction, name, languageIds, displayStyle,
462             _servletContext, _request, _stringResponse);
463 
464         return _stringResponse.getString();
465     }
466 
467     public String layoutIcon(Layout layout) throws Exception {
468         _stringResponse.recycle();
469 
470         LayoutIconTag.doTag(layout, _servletContext, _request, _stringResponse);
471 
472         return _stringResponse.getString();
473     }
474 
475     public String metaTags() throws Exception {
476         _stringResponse.recycle();
477 
478         MetaTagsTag.doTag(_servletContext, _request, _stringResponse);
479 
480         return _stringResponse.getString();
481     }
482 
483     public String myPlaces() throws Exception {
484         _stringResponse.recycle();
485 
486         MyPlacesTag.doTag(_servletContext, _request, _stringResponse);
487 
488         return _stringResponse.getString();
489     }
490 
491     public String myPlaces(int max) throws Exception {
492         _stringResponse.recycle();
493 
494         MyPlacesTag.doTag(max, _servletContext, _request, _stringResponse);
495 
496         return _stringResponse.getString();
497     }
498 
499     public String permissionsURL(
500             String redirect, String modelResource,
501             String modelResourceDescription, String resourcePrimKey)
502         throws Exception {
503 
504         return PermissionsURLTag.doTag(
505             redirect, modelResource, modelResourceDescription, resourcePrimKey,
506             null, false, _pageContext);
507     }
508 
509     public String pngImage(String image, String height, String width)
510         throws Exception {
511 
512         _stringResponse.recycle();
513 
514         PngImageTag.doTag(image, height, width, _servletContext, _request,
515             _stringResponse);
516 
517         return _stringResponse.getString();
518     }
519 
520     public String renderURL(String portletName, String queryString)
521         throws Exception {
522 
523         String windowState = WindowState.NORMAL.toString();
524         String portletMode = PortletMode.VIEW.toString();
525 
526         return renderURL(windowState, portletMode, portletName, queryString);
527     }
528 
529     public String renderURL(
530             String windowState, String portletMode, String portletName,
531             String queryString)
532         throws Exception {
533 
534         Boolean secure = null;
535         Boolean copyCurrentRenderParameters = null;
536         Boolean escapeXml = null;
537         Boolean anchor = null;
538         Boolean encrypt = null;
539         long doAsUserId = 0;
540         Boolean portletConfiguration = null;
541 
542         return renderURL(
543             windowState, portletMode, secure, copyCurrentRenderParameters,
544             escapeXml, portletName, anchor, encrypt, doAsUserId,
545             portletConfiguration, queryString);
546     }
547 
548     public String renderURL(
549             String windowState, String portletMode, Boolean secure,
550             Boolean copyCurrentRenderParameters, Boolean escapeXml,
551             String portletName, Boolean anchor, Boolean encrypt,
552             long doAsUserId, Boolean portletConfiguration, String queryString)
553         throws Exception {
554 
555         String var = null;
556         String varImpl = null;
557         String name = null;
558         String resourceID = null;
559         String cacheability = null;
560         Map<String, String[]> params = HttpUtil.parameterMapFromString(
561             queryString);
562         boolean writeOutput = false;
563 
564         return ActionURLTag.doTag(
565             PortletRequest.RENDER_PHASE, windowState, portletMode, var, varImpl,
566             secure, copyCurrentRenderParameters, escapeXml, name, resourceID,
567             cacheability, portletName, anchor, encrypt, doAsUserId,
568             portletConfiguration, params, writeOutput, _pageContext);
569     }
570 
571     public String runtime(String portletName)
572         throws Exception {
573 
574         return runtime(portletName, null);
575     }
576 
577     public String runtime(String portletName, String queryString)
578         throws Exception {
579 
580         _stringResponse.recycle();
581 
582         RuntimeTag.doTag(
583             portletName, queryString, null, _servletContext, _request,
584             _stringResponse);
585 
586         return _stringResponse.getString();
587     }
588 
589     public String runtime(
590             String portletName, String queryString, String defaultPreferences)
591         throws Exception {
592 
593         _stringResponse.recycle();
594 
595         RuntimeTag.doTag(
596             portletName, queryString, defaultPreferences, null, _servletContext,
597             _request, _stringResponse);
598 
599         return _stringResponse.getString();
600     }
601 
602     public String search() throws Exception {
603         _stringResponse.recycle();
604 
605         SearchTag.doTag(_servletContext, _request, _stringResponse);
606 
607         return _stringResponse.getString();
608     }
609 
610     public String staging() throws Exception {
611         _stringResponse.recycle();
612 
613         StagingTag.doTag(_servletContext, _request, _stringResponse);
614 
615         return _stringResponse.getString();
616     }
617 
618     public String toggle(
619             String id, String showImage, String hideImage, String showMessage,
620             String hideMessage, boolean defaultShowContent)
621         throws Exception {
622 
623         _stringResponse.recycle();
624 
625         ToggleTag.doTag(
626             id, showImage, hideImage, showMessage, hideMessage,
627             defaultShowContent, null, _servletContext, _request,
628             _stringResponse);
629 
630         return _stringResponse.getString();
631     }
632 
633     public String wrapPortlet(String wrapPage, String portletPage)
634         throws Exception {
635 
636         _stringResponse.recycle();
637 
638         return WrapPortletTag.doTag(
639             wrapPage, portletPage, _servletContext, _request, _stringResponse,
640             _pageContext);
641     }
642 
643     private ServletContext _servletContext;
644     private HttpServletRequest _request;
645     private StringServletResponse _stringResponse;
646     private PageContext _pageContext;
647 
648 }