1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.taglib.portletext;
16  
17  import com.liferay.portal.kernel.servlet.StringServletResponse;
18  import com.liferay.taglib.util.IncludeTag;
19  
20  import javax.servlet.RequestDispatcher;
21  import javax.servlet.ServletContext;
22  import javax.servlet.http.HttpServletRequest;
23  import javax.servlet.http.HttpServletResponse;
24  import javax.servlet.jsp.JspException;
25  
26  /**
27   * <a href="PreviewTag.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class PreviewTag extends IncludeTag {
32  
33      public static void doTag(
34              String portletName, String queryString, String width,
35              ServletContext servletContext, HttpServletRequest request,
36              HttpServletResponse response)
37          throws Exception {
38  
39          doTag(
40              _PAGE, portletName, queryString, width, servletContext, request,
41              response);
42      }
43  
44      public static void doTag(
45              String page, String portletName, String queryString, String width,
46              ServletContext servletContext, HttpServletRequest request,
47              HttpServletResponse response)
48          throws Exception {
49  
50          request.setAttribute(
51              "liferay-portlet:preview:portletName", portletName);
52          request.setAttribute(
53              "liferay-portlet:preview:queryString", queryString);
54          request.setAttribute("liferay-portlet:preview:width", width);
55  
56          RequestDispatcher requestDispatcher =
57              servletContext.getRequestDispatcher(page);
58  
59          requestDispatcher.include(request, response);
60      }
61  
62      public int doEndTag() throws JspException {
63          try {
64              ServletContext servletContext = getServletContext();
65              HttpServletRequest request = getServletRequest();
66              StringServletResponse response = getServletResponse();
67  
68              doTag(
69                  getPage(), _portletName, _queryString, _width, servletContext,
70                  request, response);
71  
72              pageContext.getOut().print(response.getString());
73  
74              return EVAL_PAGE;
75          }
76          catch (Exception e) {
77              throw new JspException(e);
78          }
79      }
80  
81      public void setPortletName(String portletName) {
82          _portletName = portletName;
83      }
84  
85      public void setQueryString(String queryString) {
86          _queryString = queryString;
87      }
88  
89      public void setWidth(String width) {
90          _width = width;
91      }
92  
93      protected String getDefaultPage() {
94          return _PAGE;
95      }
96  
97      private static final String _PAGE = "/html/taglib/portlet/preview/page.jsp";
98  
99      private String _portletName;
100     private String _queryString;
101     private String _width;
102 
103 }