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.theme;
16  
17  import com.liferay.portal.model.Layout;
18  
19  import javax.servlet.RequestDispatcher;
20  import javax.servlet.ServletContext;
21  import javax.servlet.http.HttpServletRequest;
22  import javax.servlet.http.HttpServletResponse;
23  
24  /**
25   * <a href="LayoutIconTag.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Brian Wing Shun Chan
28   */
29  public class LayoutIconTag extends com.liferay.taglib.util.IncludeTag {
30  
31      public static void doTag(
32              Layout layout, ServletContext servletContext,
33              HttpServletRequest request, HttpServletResponse response)
34          throws Exception {
35  
36          doTag(_PAGE, layout, servletContext, request, response);
37      }
38  
39      public static void doTag(
40              String page, Layout layout, ServletContext servletContext,
41              HttpServletRequest request, HttpServletResponse response)
42          throws Exception {
43  
44          setRequestAttributes(request, layout);
45  
46          RequestDispatcher requestDispatcher =
47              servletContext.getRequestDispatcher(page);
48  
49          requestDispatcher.include(request, response);
50      }
51  
52      public static void setRequestAttributes(
53          HttpServletRequest request, Layout layout) {
54  
55          request.setAttribute("liferay-theme:layout-icon:layout", layout);
56      }
57  
58      public int doStartTag() {
59          HttpServletRequest request =
60              (HttpServletRequest)pageContext.getRequest();
61  
62          setRequestAttributes(request, _layout);
63  
64          return EVAL_BODY_BUFFERED;
65      }
66  
67      public void setLayout(Layout layout) {
68          _layout = layout;
69      }
70  
71      public String getDefaultPage() {
72          return _PAGE;
73      }
74  
75      private static final String _PAGE =
76          "/html/taglib/theme/layout_icon/page.jsp";
77  
78      private Layout _layout;
79  
80  }