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.journal.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.security.permission.PermissionChecker;
021    import com.liferay.portal.theme.ThemeDisplay;
022    import com.liferay.portal.util.PortletKeys;
023    import com.liferay.portlet.asset.model.AssetRenderer;
024    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
025    import com.liferay.portlet.journal.model.JournalFolder;
026    import com.liferay.portlet.journal.service.JournalFolderLocalServiceUtil;
027    import com.liferay.portlet.journal.service.permission.JournalFolderPermission;
028    
029    import javax.portlet.PortletRequest;
030    import javax.portlet.PortletURL;
031    import javax.portlet.WindowState;
032    import javax.portlet.WindowStateException;
033    
034    /**
035     * @author Alexander Chow
036     */
037    public class JournalFolderAssetRendererFactory
038            extends BaseAssetRendererFactory {
039    
040            public static final String TYPE = "content_folder";
041    
042            public JournalFolderAssetRendererFactory() {
043                    setCategorizable(false);
044            }
045    
046            @Override
047            public AssetRenderer getAssetRenderer(long classPK, int type)
048                    throws PortalException {
049    
050                    JournalFolder folder = JournalFolderLocalServiceUtil.getFolder(classPK);
051    
052                    JournalFolderAssetRenderer journalFolderAssetRenderer =
053                            new JournalFolderAssetRenderer(folder);
054    
055                    journalFolderAssetRenderer.setAssetRendererType(type);
056    
057                    return journalFolderAssetRenderer;
058            }
059    
060            @Override
061            public String getClassName() {
062                    return JournalFolder.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.JOURNAL, PortletRequest.RENDER_PHASE);
083    
084                    try {
085                            liferayPortletURL.setWindowState(windowState);
086                    }
087                    catch (WindowStateException wse) {
088                    }
089    
090                    return liferayPortletURL;
091            }
092    
093            @Override
094            public boolean hasPermission(
095                            PermissionChecker permissionChecker, long classPK, String actionId)
096                    throws Exception {
097    
098                    JournalFolder folder = JournalFolderLocalServiceUtil.getFolder(classPK);
099    
100                    return JournalFolderPermission.contains(
101                            permissionChecker, folder, actionId);
102            }
103    
104            @Override
105            protected String getIconPath(ThemeDisplay themeDisplay) {
106                    return themeDisplay.getPathThemeImages() + "/common/folder.png";
107            }
108    
109    }