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.portletext;
016    
017    import com.liferay.portal.kernel.servlet.taglib.FileAvailabilityUtil;
018    import com.liferay.portal.kernel.util.StringBundler;
019    import com.liferay.portal.theme.PortletDisplay;
020    import com.liferay.taglib.ui.IconTag;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     * @author Shuyang Zhou
025     */
026    public class IconConfigurationTag extends IconTag {
027    
028            @Override
029            protected String getPage() {
030                    if (FileAvailabilityUtil.isAvailable(getServletContext(), _PAGE)) {
031                            return _PAGE;
032                    }
033    
034                    PortletDisplay portletDisplay =
035                            (PortletDisplay)pageContext.getAttribute("portletDisplay");
036    
037                    if (!portletDisplay.isShowConfigurationIcon()) {
038                            return null;
039                    }
040    
041                    setCssClass("portlet-configuration portlet-configuration-icon");
042                    setImage("../portlet/configuration");
043                    setMessage("configuration");
044                    setMethod("get");
045    
046                    StringBundler sb = new StringBundler(9);
047    
048                    sb.append("Liferay.Portlet.openConfiguration('#p_p_id_");
049                    sb.append(portletDisplay.getId());
050                    sb.append("_', '");
051                    sb.append(portletDisplay.getId());
052                    sb.append("', '");
053                    sb.append(portletDisplay.getURLConfiguration());
054                    sb.append("', '");
055                    sb.append(portletDisplay.getNamespace());
056                    sb.append("'); return false;");
057    
058                    setOnClick(sb.toString());
059    
060                    setToolTip(false);
061                    setUrl(portletDisplay.getURLConfiguration());
062    
063                    return super.getPage();
064            }
065    
066            private static final String _PAGE =
067                    "/html/taglib/portlet/icon_configuration/page.jsp";
068    
069    }