1
14
15 package com.liferay.taglib.theme;
16
17 import com.liferay.portal.kernel.servlet.StringServletResponse;
18 import com.liferay.portal.kernel.util.StringPool;
19 import com.liferay.portal.kernel.util.WebKeys;
20 import com.liferay.portal.model.Theme;
21 import com.liferay.portal.theme.PortletDisplay;
22 import com.liferay.portal.theme.ThemeDisplay;
23 import com.liferay.taglib.util.ParamAndPropertyAncestorTagImpl;
24 import com.liferay.taglib.util.ThemeUtil;
25
26 import javax.servlet.RequestDispatcher;
27 import javax.servlet.ServletContext;
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.jsp.JspException;
30 import javax.servlet.jsp.PageContext;
31
32
37 public class WrapPortletTag extends ParamAndPropertyAncestorTagImpl {
38
39 public static String doTag(
40 String wrapPage, String portletPage, ServletContext servletContext,
41 HttpServletRequest request, StringServletResponse stringResponse,
42 PageContext pageContext)
43 throws Exception {
44
45 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
46 WebKeys.THEME_DISPLAY);
47
48 Theme theme = themeDisplay.getTheme();
49 PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
50
51
53 RequestDispatcher requestDispatcher =
54 servletContext.getRequestDispatcher(portletPage);
55
56 requestDispatcher.include(request, stringResponse);
57
58 portletDisplay.setContent(stringResponse.getString());
59
60
62 stringResponse.recycle();
63
64 String content = ThemeUtil.includeVM(
65 servletContext, request, pageContext, wrapPage, theme, false);
66
67 return _CONTENT_WRAPPER_PRE.concat(content).concat(
68 _CONTENT_WRAPPER_POST);
69 }
70
71 public int doStartTag() {
72 return EVAL_BODY_BUFFERED;
73 }
74
75 public int doAfterBody() {
76 _bodyContentString = getBodyContent().getString();
77
78 return SKIP_BODY;
79 }
80
81 public int doEndTag() throws JspException {
82 try {
83 ServletContext servletContext = getServletContext();
84 HttpServletRequest request = getServletRequest();
85 StringServletResponse stringResponse = getServletResponse();
86
87 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
88 WebKeys.THEME_DISPLAY);
89
90 Theme theme = themeDisplay.getTheme();
91 PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
92
93
95 portletDisplay.setContent(_bodyContentString);
96
97
99 ThemeUtil.include(
100 servletContext, request, stringResponse, pageContext, getPage(),
101 theme);
102
103 pageContext.getOut().print(stringResponse.getString());
104
105 return EVAL_PAGE;
106 }
107 catch (Exception e) {
108 throw new JspException(e);
109 }
110 finally {
111 clearParams();
112 clearProperties();
113 }
114 }
115
116 public String getPage() {
117 return _page;
118 }
119
120 public void setPage(String page) {
121 _page = page;
122 }
123
124 private static final String _CONTENT_WRAPPER_PRE =
125 "<div id=\"content-wrapper\" class=\"column-1\">";
126
127 private static final String _CONTENT_WRAPPER_POST = "</div>";
128
129 private String _page;
130 private String _bodyContentString = StringPool.BLANK;
131
132 }