001    /**
002     * Copyright (c) 2000-2010 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.portlet.bookmarks.asset;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
020    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
021    import com.liferay.portal.security.permission.ActionKeys;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portal.util.PortletKeys;
024    import com.liferay.portal.util.WebKeys;
025    import com.liferay.portlet.asset.model.AssetRenderer;
026    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
027    import com.liferay.portlet.assetpublisher.util.AssetPublisherUtil;
028    import com.liferay.portlet.bookmarks.model.BookmarksEntry;
029    import com.liferay.portlet.bookmarks.service.BookmarksEntryLocalServiceUtil;
030    import com.liferay.portlet.bookmarks.service.permission.BookmarksPermission;
031    
032    import javax.portlet.PortletURL;
033    
034    /**
035     * @author Julio Camarero
036     * @author Juan Fernández
037     */
038    public class BookmarksEntryAssetRendererFactory
039            extends BaseAssetRendererFactory {
040    
041            public static final String CLASS_NAME =BookmarksEntry.class.getName();
042    
043            public static final String TYPE = "bookmark";
044    
045            public AssetRenderer getAssetRenderer(long classPK, int type)
046                    throws PortalException, SystemException {
047    
048                    BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
049    
050                    return new BookmarksEntryAssetRenderer(entry);
051            }
052    
053            public String getClassName() {
054                    return CLASS_NAME;
055            }
056    
057            public String getType() {
058                    return TYPE;
059            }
060    
061            public PortletURL getURLAdd(
062                    LiferayPortletRequest liferayPortletRequest,
063                    LiferayPortletResponse liferayPortletResponse) {
064    
065                    ThemeDisplay themeDisplay =
066                            (ThemeDisplay)liferayPortletRequest.getAttribute(
067                                    WebKeys.THEME_DISPLAY);
068    
069                    PortletURL addAssetURL = null;
070    
071                    if (BookmarksPermission.contains(
072                                    themeDisplay.getPermissionChecker(),
073                                    themeDisplay.getScopeGroupId(), ActionKeys.ADD_ENTRY)) {
074    
075                            addAssetURL = liferayPortletResponse.createRenderURL(
076                                    PortletKeys.BOOKMARKS);
077    
078                            addAssetURL.setParameter(
079                                    "struts_action", "/bookmarks/edit_entry");
080                            addAssetURL.setParameter(
081                                    "groupId", String.valueOf(themeDisplay.getScopeGroupId()));
082                            addAssetURL.setParameter(
083                                    "folderId",
084                                    String.valueOf(
085                                            AssetPublisherUtil.getRecentFolderId(
086                                                    liferayPortletRequest, CLASS_NAME)));
087                    }
088    
089                    return addAssetURL;
090            }
091    
092            protected String getIconPath(ThemeDisplay themeDisplay) {
093                    return themeDisplay.getPathThemeImages() + "/ratings/star_hover.png";
094            }
095    
096    }