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