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