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.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.kernel.portlet.LiferayPortletURL;
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    public class BlogsEntryAssetRendererFactory extends BaseAssetRendererFactory {
046    
047            public static final String TYPE = "blog";
048    
049            @Override
050            public AssetRenderer getAssetRenderer(long classPK, int type)
051                    throws PortalException, SystemException {
052    
053                    BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(classPK);
054    
055                    BlogsEntryAssetRenderer blogsEntryAssetRenderer =
056                            new BlogsEntryAssetRenderer(entry);
057    
058                    blogsEntryAssetRenderer.setAssetRendererType(type);
059    
060                    return blogsEntryAssetRenderer;
061            }
062    
063            @Override
064            public AssetRenderer getAssetRenderer(long groupId, String urlTitle)
065                    throws PortalException, SystemException {
066    
067                    BlogsEntry entry = BlogsEntryServiceUtil.getEntry(groupId, urlTitle);
068    
069                    return new BlogsEntryAssetRenderer(entry);
070            }
071    
072            @Override
073            public String getClassName() {
074                    return BlogsEntry.class.getName();
075            }
076    
077            @Override
078            public String getType() {
079                    return TYPE;
080            }
081    
082            @Override
083            public PortletURL getURLAdd(
084                    LiferayPortletRequest liferayPortletRequest,
085                    LiferayPortletResponse liferayPortletResponse) {
086    
087                    PortletURL portletURL = liferayPortletResponse.createRenderURL(
088                            PortletKeys.BLOGS);
089    
090                    portletURL.setParameter("struts_action", "/blogs/edit_entry");
091    
092                    return portletURL;
093            }
094    
095            @Override
096            public PortletURL getURLView(
097                    LiferayPortletResponse liferayPortletResponse,
098                    WindowState windowState) {
099    
100                    LiferayPortletURL liferayPortletURL =
101                            liferayPortletResponse.createLiferayPortletURL(
102                                    PortletKeys.BLOGS, PortletRequest.RENDER_PHASE);
103    
104                    try {
105                            liferayPortletURL.setWindowState(windowState);
106                    }
107                    catch (WindowStateException wse) {
108                    }
109    
110                    return liferayPortletURL;
111            }
112    
113            @Override
114            public boolean hasAddPermission(
115                            PermissionChecker permissionChecker, long groupId, long classTypeId)
116                    throws Exception {
117    
118                    return BlogsPermission.contains(
119                            permissionChecker, groupId, ActionKeys.ADD_ENTRY);
120            }
121    
122            @Override
123            public boolean hasPermission(
124                            PermissionChecker permissionChecker, long classPK, String actionId)
125                    throws Exception {
126    
127                    return BlogsEntryPermission.contains(
128                            permissionChecker, classPK, actionId);
129            }
130    
131            @Override
132            public boolean isLinkable() {
133                    return _LINKABLE;
134            }
135    
136            @Override
137            protected String getIconPath(ThemeDisplay themeDisplay) {
138                    return themeDisplay.getPathThemeImages() + "/blogs/blogs.png";
139            }
140    
141            private static final boolean _LINKABLE = true;
142    
143    }