001    /**
002     * Copyright (c) 2000-present 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.portletext;
016    
017    import com.liferay.portal.kernel.portlet.configuration.icon.PortletConfigurationIconFactory;
018    import com.liferay.portal.kernel.portlet.configuration.icon.PortletConfigurationIconTracker;
019    import com.liferay.portal.kernel.util.JavaConstants;
020    import com.liferay.portal.kernel.util.ListUtil;
021    import com.liferay.portal.kernel.util.Validator;
022    import com.liferay.portal.kernel.util.WebKeys;
023    import com.liferay.portal.theme.PortletDisplay;
024    import com.liferay.portal.theme.ThemeDisplay;
025    import com.liferay.taglib.ui.IconTag;
026    
027    import java.util.List;
028    
029    import javax.portlet.PortletRequest;
030    
031    import javax.servlet.http.HttpServletRequest;
032    
033    /**
034     * @author Brian Wing Shun Chan
035     */
036    public class IconOptionsTag extends IconTag {
037    
038            public void setDirection(String direction) {
039                    _direction = direction;
040            }
041    
042            @Override
043            public void setPortletId(String portletId) {
044                    _portletId = portletId;
045            }
046    
047            public void setPortletRequest(PortletRequest portletRequest) {
048                    _portletRequest = portletRequest;
049            }
050    
051            public void setShowArrow(boolean showArrow) {
052                    _showArrow = showArrow;
053            }
054    
055            @Override
056            protected void cleanUp() {
057                    super.cleanUp();
058    
059                    _direction = "down";
060                    _portletId = null;
061                    _portletRequest = null;
062                    _showArrow = true;
063            }
064    
065            @Override
066            protected String getPage() {
067                    return "/html/taglib/portlet/icon_options/page.jsp";
068            }
069    
070            protected List<PortletConfigurationIconFactory>
071                    getPortletConfigurationIconFactories() {
072    
073                    return ListUtil.copy(
074                            PortletConfigurationIconTracker.getPortletConfigurationIcons(
075                                    getPortletId(), getPortletRequest()));
076            }
077    
078            protected String getPortletId() {
079                    if (Validator.isNotNull(_portletId)) {
080                            return _portletId;
081                    }
082    
083                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
084                            WebKeys.THEME_DISPLAY);
085    
086                    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
087    
088                    return portletDisplay.getRootPortletId();
089            }
090    
091            protected PortletRequest getPortletRequest() {
092                    if (_portletRequest != null) {
093                            return _portletRequest;
094                    }
095    
096                    return (PortletRequest)request.getAttribute(
097                            JavaConstants.JAVAX_PORTLET_REQUEST);
098            }
099    
100            @Override
101            protected void setAttributes(HttpServletRequest request) {
102                    super.setAttributes(request);
103    
104                    request.setAttribute("liferay-ui:icon:direction", _direction);
105                    request.setAttribute(
106                            "liferay-ui:icon:portletRequest", getPortletRequest());
107                    request.setAttribute(
108                            "liferay-ui:icon:showArrow", String.valueOf(_showArrow));
109    
110                    request.setAttribute(
111                            "liferay-ui:icon-options:portletConfigurationIconFactories",
112                            getPortletConfigurationIconFactories());
113            }
114    
115            private String _direction = "down";
116            private String _portletId;
117            private PortletRequest _portletRequest;
118            private boolean _showArrow = true;
119    
120    }