001    /**
002     * Copyright (c) 2000-2011 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.portletext;
016    
017    import com.liferay.portal.kernel.servlet.taglib.FileAvailabilityUtil;
018    import com.liferay.portal.model.Portlet;
019    import com.liferay.portal.theme.PortletDisplay;
020    import com.liferay.portal.theme.ThemeDisplay;
021    import com.liferay.portal.util.PortalUtil;
022    import com.liferay.taglib.ui.IconTag;
023    
024    import javax.servlet.http.HttpServletRequest;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     * @author Shuyang Zhou
029     */
030    public class IconPortletTag extends IconTag {
031    
032            @Override
033            protected void cleanUp() {
034                    super.cleanUp();
035    
036                    _portlet = null;
037            }
038    
039            @Override
040            protected void setAttributes(HttpServletRequest request) {
041                    super.setAttributes(request);
042    
043                    request.setAttribute("liferay-portlet:icon_portlet:portlet", _portlet);
044            }
045    
046            public void setPortlet(Portlet portlet) {
047                    _portlet = portlet;
048            }
049    
050            @Override
051            protected String getPage() {
052                    if (FileAvailabilityUtil.isAvailable(getServletContext(), _PAGE)) {
053                            return _PAGE;
054                    }
055    
056                    ThemeDisplay themeDisplay = (ThemeDisplay)pageContext.getAttribute(
057                            "themeDisplay");
058    
059                    String message = null;
060                    String src = null;
061    
062                    if (_portlet != null) {
063                            message = PortalUtil.getPortletTitle(
064                                    _portlet, pageContext.getServletContext(),
065                                    themeDisplay.getLocale());
066                            src = _portlet.getStaticResourcePath().concat(_portlet.getIcon());
067                    }
068                    else {
069                            PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
070    
071                            if (!portletDisplay.isShowPortletIcon()) {
072                                    return null;
073                            }
074    
075                            message = portletDisplay.getTitle();
076                            src = portletDisplay.getURLPortlet();
077                    }
078    
079                    setMessage(message);
080                    setSrc(src);
081    
082                    return super.getPage();
083            }
084    
085            private static final String _PAGE =
086                    "/html/taglib/portlet/icon_portlet/page.jsp";
087    
088            private Portlet _portlet;
089    
090    }