1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.blogs.asset;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
20  import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
21  import com.liferay.portal.security.permission.ActionKeys;
22  import com.liferay.portal.theme.ThemeDisplay;
23  import com.liferay.portal.util.PortletKeys;
24  import com.liferay.portal.util.WebKeys;
25  import com.liferay.portlet.asset.model.AssetRenderer;
26  import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
27  import com.liferay.portlet.blogs.model.BlogsEntry;
28  import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
29  import com.liferay.portlet.blogs.service.BlogsEntryServiceUtil;
30  import com.liferay.portlet.blogs.service.permission.BlogsPermission;
31  
32  import javax.portlet.PortletURL;
33  
34  /**
35   * <a href="BlogsEntryAssetRendererFactory.java.html"><b><i>View Source</i></b>
36   * </a>
37   *
38   * @author Jorge Ferrer
39   * @author Juan Fernández
40   */
41  public class BlogsEntryAssetRendererFactory extends BaseAssetRendererFactory {
42  
43      public static final String CLASS_NAME = BlogsEntry.class.getName();
44  
45      public static final String TYPE = "blog";
46  
47      public AssetRenderer getAssetRenderer(long classPK)
48          throws PortalException, SystemException {
49  
50          BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(classPK);
51  
52          return new BlogsEntryAssetRenderer(entry);
53      }
54  
55      public AssetRenderer getAssetRenderer(long groupId, String urlTitle)
56          throws PortalException, SystemException {
57  
58          BlogsEntry entry = BlogsEntryServiceUtil.getEntry(groupId, urlTitle);
59  
60          return new BlogsEntryAssetRenderer(entry);
61      }
62  
63      public String getClassName() {
64          return CLASS_NAME;
65      }
66  
67      public String getType() {
68          return TYPE;
69      }
70  
71      public PortletURL getURLAdd(
72          LiferayPortletRequest liferayPortletRequest,
73          LiferayPortletResponse liferayPortletResponse) {
74  
75          ThemeDisplay themeDisplay =
76              (ThemeDisplay)liferayPortletRequest.getAttribute(
77                  WebKeys.THEME_DISPLAY);
78  
79          PortletURL addAssetURL = null;
80  
81          if (BlogsPermission.contains(
82                  themeDisplay.getPermissionChecker(),
83                  themeDisplay.getScopeGroupId(), ActionKeys.ADD_ENTRY)) {
84  
85              addAssetURL = liferayPortletResponse.createRenderURL(
86                  PortletKeys.BLOGS);
87  
88              addAssetURL.setParameter("struts_action", "/blogs/edit_entry");
89          }
90  
91          return addAssetURL;
92      }
93  
94      protected String getIconPath(ThemeDisplay themeDisplay) {
95          return themeDisplay.getPathThemeImages() + "/blogs/blogs.png";
96      }
97  
98  }