001    /**
002     * Copyright (c) 2000-2012 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.security.permission.PermissionChecker;
020    import com.liferay.portal.theme.ThemeDisplay;
021    import com.liferay.portlet.asset.model.AssetRenderer;
022    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
023    import com.liferay.portlet.bookmarks.model.BookmarksFolder;
024    import com.liferay.portlet.bookmarks.service.BookmarksFolderLocalServiceUtil;
025    import com.liferay.portlet.bookmarks.service.permission.BookmarksFolderPermission;
026    
027    /**
028     * @author Alexander Chow
029     */
030    public class BookmarksFolderAssetRendererFactory
031            extends BaseAssetRendererFactory {
032    
033            public static final String CLASS_NAME = BookmarksFolder.class.getName();
034    
035            public static final String TYPE = "bookmarks_folder";
036    
037            public AssetRenderer getAssetRenderer(long classPK, int type)
038                    throws PortalException, SystemException {
039    
040                    BookmarksFolder folder = BookmarksFolderLocalServiceUtil.getFolder(
041                            classPK);
042    
043                    return new BookmarksFolderAssetRenderer(folder);
044            }
045    
046            public String getClassName() {
047                    return CLASS_NAME;
048            }
049    
050            public String getType() {
051                    return TYPE;
052            }
053    
054            @Override
055            public boolean hasPermission(
056                            PermissionChecker permissionChecker, long classPK, String actionId)
057                    throws Exception {
058    
059                    BookmarksFolder folder = BookmarksFolderLocalServiceUtil.getFolder(
060                            classPK);
061    
062                    return BookmarksFolderPermission.contains(
063                            permissionChecker, folder, actionId);
064            }
065    
066            @Override
067            public boolean isLinkable() {
068                    return _LINKABLE;
069            }
070    
071            @Override
072            protected String getIconPath(ThemeDisplay themeDisplay) {
073                    return themeDisplay.getPathThemeImages() + "/common/folder.png";
074            }
075    
076            private static final boolean _LINKABLE = true;
077    
078    }