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.documentlibrary.asset;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.repository.model.Folder;
020    import com.liferay.portal.security.permission.PermissionChecker;
021    import com.liferay.portal.theme.ThemeDisplay;
022    import com.liferay.portlet.asset.model.AssetRenderer;
023    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
024    import com.liferay.portlet.documentlibrary.model.DLFolder;
025    import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
026    import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
027    
028    /**
029     * @author Alexander Chow
030     */
031    public class DLFolderAssetRendererFactory extends BaseAssetRendererFactory {
032    
033            public static final String TYPE = "folder";
034    
035            public AssetRenderer getAssetRenderer(long classPK, int type)
036                    throws PortalException, SystemException {
037    
038                    Folder folder = DLAppLocalServiceUtil.getFolder(classPK);
039    
040                    DLFolderAssetRenderer dlFolderAssetRenderer = new DLFolderAssetRenderer(
041                            folder);
042    
043                    dlFolderAssetRenderer.setAssetRendererType(type);
044    
045                    return dlFolderAssetRenderer;
046            }
047    
048            public String getClassName() {
049                    return DLFolder.class.getName();
050            }
051    
052            public String getType() {
053                    return TYPE;
054            }
055    
056            @Override
057            public boolean hasPermission(
058                            PermissionChecker permissionChecker, long classPK, String actionId)
059                    throws Exception {
060    
061                    Folder folder = DLAppLocalServiceUtil.getFolder(classPK);
062    
063                    return DLFolderPermission.contains(permissionChecker, folder, actionId);
064            }
065    
066            @Override
067            public boolean isCategorizable() {
068                    return _CATEGORIZABLE;
069            }
070    
071            @Override
072            public boolean isLinkable() {
073                    return _LINKABLE;
074            }
075    
076            @Override
077            protected String getIconPath(ThemeDisplay themeDisplay) {
078                    return themeDisplay.getPathThemeImages() + "/common/folder.png";
079            }
080    
081            private static final boolean _CATEGORIZABLE = false;
082    
083            private static final boolean _LINKABLE = true;
084    
085    }