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.ParamAncestorTagImpl;
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 ParamAncestorTagImpl {
47
48 public static String doTag(
49 String wrapPage, String portletPage, ServletContext ctx,
50 HttpServletRequest req, StringServletResponse res,
51 PageContext pageContext)
52 throws Exception {
53
54 ThemeDisplay themeDisplay = (ThemeDisplay)req.getAttribute(
55 WebKeys.THEME_DISPLAY);
56
57 Theme theme = themeDisplay.getTheme();
58 PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
59
60
62 RequestDispatcher rd = ctx.getRequestDispatcher(portletPage);
63
64 rd.include(req, res);
65
66 portletDisplay.setContent(res.getString());
67
68
70 res.recycle();
71
72 return ThemeUtil.includeVM(
73 ctx, req, pageContext, wrapPage, theme, false);
74 }
75
76 public int doStartTag() {
77 return EVAL_BODY_BUFFERED;
78 }
79
80 public int doAfterBody() {
81 _bodyContentString = getBodyContent().getString();
82
83 return SKIP_BODY;
84 }
85
86 public int doEndTag() throws JspException {
87 try {
88 ServletContext ctx = getServletContext();
89 HttpServletRequest req = getServletRequest();
90 StringServletResponse res = getServletResponse();
91
92 ThemeDisplay themeDisplay = (ThemeDisplay)req.getAttribute(
93 WebKeys.THEME_DISPLAY);
94
95 Theme theme = themeDisplay.getTheme();
96 PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
97
98
100 portletDisplay.setContent(_bodyContentString);
101
102
104 ThemeUtil.include(ctx, req, res, pageContext, getPage(), theme);
105
106 pageContext.getOut().print(res.getString());
107
108 return EVAL_PAGE;
109 }
110 catch (Exception e) {
111 throw new JspException(e);
112 }
113 finally {
114 clearParams();
115 }
116 }
117
118 public String getPage() {
119 return _page;
120 }
121
122 public void setPage(String page) {
123 _page = page;
124 }
125
126 private String _page;
127 private String _bodyContentString = StringPool.BLANK;
128
129 }