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