001
014
015 package com.liferay.taglib.portletext;
016
017 import com.liferay.portal.kernel.servlet.PipingServletResponse;
018 import com.liferay.taglib.util.IncludeTag;
019
020 import javax.servlet.RequestDispatcher;
021 import javax.servlet.ServletContext;
022 import javax.servlet.http.HttpServletRequest;
023 import javax.servlet.http.HttpServletResponse;
024 import javax.servlet.jsp.JspException;
025
026
029 public class PreviewTag extends IncludeTag {
030
031 public static void doTag(
032 String portletName, String queryString, String width,
033 ServletContext servletContext, HttpServletRequest request,
034 HttpServletResponse response)
035 throws Exception {
036
037 doTag(
038 _PAGE, portletName, queryString, width, servletContext, request,
039 response);
040 }
041
042 public static void doTag(
043 String page, String portletName, String queryString, String width,
044 ServletContext servletContext, HttpServletRequest request,
045 HttpServletResponse response)
046 throws Exception {
047
048 request.setAttribute(
049 "liferay-portlet:preview:portletName", portletName);
050 request.setAttribute(
051 "liferay-portlet:preview:queryString", queryString);
052 request.setAttribute("liferay-portlet:preview:width", width);
053
054 RequestDispatcher requestDispatcher =
055 servletContext.getRequestDispatcher(page);
056
057 requestDispatcher.include(request, response);
058 }
059
060 public int doEndTag() throws JspException {
061 try {
062 ServletContext servletContext = getServletContext();
063 HttpServletRequest request = getServletRequest();
064
065 doTag(
066 getPage(), _portletName, _queryString, _width, servletContext,
067 request, new PipingServletResponse(pageContext));
068
069 return EVAL_PAGE;
070 }
071 catch (Exception e) {
072 throw new JspException(e);
073 }
074 }
075
076 public void setPortletName(String portletName) {
077 _portletName = portletName;
078 }
079
080 public void setQueryString(String queryString) {
081 _queryString = queryString;
082 }
083
084 public void setWidth(String width) {
085 _width = width;
086 }
087
088 protected String getPage() {
089 return _PAGE;
090 }
091
092 private static final String _PAGE = "/html/taglib/portlet/preview/page.jsp";
093
094 private String _portletName;
095 private String _queryString;
096 private String _width;
097
098 }