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.portal.model.Portlet;
24  import com.liferay.taglib.ui.IconTag;
25  
26  import java.io.IOException;
27  
28  import javax.servlet.RequestDispatcher;
29  import javax.servlet.ServletContext;
30  import javax.servlet.ServletException;
31  import javax.servlet.http.HttpServletRequest;
32  import javax.servlet.http.HttpServletResponse;
33  import javax.servlet.jsp.JspException;
34  
35  /**
36   * <a href="IconPortletTag.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   *
40   */
41  public class IconPortletTag extends IconTag {
42  
43      public static void doTag(
44              ServletContext servletContext, HttpServletRequest request,
45              HttpServletResponse response)
46          throws IOException, ServletException {
47  
48          doTag(_PAGE, null, servletContext, request, response);
49      }
50  
51      public static void doTag(
52              String page, Portlet portlet, ServletContext servletContext,
53              HttpServletRequest request, HttpServletResponse response)
54          throws IOException, ServletException {
55  
56          try {
57              request.setAttribute(
58                  "liferay-portlet:icon_portlet:portlet", portlet);
59  
60              RequestDispatcher requestDispatcher =
61                  servletContext.getRequestDispatcher(page);
62  
63              requestDispatcher.include(request, response);
64          }
65          finally {
66              request.removeAttribute("liferay-portlet:icon_portlet:portlet");
67          }
68      }
69  
70      public int doEndTag() throws JspException {
71          try {
72              ServletContext servletContext = getServletContext();
73              HttpServletRequest request = getServletRequest();
74              StringServletResponse response = getServletResponse();
75  
76              doTag(getPage(), _portlet, servletContext, request, response);
77  
78              pageContext.getOut().print(response.getString());
79  
80              return EVAL_PAGE;
81          }
82          catch (Exception e) {
83              throw new JspException(e);
84          }
85      }
86  
87      public void setPortlet(Portlet portlet) {
88          _portlet = portlet;
89      }
90  
91      protected String getDefaultPage() {
92          return _PAGE;
93      }
94  
95      private static final String _PAGE =
96          "/html/taglib/portlet/icon_portlet/page.jsp";
97  
98      private Portlet _portlet;
99  
100 }