001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.taglib.theme;
022:
023: import com.liferay.portal.kernel.servlet.StringServletResponse;
024: import com.liferay.portal.kernel.util.StringPool;
025: import com.liferay.portal.model.Theme;
026: import com.liferay.portal.theme.PortletDisplay;
027: import com.liferay.portal.theme.ThemeDisplay;
028: import com.liferay.portal.util.WebKeys;
029: import com.liferay.taglib.util.ParamAncestorTagImpl;
030: import com.liferay.taglib.util.ThemeUtil;
031:
032: import javax.servlet.RequestDispatcher;
033: import javax.servlet.ServletContext;
034: import javax.servlet.http.HttpServletRequest;
035: import javax.servlet.jsp.JspException;
036: import javax.servlet.jsp.PageContext;
037:
038: /**
039: * <a href="WrapPortletTag.java.html"><b><i>View Source</i></b></a>
040: *
041: * @author Brian Wing Shun Chan
042: *
043: */
044: public class WrapPortletTag extends ParamAncestorTagImpl {
045:
046: public static String doTag(String wrapPage, String portletPage,
047: ServletContext ctx, HttpServletRequest req,
048: StringServletResponse res, PageContext pageContext)
049: throws Exception {
050:
051: ThemeDisplay themeDisplay = (ThemeDisplay) req
052: .getAttribute(WebKeys.THEME_DISPLAY);
053:
054: Theme theme = themeDisplay.getTheme();
055: PortletDisplay portletDisplay = themeDisplay
056: .getPortletDisplay();
057:
058: // Portlet content
059:
060: RequestDispatcher rd = ctx.getRequestDispatcher(portletPage);
061:
062: rd.include(req, res);
063:
064: portletDisplay.setContent(res.getString());
065:
066: // Page
067:
068: res.recycle();
069:
070: return ThemeUtil.includeVM(ctx, req, pageContext, wrapPage,
071: theme, false);
072: }
073:
074: public int doStartTag() {
075: return EVAL_BODY_BUFFERED;
076: }
077:
078: public int doAfterBody() {
079: _bodyContentString = getBodyContent().getString();
080:
081: return SKIP_BODY;
082: }
083:
084: public int doEndTag() throws JspException {
085: try {
086: ServletContext ctx = getServletContext();
087: HttpServletRequest req = getServletRequest();
088: StringServletResponse res = getServletResponse();
089:
090: ThemeDisplay themeDisplay = (ThemeDisplay) req
091: .getAttribute(WebKeys.THEME_DISPLAY);
092:
093: Theme theme = themeDisplay.getTheme();
094: PortletDisplay portletDisplay = themeDisplay
095: .getPortletDisplay();
096:
097: // Portlet content
098:
099: portletDisplay.setContent(_bodyContentString);
100:
101: // Page
102:
103: ThemeUtil.include(ctx, req, res, pageContext, getPage(),
104: theme);
105:
106: pageContext.getOut().print(res.getString());
107:
108: return EVAL_PAGE;
109: } catch (Exception e) {
110: throw new JspException(e);
111: } finally {
112: clearParams();
113: }
114: }
115:
116: public String getPage() {
117: return _page;
118: }
119:
120: public void setPage(String page) {
121: _page = page;
122: }
123:
124: private String _page;
125: private String _bodyContentString = StringPool.BLANK;
126:
127: }
|