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.portlet.LiferayPortletRequest;
18  import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
19  import com.liferay.portal.security.permission.ActionKeys;
20  import com.liferay.portal.theme.ThemeDisplay;
21  import com.liferay.portal.util.PortletKeys;
22  import com.liferay.portal.util.WebKeys;
23  import com.liferay.portlet.asset.model.AssetRenderer;
24  import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
25  import com.liferay.portlet.blogs.model.BlogsEntry;
26  import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
27  import com.liferay.portlet.blogs.service.BlogsEntryServiceUtil;
28  import com.liferay.portlet.blogs.service.permission.BlogsPermission;
29  
30  import javax.portlet.PortletURL;
31  
32  /**
33   * <a href="BlogsEntryAssetRendererFactory.java.html"><b><i>View Source</i></b>
34   * </a>
35   *
36   * @author Jorge Ferrer
37   */
38  public class BlogsEntryAssetRendererFactory extends BaseAssetRendererFactory {
39  
40      public static final String CLASS_NAME = BlogsEntry.class.getName();
41  
42      public static final String TYPE = "blog";
43  
44      public AssetRenderer getAssetRenderer(long classPK) throws Exception {
45          BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(classPK);
46  
47          return new BlogsEntryAssetRenderer(entry);
48      }
49  
50      public AssetRenderer getAssetRenderer(long groupId, String urlTitle)
51          throws Exception {
52  
53          BlogsEntry entry = BlogsEntryServiceUtil.getEntry(groupId, urlTitle);
54  
55          return new BlogsEntryAssetRenderer(entry);
56      }
57  
58      public String getClassName() {
59          return CLASS_NAME;
60      }
61  
62      public String getType() {
63          return TYPE;
64      }
65  
66      public PortletURL getURLAdd(
67          LiferayPortletRequest liferayPortletRequest,
68          LiferayPortletResponse liferayPortletResponse) {
69  
70          ThemeDisplay themeDisplay =
71              (ThemeDisplay)liferayPortletRequest.getAttribute(
72                  WebKeys.THEME_DISPLAY);
73  
74          PortletURL addAssetURL = null;
75  
76          if (BlogsPermission.contains(
77                  themeDisplay.getPermissionChecker(),
78                  themeDisplay.getScopeGroupId(), ActionKeys.ADD_ENTRY)) {
79  
80              addAssetURL = liferayPortletResponse.createRenderURL(
81                  PortletKeys.BLOGS);
82  
83              addAssetURL.setParameter("struts_action", "/blogs/edit_entry");
84          }
85  
86          return addAssetURL;
87      }
88  
89  }