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.portletext;
022:
023: import com.liferay.portal.kernel.servlet.StringServletResponse;
024: import com.liferay.taglib.util.IncludeTag;
025:
026: import java.io.IOException;
027:
028: import javax.servlet.RequestDispatcher;
029: import javax.servlet.ServletContext;
030: import javax.servlet.ServletException;
031: import javax.servlet.http.HttpServletRequest;
032: import javax.servlet.http.HttpServletResponse;
033: import javax.servlet.jsp.JspException;
034:
035: /**
036: * <a href="PreviewTag.java.html"><b><i>View Source</i></b></a>
037: *
038: * @author Brian Wing Shun Chan
039: *
040: */
041: public class PreviewTag extends IncludeTag {
042:
043: public static void doTag(String portletName, String queryString,
044: String width, ServletContext ctx, HttpServletRequest req,
045: HttpServletResponse res) throws IOException,
046: ServletException {
047:
048: doTag(_PAGE, portletName, queryString, width, ctx, req, res);
049: }
050:
051: public static void doTag(String page, String portletName,
052: String queryString, String width, ServletContext ctx,
053: HttpServletRequest req, HttpServletResponse res)
054: throws IOException, ServletException {
055:
056: req.setAttribute("liferay-portlet:preview:portletName",
057: portletName);
058: req.setAttribute("liferay-portlet:preview:queryString",
059: queryString);
060: req.setAttribute("liferay-portlet:preview:width", width);
061:
062: RequestDispatcher rd = ctx.getRequestDispatcher(page);
063:
064: rd.include(req, res);
065: }
066:
067: public int doEndTag() throws JspException {
068: try {
069: ServletContext ctx = getServletContext();
070: HttpServletRequest req = getServletRequest();
071: StringServletResponse res = getServletResponse();
072:
073: doTag(_portletName, _queryString, _width, ctx, req, res);
074:
075: pageContext.getOut().print(res.getString());
076:
077: return EVAL_PAGE;
078: } catch (Exception e) {
079: throw new JspException(e);
080: }
081: }
082:
083: public void setPortletName(String portletName) {
084: _portletName = portletName;
085: }
086:
087: public void setQueryString(String queryString) {
088: _queryString = queryString;
089: }
090:
091: public void setWidth(String width) {
092: _width = width;
093: }
094:
095: protected String getDefaultPage() {
096: return _PAGE;
097: }
098:
099: private static final String _PAGE = "/html/taglib/portlet/preview/page.jsp";
100:
101: private String _portletName;
102: private String _queryString;
103: private String _width;
104:
105: }
|