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   */
40  public class BlogsEntryAssetRendererFactory extends BaseAssetRendererFactory {
41  
42      public static final String CLASS_NAME = BlogsEntry.class.getName();
43  
44      public static final String TYPE = "blog";
45  
46      public AssetRenderer getAssetRenderer(long classPK)
47          throws PortalException, SystemException {
48  
49          BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(classPK);
50  
51          return new BlogsEntryAssetRenderer(entry);
52      }
53  
54      public AssetRenderer getAssetRenderer(long groupId, String urlTitle)
55          throws PortalException, SystemException {
56  
57          BlogsEntry entry = BlogsEntryServiceUtil.getEntry(groupId, urlTitle);
58  
59          return new BlogsEntryAssetRenderer(entry);
60      }
61  
62      public String getClassName() {
63          return CLASS_NAME;
64      }
65  
66      public String getType() {
67          return TYPE;
68      }
69  
70      public PortletURL getURLAdd(
71          LiferayPortletRequest liferayPortletRequest,
72          LiferayPortletResponse liferayPortletResponse) {
73  
74          ThemeDisplay themeDisplay =
75              (ThemeDisplay)liferayPortletRequest.getAttribute(
76                  WebKeys.THEME_DISPLAY);
77  
78          PortletURL addAssetURL = null;
79  
80          if (BlogsPermission.contains(
81                  themeDisplay.getPermissionChecker(),
82                  themeDisplay.getScopeGroupId(), ActionKeys.ADD_ENTRY)) {
83  
84              addAssetURL = liferayPortletResponse.createRenderURL(
85                  PortletKeys.BLOGS);
86  
87              addAssetURL.setParameter("struts_action", "/blogs/edit_entry");
88          }
89  
90          return addAssetURL;
91      }
92  
93  }