1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.taglib.portletext;
21  
22  import com.liferay.portal.kernel.servlet.StringServletResponse;
23  import com.liferay.taglib.util.IncludeTag;
24  
25  import java.io.IOException;
26  
27  import javax.servlet.RequestDispatcher;
28  import javax.servlet.ServletContext;
29  import javax.servlet.ServletException;
30  import javax.servlet.http.HttpServletRequest;
31  import javax.servlet.http.HttpServletResponse;
32  import javax.servlet.jsp.JspException;
33  
34  /**
35   * <a href="PreviewTag.java.html"><b><i>View Source</i></b></a>
36   *
37   * @author Brian Wing Shun Chan
38   *
39   */
40  public class PreviewTag extends IncludeTag {
41  
42      public static void doTag(
43              String portletName, String queryString, String width,
44              ServletContext servletContext, HttpServletRequest request,
45              HttpServletResponse response)
46          throws IOException, ServletException {
47  
48          doTag(
49              _PAGE, portletName, queryString, width, servletContext, request,
50              response);
51      }
52  
53      public static void doTag(
54              String page, String portletName, String queryString, String width,
55              ServletContext servletContext, HttpServletRequest request,
56              HttpServletResponse response)
57          throws IOException, ServletException {
58  
59          request.setAttribute(
60              "liferay-portlet:preview:portletName", portletName);
61          request.setAttribute(
62              "liferay-portlet:preview:queryString", queryString);
63          request.setAttribute("liferay-portlet:preview:width", width);
64  
65          RequestDispatcher requestDispatcher =
66              servletContext.getRequestDispatcher(page);
67  
68          requestDispatcher.include(request, response);
69      }
70  
71      public int doEndTag() throws JspException {
72          try {
73              ServletContext servletContext = getServletContext();
74              HttpServletRequest request = getServletRequest();
75              StringServletResponse response = getServletResponse();
76  
77              doTag(
78                  getPage(), _portletName, _queryString, _width, servletContext,
79                  request, response);
80  
81              pageContext.getOut().print(response.getString());
82  
83              return EVAL_PAGE;
84          }
85          catch (Exception e) {
86              throw new JspException(e);
87          }
88      }
89  
90      public void setPortletName(String portletName) {
91          _portletName = portletName;
92      }
93  
94      public void setQueryString(String queryString) {
95          _queryString = queryString;
96      }
97  
98      public void setWidth(String width) {
99          _width = width;
100     }
101 
102     protected String getDefaultPage() {
103         return _PAGE;
104     }
105 
106     private static final String _PAGE = "/html/taglib/portlet/preview/page.jsp";
107 
108     private String _portletName;
109     private String _queryString;
110     private String _width;
111 
112 }