001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.security.permission.PermissionChecker;
023    import com.liferay.portal.theme.ThemeDisplay;
024    import com.liferay.portal.util.PortletKeys;
025    import com.liferay.portal.util.WebKeys;
026    import com.liferay.portlet.asset.model.AssetRenderer;
027    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
028    import com.liferay.portlet.assetpublisher.util.AssetPublisherUtil;
029    import com.liferay.portlet.bookmarks.model.BookmarksEntry;
030    import com.liferay.portlet.bookmarks.service.BookmarksEntryLocalServiceUtil;
031    import com.liferay.portlet.bookmarks.service.permission.BookmarksEntryPermission;
032    import com.liferay.portlet.bookmarks.service.permission.BookmarksPermission;
033    
034    import javax.portlet.PortletURL;
035    
036    /**
037     * @author Julio Camarero
038     * @author Juan Fernández
039     * @author Raymond Augé
040     */
041    public class BookmarksEntryAssetRendererFactory
042            extends BaseAssetRendererFactory {
043    
044            public static final String CLASS_NAME =BookmarksEntry.class.getName();
045    
046            public static final String TYPE = "bookmark";
047    
048            public AssetRenderer getAssetRenderer(long classPK, int type)
049                    throws PortalException, SystemException {
050    
051                    BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
052    
053                    return new BookmarksEntryAssetRenderer(entry);
054            }
055    
056            public String getClassName() {
057                    return CLASS_NAME;
058            }
059    
060            public String getType() {
061                    return TYPE;
062            }
063    
064            public PortletURL getURLAdd(
065                    LiferayPortletRequest liferayPortletRequest,
066                    LiferayPortletResponse liferayPortletResponse) {
067    
068                    ThemeDisplay themeDisplay =
069                            (ThemeDisplay)liferayPortletRequest.getAttribute(
070                                    WebKeys.THEME_DISPLAY);
071    
072                    PortletURL addAssetURL = null;
073    
074                    if (BookmarksPermission.contains(
075                                    themeDisplay.getPermissionChecker(),
076                                    themeDisplay.getScopeGroupId(), ActionKeys.ADD_ENTRY)) {
077    
078                            addAssetURL = liferayPortletResponse.createRenderURL(
079                                    PortletKeys.BOOKMARKS);
080    
081                            addAssetURL.setParameter(
082                                    "struts_action", "/bookmarks/edit_entry");
083                            addAssetURL.setParameter(
084                                    "groupId", String.valueOf(themeDisplay.getScopeGroupId()));
085                            addAssetURL.setParameter(
086                                    "folderId",
087                                    String.valueOf(
088                                            AssetPublisherUtil.getRecentFolderId(
089                                                    liferayPortletRequest, CLASS_NAME)));
090                    }
091    
092                    return addAssetURL;
093            }
094    
095            public boolean hasPermission(
096                            PermissionChecker permissionChecker, long classPK, String actionId)
097                    throws Exception {
098    
099                    return BookmarksEntryPermission.contains(
100                            permissionChecker, classPK, actionId);
101            }
102    
103            protected String getIconPath(ThemeDisplay themeDisplay) {
104                    return themeDisplay.getPathThemeImages() + "/ratings/star_hover.png";
105            }
106    
107    }