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.bookmarks.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.security.permission.PermissionChecker;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portal.util.PortletKeys;
024    import com.liferay.portlet.asset.model.AssetRenderer;
025    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
026    import com.liferay.portlet.bookmarks.model.BookmarksFolder;
027    import com.liferay.portlet.bookmarks.service.BookmarksFolderLocalServiceUtil;
028    import com.liferay.portlet.bookmarks.service.permission.BookmarksFolderPermission;
029    
030    import javax.portlet.PortletRequest;
031    import javax.portlet.PortletURL;
032    import javax.portlet.WindowState;
033    import javax.portlet.WindowStateException;
034    
035    /**
036     * @author Alexander Chow
037     */
038    public class BookmarksFolderAssetRendererFactory
039            extends BaseAssetRendererFactory {
040    
041            public static final String TYPE = "bookmark_folder";
042    
043            @Override
044            public AssetRenderer getAssetRenderer(long classPK, int type)
045                    throws PortalException, SystemException {
046    
047                    BookmarksFolder folder = BookmarksFolderLocalServiceUtil.getFolder(
048                            classPK);
049    
050                    BookmarksFolderAssetRenderer bookmarksFolderAssetRenderer =
051                            new BookmarksFolderAssetRenderer(folder);
052    
053                    bookmarksFolderAssetRenderer.setAssetRendererType(type);
054    
055                    return bookmarksFolderAssetRenderer;
056            }
057    
058            @Override
059            public String getClassName() {
060                    return BookmarksFolder.class.getName();
061            }
062    
063            @Override
064            public String getType() {
065                    return TYPE;
066            }
067    
068            @Override
069            public PortletURL getURLView(
070                    LiferayPortletResponse liferayPortletResponse,
071                    WindowState windowState) {
072    
073                    LiferayPortletURL liferayPortletURL =
074                            liferayPortletResponse.createLiferayPortletURL(
075                                    PortletKeys.BOOKMARKS, 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                    BookmarksFolder folder = BookmarksFolderLocalServiceUtil.getFolder(
092                            classPK);
093    
094                    return BookmarksFolderPermission.contains(
095                            permissionChecker, folder, actionId);
096            }
097    
098            @Override
099            public boolean isCategorizable() {
100                    return _CATEGORIZABLE;
101            }
102    
103            @Override
104            public boolean isLinkable() {
105                    return _LINKABLE;
106            }
107    
108            @Override
109            protected String getIconPath(ThemeDisplay themeDisplay) {
110                    return themeDisplay.getPathThemeImages() + "/common/folder.png";
111            }
112    
113            private static final boolean _CATEGORIZABLE = false;
114    
115            private static final boolean _LINKABLE = false;
116    
117    }