001    /**
002     * Copyright (c) 2000-2010 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.blogs.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.LiferayPortletRequest;
020    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
021    import com.liferay.portal.security.permission.ActionKeys;
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.portal.util.WebKeys;
026    import com.liferay.portlet.asset.model.AssetRenderer;
027    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
028    import com.liferay.portlet.blogs.model.BlogsEntry;
029    import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
030    import com.liferay.portlet.blogs.service.BlogsEntryServiceUtil;
031    import com.liferay.portlet.blogs.service.permission.BlogsEntryPermission;
032    import com.liferay.portlet.blogs.service.permission.BlogsPermission;
033    
034    import javax.portlet.PortletURL;
035    
036    /**
037     * @author Jorge Ferrer
038     * @author Juan Fernández
039     * @author Raymond Augé
040     */
041    public class BlogsEntryAssetRendererFactory extends BaseAssetRendererFactory {
042    
043            public static final String CLASS_NAME = BlogsEntry.class.getName();
044    
045            public static final String TYPE = "blog";
046    
047            public AssetRenderer getAssetRenderer(long classPK, int type)
048                    throws PortalException, SystemException {
049    
050                    BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(classPK);
051    
052                    return new BlogsEntryAssetRenderer(entry);
053            }
054    
055            public AssetRenderer getAssetRenderer(long groupId, String urlTitle)
056                    throws PortalException, SystemException {
057    
058                    BlogsEntry entry = BlogsEntryServiceUtil.getEntry(groupId, urlTitle);
059    
060                    return new BlogsEntryAssetRenderer(entry);
061            }
062    
063            public String getClassName() {
064                    return CLASS_NAME;
065            }
066    
067            public String getType() {
068                    return TYPE;
069            }
070    
071            public PortletURL getURLAdd(
072                    LiferayPortletRequest liferayPortletRequest,
073                    LiferayPortletResponse liferayPortletResponse) {
074    
075                    ThemeDisplay themeDisplay =
076                            (ThemeDisplay)liferayPortletRequest.getAttribute(
077                                    WebKeys.THEME_DISPLAY);
078    
079                    PortletURL addAssetURL = null;
080    
081                    if (BlogsPermission.contains(
082                                    themeDisplay.getPermissionChecker(),
083                                    themeDisplay.getScopeGroupId(), ActionKeys.ADD_ENTRY)) {
084    
085                            addAssetURL = liferayPortletResponse.createRenderURL(
086                                    PortletKeys.BLOGS);
087    
088                            addAssetURL.setParameter("struts_action", "/blogs/edit_entry");
089                    }
090    
091                    return addAssetURL;
092            }
093    
094            public boolean hasPermission(
095                            PermissionChecker permissionChecker, long classPK, String actionId)
096                    throws Exception {
097    
098                    return BlogsEntryPermission.contains(
099                            permissionChecker, classPK, actionId);
100            }
101    
102            protected String getIconPath(ThemeDisplay themeDisplay) {
103                    return themeDisplay.getPathThemeImages() + "/blogs/blogs.png";
104            }
105    
106    }