001    /**
002     * Copyright (c) 2000-2013 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 TYPE = "bookmarks_folder";
034    
035            public AssetRenderer getAssetRenderer(long classPK, int type)
036                    throws PortalException, SystemException {
037    
038                    BookmarksFolder folder = BookmarksFolderLocalServiceUtil.getFolder(
039                            classPK);
040    
041                    BookmarksFolderAssetRenderer bookmarksFolderAssetRenderer =
042                            new BookmarksFolderAssetRenderer(folder);
043    
044                    bookmarksFolderAssetRenderer.setAssetRendererType(type);
045    
046                    return bookmarksFolderAssetRenderer;
047            }
048    
049            public String getClassName() {
050                    return BookmarksFolder.class.getName();
051            }
052    
053            public String getType() {
054                    return TYPE;
055            }
056    
057            @Override
058            public boolean hasPermission(
059                            PermissionChecker permissionChecker, long classPK, String actionId)
060                    throws Exception {
061    
062                    BookmarksFolder folder = BookmarksFolderLocalServiceUtil.getFolder(
063                            classPK);
064    
065                    return BookmarksFolderPermission.contains(
066                            permissionChecker, folder, actionId);
067            }
068    
069            @Override
070            public boolean isCategorizable() {
071                    return _CATEGORIZABLE;
072            }
073    
074            @Override
075            public boolean isLinkable() {
076                    return _LINKABLE;
077            }
078    
079            @Override
080            protected String getIconPath(ThemeDisplay themeDisplay) {
081                    return themeDisplay.getPathThemeImages() + "/common/folder.png";
082            }
083    
084            private static final boolean _CATEGORIZABLE = false;
085    
086            private static final boolean _LINKABLE = true;
087    
088    }