001    /**
002     * Copyright (c) 2000-present 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.portlet.LiferayPortletResponse;
019    import com.liferay.portal.kernel.portlet.LiferayPortletURL;
020    import com.liferay.portal.kernel.repository.model.Folder;
021    import com.liferay.portal.security.permission.PermissionChecker;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portal.util.PortletKeys;
024    import com.liferay.portlet.asset.model.AssetRenderer;
025    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
026    import com.liferay.portlet.documentlibrary.model.DLFolder;
027    import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
028    import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
029    
030    import javax.portlet.PortletRequest;
031    import javax.portlet.PortletURL;
032    import javax.portlet.WindowState;
033    import javax.portlet.WindowStateException;
034    
035    /**
036     * @author Alexander Chow
037     */
038    public class DLFolderAssetRendererFactory extends BaseAssetRendererFactory {
039    
040            public static final String TYPE = "document_folder";
041    
042            public DLFolderAssetRendererFactory() {
043                    setCategorizable(false);
044            }
045    
046            @Override
047            public AssetRenderer getAssetRenderer(long classPK, int type)
048                    throws PortalException {
049    
050                    Folder folder = DLAppLocalServiceUtil.getFolder(classPK);
051    
052                    DLFolderAssetRenderer dlFolderAssetRenderer = new DLFolderAssetRenderer(
053                            folder);
054    
055                    dlFolderAssetRenderer.setAssetRendererType(type);
056    
057                    return dlFolderAssetRenderer;
058            }
059    
060            @Override
061            public String getClassName() {
062                    return DLFolder.class.getName();
063            }
064    
065            @Override
066            public String getIconCssClass() {
067                    return "icon-folder-close";
068            }
069    
070            @Override
071            public String getType() {
072                    return TYPE;
073            }
074    
075            @Override
076            public PortletURL getURLView(
077                    LiferayPortletResponse liferayPortletResponse,
078                    WindowState windowState) {
079    
080                    LiferayPortletURL liferayPortletURL =
081                            liferayPortletResponse.createLiferayPortletURL(
082                                    PortletKeys.DOCUMENT_LIBRARY_DISPLAY,
083                                    PortletRequest.RENDER_PHASE);
084    
085                    try {
086                            liferayPortletURL.setWindowState(windowState);
087                    }
088                    catch (WindowStateException wse) {
089                    }
090    
091                    return liferayPortletURL;
092            }
093    
094            @Override
095            public boolean hasPermission(
096                            PermissionChecker permissionChecker, long classPK, String actionId)
097                    throws Exception {
098    
099                    Folder folder = DLAppLocalServiceUtil.getFolder(classPK);
100    
101                    return DLFolderPermission.contains(permissionChecker, folder, actionId);
102            }
103    
104            @Override
105            protected String getIconPath(ThemeDisplay themeDisplay) {
106                    return themeDisplay.getPathThemeImages() + "/common/folder.png";
107            }
108    
109    }