001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    import javax.servlet.jsp.tagext.BodyTag;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class LayoutIconTag
029            extends com.liferay.taglib.util.IncludeTag implements BodyTag {
030    
031            public static void doTag(
032                            Layout layout, ServletContext servletContext,
033                            HttpServletRequest request, HttpServletResponse response)
034                    throws Exception {
035    
036                    doTag(_PAGE, layout, servletContext, request, response);
037            }
038    
039            public static void doTag(
040                            String page, Layout layout, ServletContext servletContext,
041                            HttpServletRequest request, HttpServletResponse response)
042                    throws Exception {
043    
044                    setRequestAttributes(request, layout);
045    
046                    RequestDispatcher requestDispatcher =
047                            servletContext.getRequestDispatcher(page);
048    
049                    requestDispatcher.include(request, response);
050            }
051    
052            public static void setRequestAttributes(
053                    HttpServletRequest request, Layout layout) {
054    
055                    request.setAttribute("liferay-theme:layout-icon:layout", layout);
056            }
057    
058            @Override
059            public int doStartTag() {
060                    HttpServletRequest request =
061                            (HttpServletRequest)pageContext.getRequest();
062    
063                    setRequestAttributes(request, _layout);
064    
065                    return EVAL_BODY_BUFFERED;
066            }
067    
068            public void setLayout(Layout layout) {
069                    _layout = layout;
070            }
071    
072            @Override
073            protected String getPage() {
074                    return _PAGE;
075            }
076    
077            private static final String _PAGE =
078                    "/html/taglib/theme/layout_icon/page.jsp";
079    
080            private Layout _layout;
081    
082    }