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.bookmarks.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.bookmarks.model.BookmarksFolder;
026    import com.liferay.portlet.bookmarks.service.BookmarksFolderLocalServiceUtil;
027    import com.liferay.portlet.bookmarks.service.permission.BookmarksFolderPermission;
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 BookmarksFolderAssetRendererFactory
038            extends BaseAssetRendererFactory {
039    
040            public static final String TYPE = "bookmark_folder";
041    
042            public BookmarksFolderAssetRendererFactory() {
043                    setCategorizable(false);
044            }
045    
046            @Override
047            public AssetRenderer getAssetRenderer(long classPK, int type)
048                    throws PortalException {
049    
050                    BookmarksFolder folder = BookmarksFolderLocalServiceUtil.getFolder(
051                            classPK);
052    
053                    BookmarksFolderAssetRenderer bookmarksFolderAssetRenderer =
054                            new BookmarksFolderAssetRenderer(folder);
055    
056                    bookmarksFolderAssetRenderer.setAssetRendererType(type);
057    
058                    return bookmarksFolderAssetRenderer;
059            }
060    
061            @Override
062            public String getClassName() {
063                    return BookmarksFolder.class.getName();
064            }
065    
066            @Override
067            public String getIconCssClass() {
068                    return "icon-folder-close";
069            }
070    
071            @Override
072            public String getType() {
073                    return TYPE;
074            }
075    
076            @Override
077            public PortletURL getURLView(
078                    LiferayPortletResponse liferayPortletResponse,
079                    WindowState windowState) {
080    
081                    LiferayPortletURL liferayPortletURL =
082                            liferayPortletResponse.createLiferayPortletURL(
083                                    PortletKeys.BOOKMARKS, 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                    BookmarksFolder folder = BookmarksFolderLocalServiceUtil.getFolder(
100                            classPK);
101    
102                    return BookmarksFolderPermission.contains(
103                            permissionChecker, folder, actionId);
104            }
105    
106            @Override
107            protected String getIconPath(ThemeDisplay themeDisplay) {
108                    return themeDisplay.getPathThemeImages() + "/common/folder.png";
109            }
110    
111    }