com.liferay.portlet.configuration.icon.locator.internal.LegacyConfigurationIconLocator.java Source code

Java tutorial

Introduction

Here is the source code for com.liferay.portlet.configuration.icon.locator.internal.LegacyConfigurationIconLocator.java

Source

/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.liferay.portlet.configuration.icon.locator.internal;

import com.liferay.portal.kernel.model.Portlet;
import com.liferay.portal.kernel.portlet.configuration.icon.locator.PortletConfigurationIconLocator;
import com.liferay.portal.kernel.service.PortletLocalService;
import com.liferay.portal.kernel.theme.PortletDisplay;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.WebKeys;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.portlet.PortletRequest;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
 * @author Sergio Gonzlez
 */
@Component(immediate = true, service = PortletConfigurationIconLocator.class)
public class LegacyConfigurationIconLocator implements PortletConfigurationIconLocator {

    @Override
    public List<String> getDefaultViews(String portletId) {
        return new ArrayList<>();
    }

    @Override
    public String getPath(PortletRequest portletRequest) {
        ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

        PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

        String portletId = portletDisplay.getRootPortletId();

        Portlet portlet = _portletLocalService.getPortletById(portletId);

        if (portlet == null) {
            return StringPool.BLANK;
        }

        Map<String, String> initParams = portlet.getInitParams();

        boolean alwaysDisplayDefaultConfigurationIcons = GetterUtil
                .getBoolean(initParams.get("always-display-default-configuration-icons"));

        if (alwaysDisplayDefaultConfigurationIcons) {
            return StringPool.DASH;
        }

        return StringPool.BLANK;
    }

    @Reference(unbind = "-")
    protected void setPortletLocalService(PortletLocalService portletLocalService) {

        _portletLocalService = portletLocalService;
    }

    private PortletLocalService _portletLocalService;

}