1
14
15 package com.liferay.taglib.theme;
16
17 import com.liferay.portal.kernel.servlet.PipingServletResponse;
18 import com.liferay.portal.kernel.servlet.StringServletResponse;
19 import com.liferay.portal.kernel.util.StringPool;
20 import com.liferay.portal.kernel.util.WebKeys;
21 import com.liferay.portal.model.Theme;
22 import com.liferay.portal.theme.PortletDisplay;
23 import com.liferay.portal.theme.ThemeDisplay;
24 import com.liferay.taglib.util.ParamAndPropertyAncestorTagImpl;
25 import com.liferay.taglib.util.ThemeUtil;
26
27 import javax.servlet.RequestDispatcher;
28 import javax.servlet.ServletContext;
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31 import javax.servlet.jsp.JspException;
32 import javax.servlet.jsp.PageContext;
33
34
39 public class WrapPortletTag extends ParamAndPropertyAncestorTagImpl {
40
41 public static String doTag(
42 String wrapPage, String portletPage, ServletContext servletContext,
43 HttpServletRequest request, HttpServletResponse response,
44 PageContext pageContext)
45 throws Exception {
46
47 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
48 WebKeys.THEME_DISPLAY);
49
50 Theme theme = themeDisplay.getTheme();
51 PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
52
53
55 RequestDispatcher requestDispatcher =
56 servletContext.getRequestDispatcher(portletPage);
57
58 StringServletResponse stringResponse =
59 new StringServletResponse(response);
60
61 requestDispatcher.include(request, stringResponse);
62
63 portletDisplay.setContent(stringResponse.getString());
64
65
67 String content = ThemeUtil.includeVM(
68 servletContext, request, pageContext, wrapPage, theme, false);
69
70 return _CONTENT_WRAPPER_PRE.concat(content).concat(
71 _CONTENT_WRAPPER_POST);
72 }
73
74 public int doStartTag() {
75 return EVAL_BODY_BUFFERED;
76 }
77
78 public int doAfterBody() {
79 _bodyContentString = getBodyContent().getString();
80
81 return SKIP_BODY;
82 }
83
84 public int doEndTag() throws JspException {
85 try {
86 ServletContext servletContext = getServletContext();
87 HttpServletRequest request = getServletRequest();
88
89 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
90 WebKeys.THEME_DISPLAY);
91
92 Theme theme = themeDisplay.getTheme();
93 PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
94
95
97 portletDisplay.setContent(_bodyContentString);
98
99
101 ThemeUtil.include(
102 servletContext, request, new PipingServletResponse(pageContext),
103 pageContext, getPage(), theme);
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 protected 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 class=\"column-1\" id=\"main-content\" role=\"main\">";
126
127 private static final String _CONTENT_WRAPPER_POST = "</div>";
128
129 private String _page;
130 private String _bodyContentString = StringPool.BLANK;
131
132 }