001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.taglib.theme;
016    
017    import com.liferay.portal.model.Layout;
018    
019    import javax.servlet.RequestDispatcher;
020    import javax.servlet.ServletContext;
021    import javax.servlet.http.HttpServletRequest;
022    import javax.servlet.http.HttpServletResponse;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class LayoutIconTag extends com.liferay.taglib.util.IncludeTag {
028    
029            public static void doTag(
030                            Layout layout, ServletContext servletContext,
031                            HttpServletRequest request, HttpServletResponse response)
032                    throws Exception {
033    
034                    doTag(_PAGE, layout, servletContext, request, response);
035            }
036    
037            public static void doTag(
038                            String page, Layout layout, ServletContext servletContext,
039                            HttpServletRequest request, HttpServletResponse response)
040                    throws Exception {
041    
042                    setRequestAttributes(request, layout);
043    
044                    RequestDispatcher requestDispatcher =
045                            servletContext.getRequestDispatcher(page);
046    
047                    requestDispatcher.include(request, response);
048            }
049    
050            public static void setRequestAttributes(
051                    HttpServletRequest request, Layout layout) {
052    
053                    request.setAttribute("liferay-theme:layout-icon:layout", layout);
054            }
055    
056            public int doStartTag() {
057                    HttpServletRequest request =
058                            (HttpServletRequest)pageContext.getRequest();
059    
060                    setRequestAttributes(request, _layout);
061    
062                    return EVAL_BODY_BUFFERED;
063            }
064    
065            public void setLayout(Layout layout) {
066                    _layout = layout;
067            }
068    
069            protected String getPage() {
070                    return _PAGE;
071            }
072    
073            private static final String _PAGE =
074                    "/html/taglib/theme/layout_icon/page.jsp";
075    
076            private Layout _layout;
077    
078    }