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.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  }