001    /**
002     * Copyright (c) 2000-2012 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.exception.SystemException;
019    import com.liferay.portal.security.permission.PermissionChecker;
020    import com.liferay.portal.theme.ThemeDisplay;
021    import com.liferay.portlet.asset.model.AssetRenderer;
022    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
023    import com.liferay.portlet.journal.model.JournalFolder;
024    import com.liferay.portlet.journal.service.JournalFolderLocalServiceUtil;
025    import com.liferay.portlet.journal.service.permission.JournalFolderPermission;
026    
027    /**
028     * @author Alexander Chow
029     */
030    public class JournalFolderAssetRendererFactory
031            extends BaseAssetRendererFactory {
032    
033            public static final String CLASS_NAME = JournalFolder.class.getName();
034    
035            public static final String TYPE = "folder";
036    
037            public AssetRenderer getAssetRenderer(long classPK, int type)
038                    throws PortalException, SystemException {
039    
040                    JournalFolder folder = JournalFolderLocalServiceUtil.getFolder(classPK);
041    
042                    return new JournalFolderAssetRenderer(folder);
043            }
044    
045            public String getClassName() {
046                    return CLASS_NAME;
047            }
048    
049            public String getType() {
050                    return TYPE;
051            }
052    
053            @Override
054            public boolean hasPermission(
055                            PermissionChecker permissionChecker, long classPK, String actionId)
056                    throws Exception {
057    
058                    JournalFolder folder = JournalFolderLocalServiceUtil.getFolder(classPK);
059    
060                    return JournalFolderPermission.contains(
061                            permissionChecker, folder, actionId);
062            }
063    
064            @Override
065            public boolean isLinkable() {
066                    return _LINKABLE;
067            }
068    
069            @Override
070            protected String getIconPath(ThemeDisplay themeDisplay) {
071                    return themeDisplay.getPathThemeImages() + "/common/folder.png";
072            }
073    
074            private static final boolean _LINKABLE = true;
075    
076    }