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