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