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