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.portlet.LiferayPortletResponse;
020    import com.liferay.portal.kernel.portlet.LiferayPortletURL;
021    import com.liferay.portal.kernel.repository.model.Folder;
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    public class DLFolderAssetRendererFactory extends BaseAssetRendererFactory {
040    
041            public static final String TYPE = "document_folder";
042    
043            @Override
044            public AssetRenderer getAssetRenderer(long classPK, int type)
045                    throws PortalException, SystemException {
046    
047                    Folder folder = DLAppLocalServiceUtil.getFolder(classPK);
048    
049                    DLFolderAssetRenderer dlFolderAssetRenderer = new DLFolderAssetRenderer(
050                            folder);
051    
052                    dlFolderAssetRenderer.setAssetRendererType(type);
053    
054                    return dlFolderAssetRenderer;
055            }
056    
057            @Override
058            public String getClassName() {
059                    return DLFolder.class.getName();
060            }
061    
062            @Override
063            public String getType() {
064                    return TYPE;
065            }
066    
067            @Override
068            public PortletURL getURLView(
069                    LiferayPortletResponse liferayPortletResponse,
070                    WindowState windowState) {
071    
072                    LiferayPortletURL liferayPortletURL =
073                            liferayPortletResponse.createLiferayPortletURL(
074                                    PortletKeys.DOCUMENT_LIBRARY_DISPLAY,
075                                    PortletRequest.RENDER_PHASE);
076    
077                    try {
078                            liferayPortletURL.setWindowState(windowState);
079                    }
080                    catch (WindowStateException wse) {
081                    }
082    
083                    return liferayPortletURL;
084            }
085    
086            @Override
087            public boolean hasPermission(
088                            PermissionChecker permissionChecker, long classPK, String actionId)
089                    throws Exception {
090    
091                    Folder folder = DLAppLocalServiceUtil.getFolder(classPK);
092    
093                    return DLFolderPermission.contains(permissionChecker, folder, actionId);
094            }
095    
096            @Override
097            public boolean isCategorizable() {
098                    return _CATEGORIZABLE;
099            }
100    
101            @Override
102            public boolean isLinkable() {
103                    return _LINKABLE;
104            }
105    
106            @Override
107            protected String getIconPath(ThemeDisplay themeDisplay) {
108                    return themeDisplay.getPathThemeImages() + "/common/folder.png";
109            }
110    
111            private static final boolean _CATEGORIZABLE = false;
112    
113            private static final boolean _LINKABLE = false;
114    
115    }