001
014
015 package com.liferay.taglib.util;
016
017 import com.liferay.portal.kernel.servlet.DirectRequestDispatcherFactoryUtil;
018 import com.liferay.portal.kernel.servlet.PipingPageContext;
019 import com.liferay.portal.kernel.servlet.taglib.TagSupport;
020 import com.liferay.portal.kernel.util.HttpUtil;
021 import com.liferay.portal.kernel.util.WebKeys;
022 import com.liferay.portal.model.Layout;
023 import com.liferay.portal.model.LayoutConstants;
024 import com.liferay.portal.model.Portlet;
025 import com.liferay.portal.theme.ThemeDisplay;
026 import com.liferay.taglib.portlet.ActionURLTag;
027 import com.liferay.taglib.portletext.IconBackTag;
028 import com.liferay.taglib.portletext.IconCloseTag;
029 import com.liferay.taglib.portletext.IconConfigurationTag;
030 import com.liferay.taglib.portletext.IconEditDefaultsTag;
031 import com.liferay.taglib.portletext.IconEditGuestTag;
032 import com.liferay.taglib.portletext.IconEditTag;
033 import com.liferay.taglib.portletext.IconHelpTag;
034 import com.liferay.taglib.portletext.IconMaximizeTag;
035 import com.liferay.taglib.portletext.IconMinimizeTag;
036 import com.liferay.taglib.portletext.IconOptionsTag;
037 import com.liferay.taglib.portletext.IconPortletCssTag;
038 import com.liferay.taglib.portletext.IconPortletTag;
039 import com.liferay.taglib.portletext.IconPrintTag;
040 import com.liferay.taglib.portletext.IconRefreshTag;
041 import com.liferay.taglib.portletext.RuntimeTag;
042 import com.liferay.taglib.security.DoAsURLTag;
043 import com.liferay.taglib.security.PermissionsURLTag;
044 import com.liferay.taglib.theme.LayoutIconTag;
045 import com.liferay.taglib.theme.MetaTagsTag;
046 import com.liferay.taglib.theme.WrapPortletTag;
047 import com.liferay.taglib.ui.BreadcrumbTag;
048 import com.liferay.taglib.ui.JournalContentSearchTag;
049 import com.liferay.taglib.ui.LanguageTag;
050 import com.liferay.taglib.ui.MySitesTag;
051 import com.liferay.taglib.ui.PngImageTag;
052 import com.liferay.taglib.ui.SearchTag;
053 import com.liferay.taglib.ui.StagingTag;
054 import com.liferay.taglib.ui.ToggleTag;
055
056 import java.util.Map;
057 import java.util.Set;
058
059 import javax.portlet.PortletMode;
060 import javax.portlet.PortletRequest;
061 import javax.portlet.WindowState;
062
063 import javax.servlet.RequestDispatcher;
064 import javax.servlet.ServletContext;
065 import javax.servlet.http.HttpServletRequest;
066 import javax.servlet.http.HttpServletResponse;
067 import javax.servlet.jsp.PageContext;
068
069
073 public class VelocityTaglib {
074
075 public VelocityTaglib() {
076 }
077
078 public VelocityTaglib(
079 ServletContext servletContext, HttpServletRequest request,
080 HttpServletResponse response, PageContext pageContext) {
081
082 init(servletContext, request, response, pageContext);
083 }
084
085 public void actionURL(long plid, String portletName, String queryString)
086 throws Exception {
087
088 String windowState = WindowState.NORMAL.toString();
089 String portletMode = PortletMode.VIEW.toString();
090
091 actionURL(windowState, portletMode, plid, portletName, queryString);
092 }
093
094 public void actionURL(String portletName, String queryString)
095 throws Exception {
096
097 actionURL(LayoutConstants.DEFAULT_PLID, portletName, queryString);
098 }
099
100
105 public void actionURL(
106 String windowState, String portletMode, Boolean secure,
107 Boolean copyCurrentRenderParameters, Boolean escapeXml, String name,
108 long plid, long refererPlid, String portletName, Boolean anchor,
109 Boolean encrypt, long doAsUserId, Boolean portletConfiguration,
110 String queryString)
111 throws Exception {
112
113 actionURL(
114 windowState, portletMode, secure, copyCurrentRenderParameters,
115 escapeXml, name, plid, refererPlid, portletName, anchor, encrypt, 0,
116 doAsUserId, portletConfiguration, queryString);
117 }
118
119 public void actionURL(
120 String windowState, String portletMode, Boolean secure,
121 Boolean copyCurrentRenderParameters, Boolean escapeXml, String name,
122 long plid, long refererPlid, String portletName, Boolean anchor,
123 Boolean encrypt, long doAsGroupId, long doAsUserId,
124 Boolean portletConfiguration, String queryString)
125 throws Exception {
126
127 String var = null;
128 String varImpl = null;
129 String resourceID = null;
130 String cacheability = null;
131 Map<String, String[]> parameterMap = HttpUtil.parameterMapFromString(
132 queryString);
133 Set<String> removedParameterNames = null;
134
135 ActionURLTag.doTag(
136 PortletRequest.ACTION_PHASE, windowState, portletMode, var, varImpl,
137 secure, copyCurrentRenderParameters, escapeXml, name, resourceID,
138 cacheability, plid, refererPlid, portletName, anchor, encrypt,
139 doAsGroupId, doAsUserId, portletConfiguration, parameterMap,
140 removedParameterNames, _pageContext);
141 }
142
143 public void actionURL(
144 String windowState, String portletMode, long plid,
145 String portletName, String queryString)
146 throws Exception {
147
148 Boolean secure = null;
149 Boolean copyCurrentRenderParameters = null;
150 Boolean escapeXml = null;
151 long refererPlid = LayoutConstants.DEFAULT_PLID;
152 String name = null;
153 Boolean anchor = null;
154 Boolean encrypt = null;
155 long doAsGroupId = 0;
156 long doAsUserId = 0;
157 Boolean portletConfiguration = null;
158
159 actionURL(
160 windowState, portletMode, secure, copyCurrentRenderParameters,
161 escapeXml, name, plid, refererPlid, portletName, anchor, encrypt,
162 doAsGroupId, doAsUserId, portletConfiguration, queryString);
163 }
164
165 public void actionURL(
166 String windowState, String portletMode, String portletName,
167 String queryString)
168 throws Exception {
169
170 actionURL(
171 windowState, portletMode, LayoutConstants.DEFAULT_PLID, portletName,
172 queryString);
173 }
174
175 public void breadcrumb() throws Exception {
176 BreadcrumbTag breadcrumbTag = new BreadcrumbTag();
177
178 setUp(breadcrumbTag);
179
180 breadcrumbTag.runTag();
181 }
182
183 public void breadcrumb(
184 String displayStyle, boolean showGuestGroup,
185 boolean showParentGroups, boolean showLayout,
186 boolean showPortletBreadcrumb)
187 throws Exception {
188
189 BreadcrumbTag breadcrumbTag = new BreadcrumbTag();
190
191 setUp(breadcrumbTag);
192
193 breadcrumbTag.setDisplayStyle(displayStyle);
194 breadcrumbTag.setShowGuestGroup(showGuestGroup);
195 breadcrumbTag.setShowLayout(showLayout);
196 breadcrumbTag.setShowParentGroups(showParentGroups);
197 breadcrumbTag.setShowPortletBreadcrumb(showPortletBreadcrumb);
198
199 breadcrumbTag.runTag();
200 }
201
202 public void doAsURL(long doAsUserId) throws Exception {
203 DoAsURLTag.doTag(doAsUserId, null, _pageContext);
204 }
205
206 public BreadcrumbTag getBreadcrumbTag() throws Exception {
207 BreadcrumbTag breadcrumbTag = new BreadcrumbTag();
208
209 setUp(breadcrumbTag);
210
211 return breadcrumbTag;
212 }
213
214 public MySitesTag getMySitesTag() throws Exception {
215 MySitesTag mySitesTag = new MySitesTag();
216
217 setUp(mySitesTag);
218
219 return mySitesTag;
220 }
221
222 public PngImageTag getPngImageTag() throws Exception {
223 PngImageTag pngImageTag = new PngImageTag();
224
225 setUp(pngImageTag);
226
227 return pngImageTag;
228 }
229
230 public String getSetting(String name) {
231 ThemeDisplay themeDisplay = (ThemeDisplay)_request.getAttribute(
232 WebKeys.THEME_DISPLAY);
233
234 return themeDisplay.getThemeSetting(name);
235 }
236
237 public void iconBack() throws Exception {
238 IconBackTag iconBackTag = new IconBackTag();
239
240 setUp(iconBackTag);
241
242 iconBackTag.runTag();
243 }
244
245 public void iconClose() throws Exception {
246 IconCloseTag iconCloseTag = new IconCloseTag();
247
248 setUp(iconCloseTag);
249
250 iconCloseTag.runTag();
251 }
252
253 public void iconConfiguration() throws Exception {
254 IconConfigurationTag iconConfigurationTag = new IconConfigurationTag();
255
256 setUp(iconConfigurationTag);
257
258 iconConfigurationTag.runTag();
259 }
260
261 public void iconEdit() throws Exception {
262 IconEditTag iconEditTag = new IconEditTag();
263
264 setUp(iconEditTag);
265
266 iconEditTag.runTag();
267 }
268
269 public void iconEditDefaults() throws Exception {
270 IconEditDefaultsTag iconEditDefaultsTag = new IconEditDefaultsTag();
271
272 setUp(iconEditDefaultsTag);
273
274 iconEditDefaultsTag.runTag();
275 }
276
277 public void iconEditGuest() throws Exception {
278 IconEditGuestTag iconEditGuestTag = new IconEditGuestTag();
279
280 setUp(iconEditGuestTag);
281
282 iconEditGuestTag.runTag();
283 }
284
285 public void iconHelp() throws Exception {
286 IconHelpTag iconHelpTag = new IconHelpTag();
287
288 setUp(iconHelpTag);
289
290 iconHelpTag.runTag();
291 }
292
293 public void iconMaximize() throws Exception {
294 IconMaximizeTag iconMaximizeTag = new IconMaximizeTag();
295
296 setUp(iconMaximizeTag);
297
298 iconMaximizeTag.runTag();
299 }
300
301 public void iconMinimize() throws Exception {
302 IconMinimizeTag iconMinimizeTag = new IconMinimizeTag();
303
304 setUp(iconMinimizeTag);
305
306 iconMinimizeTag.runTag();
307 }
308
309 public void iconOptions() throws Exception {
310 IconOptionsTag iconOptionsTag = new IconOptionsTag();
311
312 setUp(iconOptionsTag);
313
314 iconOptionsTag.runTag();
315 }
316
317 public void iconPortlet() throws Exception {
318 IconPortletTag iconPortletTag = new IconPortletTag();
319
320 setUp(iconPortletTag);
321
322 iconPortletTag.runTag();
323 }
324
325 public void iconPortlet(Portlet portlet) throws Exception {
326 IconPortletTag iconPortletTag = new IconPortletTag();
327
328 setUp(iconPortletTag);
329
330 iconPortletTag.setPortlet(portlet);
331
332 iconPortletTag.runTag();
333 }
334
335 public void iconPortletCss() throws Exception {
336 IconPortletCssTag iconPortletCssTag = new IconPortletCssTag();
337
338 setUp(iconPortletCssTag);
339
340 iconPortletCssTag.runTag();
341 }
342
343 public void iconPrint() throws Exception {
344 IconPrintTag iconPrintTag = new IconPrintTag();
345
346 setUp(iconPrintTag);
347
348 iconPrintTag.runTag();
349 }
350
351 public void iconRefresh() throws Exception {
352 IconRefreshTag iconRefreshTag = new IconRefreshTag();
353
354 setUp(iconRefreshTag);
355
356 iconRefreshTag.runTag();
357 }
358
359 public void include(ServletContext servletContext, String page)
360 throws Exception {
361
362 RequestDispatcher requestDispatcher =
363 servletContext.getRequestDispatcher(page);
364
365 requestDispatcher.include(_request, _response);
366 }
367
368 public void include(String page) throws Exception {
369 RequestDispatcher requestDispatcher =
370 DirectRequestDispatcherFactoryUtil.getRequestDispatcher(
371 _servletContext, page);
372
373 requestDispatcher.include(_request, _response);
374 }
375
376 public VelocityTaglib init(
377 ServletContext servletContext, HttpServletRequest request,
378 HttpServletResponse response, PageContext pageContext) {
379
380 _servletContext = servletContext;
381 _request = request;
382 _response = response;
383 _pageContext = pageContext;
384
385 return this;
386 }
387
388 public void journalContentSearch() throws Exception {
389 JournalContentSearchTag journalContentSearchTag =
390 new JournalContentSearchTag();
391
392 setUp(journalContentSearchTag);
393
394 journalContentSearchTag.runTag();
395 }
396
397 public void language() throws Exception {
398 LanguageTag languageTag = new LanguageTag();
399
400 setUp(languageTag);
401
402 languageTag.runTag();
403 }
404
405 public void language(
406 String formName, String formAction, String name, int displayStyle)
407 throws Exception {
408
409 LanguageTag languageTag = new LanguageTag();
410
411 setUp(languageTag);
412
413 languageTag.setDisplayStyle(displayStyle);
414 languageTag.setFormAction(formAction);
415 languageTag.setFormName(formName);
416 languageTag.setName(name);
417
418 languageTag.runTag();
419 }
420
421 public void language(
422 String formName, String formAction, String name,
423 String[] languageIds, int displayStyle)
424 throws Exception {
425
426 LanguageTag languageTag = new LanguageTag();
427
428 setUp(languageTag);
429
430 languageTag.setDisplayStyle(displayStyle);
431 languageTag.setFormAction(formAction);
432 languageTag.setFormName(formName);
433 languageTag.setLanguageIds(languageIds);
434 languageTag.setName(name);
435
436 languageTag.runTag();
437 }
438
439 public void layoutIcon(Layout layout) throws Exception {
440 LayoutIconTag.doTag(layout, _servletContext, _request, _response);
441 }
442
443 public void metaTags() throws Exception {
444 MetaTagsTag.doTag(_servletContext, _request, _response);
445 }
446
447
450 public void myPlaces() throws Exception {
451 mySites();
452 }
453
454
457 public void myPlaces(int max) throws Exception {
458 mySites(max);
459 }
460
461 public void mySites() throws Exception {
462 MySitesTag mySitesTag = new MySitesTag();
463
464 setUp(mySitesTag);
465
466 mySitesTag.runTag();
467 }
468
469 public void mySites(int max) throws Exception {
470 MySitesTag mySitesTag = new MySitesTag();
471
472 setUp(mySitesTag);
473
474 mySitesTag.setMax(max);
475
476 mySitesTag.runTag();
477 }
478
479 public void permissionsURL(
480 String redirect, String modelResource,
481 String modelResourceDescription, long resourceGroupId,
482 String resourcePrimKey, String windowState, int[] roleTypes)
483 throws Exception {
484
485 PermissionsURLTag.doTag(
486 redirect, modelResource, modelResourceDescription, resourceGroupId,
487 resourcePrimKey, windowState, null, roleTypes, _pageContext);
488 }
489
490
494 public void permissionsURL(
495 String redirect, String modelResource,
496 String modelResourceDescription, String resourcePrimKey,
497 String windowState, int[] roleTypes)
498 throws Exception {
499
500 permissionsURL(
501 redirect, modelResourceDescription, modelResourceDescription, 0,
502 resourcePrimKey, windowState, roleTypes);
503 }
504
505 public void renderURL(long plid, String portletName, String queryString)
506 throws Exception {
507
508 String windowState = WindowState.NORMAL.toString();
509 String portletMode = PortletMode.VIEW.toString();
510
511 renderURL(windowState, portletMode, plid, portletName, queryString);
512 }
513
514 public void renderURL(String portletName, String queryString)
515 throws Exception {
516
517 renderURL(LayoutConstants.DEFAULT_PLID, portletName, queryString);
518 }
519
520 public void renderURL(
521 String windowState, String portletMode, Boolean secure,
522 Boolean copyCurrentRenderParameters, Boolean escapeXml, long plid,
523 long refererPlid, String portletName, Boolean anchor,
524 Boolean encrypt, long doAsGroupId, long doAsUserId,
525 Boolean portletConfiguration, String queryString)
526 throws Exception {
527
528 String var = null;
529 String varImpl = null;
530 String name = null;
531 String resourceID = null;
532 String cacheability = null;
533 Map<String, String[]> parameterMap = HttpUtil.parameterMapFromString(
534 queryString);
535 Set<String> removedParameterNames = null;
536
537 ActionURLTag.doTag(
538 PortletRequest.RENDER_PHASE, windowState, portletMode, var, varImpl,
539 secure, copyCurrentRenderParameters, escapeXml, name, resourceID,
540 cacheability, plid, refererPlid, portletName, anchor, encrypt,
541 doAsGroupId, doAsUserId, portletConfiguration, parameterMap,
542 removedParameterNames, _pageContext);
543 }
544
545
550 public void renderURL(
551 String windowState, String portletMode, Boolean secure,
552 Boolean copyCurrentRenderParameters, Boolean escapeXml, long plid,
553 String portletName, Boolean anchor, Boolean encrypt,
554 long doAsUserId, Boolean portletConfiguration, String queryString)
555 throws Exception {
556
557 long refererPlid = LayoutConstants.DEFAULT_PLID;
558
559 renderURL(
560 windowState, portletMode, secure, copyCurrentRenderParameters,
561 escapeXml, plid, refererPlid, portletName, anchor, encrypt, 0,
562 doAsUserId, portletConfiguration, queryString);
563 }
564
565 public void renderURL(
566 String windowState, String portletMode, long plid,
567 String portletName, String queryString)
568 throws Exception {
569
570 Boolean secure = null;
571 Boolean copyCurrentRenderParameters = null;
572 Boolean escapeXml = null;
573 long referPlid = LayoutConstants.DEFAULT_PLID;
574 Boolean anchor = null;
575 Boolean encrypt = null;
576 long doAsGroupId = 0;
577 long doAsUserId = 0;
578 Boolean portletConfiguration = null;
579
580 renderURL(
581 windowState, portletMode, secure, copyCurrentRenderParameters,
582 escapeXml, plid, referPlid, portletName, anchor, encrypt,
583 doAsGroupId, doAsUserId, portletConfiguration, queryString);
584 }
585
586 public void renderURL(
587 String windowState, String portletMode, String portletName,
588 String queryString)
589 throws Exception {
590
591 renderURL(
592 windowState, portletMode, LayoutConstants.DEFAULT_PLID, portletName,
593 queryString);
594 }
595
596 public void runtime(String portletName) throws Exception {
597 runtime(portletName, null);
598 }
599
600 public void runtime(String portletName, String queryString)
601 throws Exception {
602
603 RuntimeTag.doTag(
604 portletName, queryString, null, _servletContext, _request,
605 _response);
606 }
607
608 public void runtime(
609 String portletName, String queryString, String defaultPreferences)
610 throws Exception {
611
612 RuntimeTag.doTag(
613 portletName, queryString, defaultPreferences, null, _servletContext,
614 _request, _response);
615 }
616
617 public void search() throws Exception {
618 SearchTag searchTag = new SearchTag();
619
620 setUp(searchTag);
621
622 searchTag.runTag();
623 }
624
625 public void staging() throws Exception {
626 StagingTag stagingTag = new StagingTag();
627
628 setUp(stagingTag);
629
630 stagingTag.runTag();
631 }
632
633 public void toggle(
634 String id, String showImage, String hideImage, String showMessage,
635 String hideMessage, boolean defaultShowContent)
636 throws Exception {
637
638 ToggleTag.doTag(
639 id, showImage, hideImage, showMessage, hideMessage,
640 defaultShowContent, null, _servletContext, _request, _response);
641 }
642
643 public String wrapPortlet(String wrapPage, String portletPage)
644 throws Exception {
645
646 return WrapPortletTag.doTag(
647 wrapPage, portletPage, _servletContext, _request, _response,
648 _pageContext);
649 }
650
651 protected void setUp(TagSupport tagSupport) throws Exception {
652 tagSupport.setPageContext(
653 new PipingPageContext(_pageContext, _response.getWriter()));
654 }
655
656 private PageContext _pageContext;
657 private HttpServletRequest _request;
658 private HttpServletResponse _response;
659 private ServletContext _servletContext;
660
661 }