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