com.liferay.announcements.web.internal.portlet.configuration.icon.DeleteEntryPortletConfigurationIcon.java Source code

Java tutorial

Introduction

Here is the source code for com.liferay.announcements.web.internal.portlet.configuration.icon.DeleteEntryPortletConfigurationIcon.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.announcements.web.internal.portlet.configuration.icon;

import com.liferay.announcements.constants.AnnouncementsPortletKeys;
import com.liferay.announcements.kernel.model.AnnouncementsEntry;
import com.liferay.announcements.web.internal.portlet.action.ActionUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.portlet.configuration.icon.BasePortletConfigurationIcon;
import com.liferay.portal.kernel.portlet.configuration.icon.PortletConfigurationIcon;
import com.liferay.portal.kernel.security.permission.ActionKeys;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.Portal;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portlet.announcements.service.permission.AnnouncementsEntryPermission;

import javax.portlet.ActionRequest;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import javax.portlet.PortletURL;

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

/**
 * @author Roberto Daz
 */
@Component(immediate = true, property = { "javax.portlet.name=" + AnnouncementsPortletKeys.ANNOUNCEMENTS_ADMIN,
        "path=/announcements/view_entry" }, service = PortletConfigurationIcon.class)
public class DeleteEntryPortletConfigurationIcon extends BasePortletConfigurationIcon {

    @Override
    public String getMessage(PortletRequest portletRequest) {
        return LanguageUtil.get(getResourceBundle(getLocale(portletRequest)), "delete");
    }

    @Override
    public String getURL(PortletRequest portletRequest, PortletResponse portletResponse) {

        PortletURL portletURL = _portal.getControlPanelPortletURL(portletRequest,
                AnnouncementsPortletKeys.ANNOUNCEMENTS_ADMIN, PortletRequest.ACTION_PHASE);

        portletURL.setParameter(ActionRequest.ACTION_NAME, "/announcements/edit_entry");
        portletURL.setParameter(Constants.CMD, Constants.DELETE);

        PortletURL redirectURL = _portal.getControlPanelPortletURL(portletRequest,
                AnnouncementsPortletKeys.ANNOUNCEMENTS_ADMIN, PortletRequest.RENDER_PHASE);

        portletURL.setParameter("redirect", redirectURL.toString());

        AnnouncementsEntry entry = null;

        try {
            entry = ActionUtil.getEntry(portletRequest);
        } catch (PortalException pe) {
            throw new RuntimeException(pe);
        }

        portletURL.setParameter("entryId", String.valueOf(entry.getEntryId()));

        return portletURL.toString();
    }

    @Override
    public double getWeight() {
        return 100;
    }

    @Override
    public boolean isShow(PortletRequest portletRequest) {
        try {
            ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

            AnnouncementsEntry entry = ActionUtil.getEntry(portletRequest);

            return AnnouncementsEntryPermission.contains(themeDisplay.getPermissionChecker(), entry,
                    ActionKeys.DELETE);
        } catch (PortalException pe) {
            throw new RuntimeException(pe);
        }
    }

    @Override
    public boolean isToolTip() {
        return false;
    }

    @Reference
    private Portal _portal;

}