1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.taglib.portletext;
16  
17  import com.liferay.portal.kernel.servlet.StringServletResponse;
18  import com.liferay.portal.model.Portlet;
19  import com.liferay.taglib.ui.IconTag;
20  
21  import javax.servlet.RequestDispatcher;
22  import javax.servlet.ServletContext;
23  import javax.servlet.http.HttpServletRequest;
24  import javax.servlet.http.HttpServletResponse;
25  import javax.servlet.jsp.JspException;
26  
27  /**
28   * <a href="IconPortletTag.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public class IconPortletTag extends IconTag {
33  
34      public static void doTag(
35              ServletContext servletContext, HttpServletRequest request,
36              HttpServletResponse response)
37          throws Exception {
38  
39          doTag(_PAGE, null, servletContext, request, response);
40      }
41  
42      public static void doTag(
43              String page, Portlet portlet, ServletContext servletContext,
44              HttpServletRequest request, HttpServletResponse response)
45          throws Exception {
46  
47          try {
48              request.setAttribute(
49                  "liferay-portlet:icon_portlet:portlet", portlet);
50  
51              RequestDispatcher requestDispatcher =
52                  servletContext.getRequestDispatcher(page);
53  
54              requestDispatcher.include(request, response);
55          }
56          finally {
57              request.removeAttribute("liferay-portlet:icon_portlet:portlet");
58          }
59      }
60  
61      public int doEndTag() throws JspException {
62          try {
63              ServletContext servletContext = getServletContext();
64              HttpServletRequest request = getServletRequest();
65              StringServletResponse response = getServletResponse();
66  
67              doTag(getPage(), _portlet, servletContext, request, response);
68  
69              pageContext.getOut().print(response.getString());
70  
71              return EVAL_PAGE;
72          }
73          catch (Exception e) {
74              throw new JspException(e);
75          }
76      }
77  
78      public void setPortlet(Portlet portlet) {
79          _portlet = portlet;
80      }
81  
82      protected String getDefaultPage() {
83          return _PAGE;
84      }
85  
86      private static final String _PAGE =
87          "/html/taglib/portlet/icon_portlet/page.jsp";
88  
89      private Portlet _portlet;
90  
91  }