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