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.blogs.asset;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
019    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
020    import com.liferay.portal.kernel.portlet.LiferayPortletURL;
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.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.BlogsEntryPermission;
031    import com.liferay.portlet.blogs.service.permission.BlogsPermission;
032    
033    import javax.portlet.PortletRequest;
034    import javax.portlet.PortletURL;
035    import javax.portlet.WindowState;
036    import javax.portlet.WindowStateException;
037    
038    /**
039     * @author Jorge Ferrer
040     * @author Juan Fern??ndez
041     * @author Raymond Aug??
042     * @author Sergio Gonz??lez
043     */
044    public class BlogsEntryAssetRendererFactory extends BaseAssetRendererFactory {
045    
046            public static final String TYPE = "blog";
047    
048            public BlogsEntryAssetRendererFactory() {
049                    setLinkable(true);
050            }
051    
052            @Override
053            public AssetRenderer getAssetRenderer(long classPK, int type)
054                    throws PortalException {
055    
056                    BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(classPK);
057    
058                    BlogsEntryAssetRenderer blogsEntryAssetRenderer =
059                            new BlogsEntryAssetRenderer(entry);
060    
061                    blogsEntryAssetRenderer.setAssetRendererType(type);
062    
063                    return blogsEntryAssetRenderer;
064            }
065    
066            @Override
067            public AssetRenderer getAssetRenderer(long groupId, String urlTitle)
068                    throws PortalException {
069    
070                    BlogsEntry entry = BlogsEntryServiceUtil.getEntry(groupId, urlTitle);
071    
072                    return new BlogsEntryAssetRenderer(entry);
073            }
074    
075            @Override
076            public String getClassName() {
077                    return BlogsEntry.class.getName();
078            }
079    
080            @Override
081            public String getIconCssClass() {
082                    return "icon-edit";
083            }
084    
085            @Override
086            public String getType() {
087                    return TYPE;
088            }
089    
090            @Override
091            public PortletURL getURLAdd(
092                    LiferayPortletRequest liferayPortletRequest,
093                    LiferayPortletResponse liferayPortletResponse) {
094    
095                    PortletURL portletURL = liferayPortletResponse.createRenderURL(
096                            PortletKeys.BLOGS);
097    
098                    portletURL.setParameter("struts_action", "/blogs/edit_entry");
099    
100                    return portletURL;
101            }
102    
103            @Override
104            public PortletURL getURLView(
105                    LiferayPortletResponse liferayPortletResponse,
106                    WindowState windowState) {
107    
108                    LiferayPortletURL liferayPortletURL =
109                            liferayPortletResponse.createLiferayPortletURL(
110                                    PortletKeys.BLOGS, PortletRequest.RENDER_PHASE);
111    
112                    try {
113                            liferayPortletURL.setWindowState(windowState);
114                    }
115                    catch (WindowStateException wse) {
116                    }
117    
118                    return liferayPortletURL;
119            }
120    
121            @Override
122            public boolean hasAddPermission(
123                            PermissionChecker permissionChecker, long groupId, long classTypeId)
124                    throws Exception {
125    
126                    return BlogsPermission.contains(
127                            permissionChecker, groupId, ActionKeys.ADD_ENTRY);
128            }
129    
130            @Override
131            public boolean hasPermission(
132                            PermissionChecker permissionChecker, long classPK, String actionId)
133                    throws Exception {
134    
135                    return BlogsEntryPermission.contains(
136                            permissionChecker, classPK, actionId);
137            }
138    
139            @Override
140            protected String getIconPath(ThemeDisplay themeDisplay) {
141                    return themeDisplay.getPathThemeImages() + "/blogs/blogs.png";
142            }
143    
144    }