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.journal.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.journal.model.JournalArticle;
28  import com.liferay.portlet.journal.model.JournalArticleResource;
29  import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
30  import com.liferay.portlet.journal.service.JournalArticleResourceLocalServiceUtil;
31  import com.liferay.portlet.journal.service.JournalArticleServiceUtil;
32  import com.liferay.portlet.journal.service.permission.JournalPermission;
33  
34  import javax.portlet.PortletURL;
35  
36  /**
37   * <a href="JournalArticleAssetRendererFactory.java.html"><b><i>View Source</i>
38   * </b></a>
39   *
40   * @author Julio Camarero
41   * @author Juan Fernández
42   */
43  public class JournalArticleAssetRendererFactory
44      extends BaseAssetRendererFactory {
45  
46      public static final String CLASS_NAME = JournalArticle.class.getName();
47  
48      public static final String TYPE = "content";
49  
50      public AssetRenderer getAssetRenderer(long classPK)
51          throws PortalException, SystemException {
52  
53          JournalArticleResource articleResource =
54              JournalArticleResourceLocalServiceUtil.getArticleResource(classPK);
55  
56          JournalArticle article =
57              JournalArticleLocalServiceUtil.getArticle(
58                  articleResource.getGroupId(), articleResource.getArticleId());
59  
60          return new JournalArticleAssetRenderer(article);
61      }
62  
63      public AssetRenderer getAssetRenderer(long groupId, String urlTitle)
64          throws PortalException, SystemException {
65  
66          JournalArticle article = JournalArticleServiceUtil.getArticleByUrlTitle(
67              groupId, urlTitle);
68  
69          return new JournalArticleAssetRenderer(article);
70      }
71  
72      public String getClassName() {
73          return CLASS_NAME;
74      }
75  
76      public String getType() {
77          return TYPE;
78      }
79  
80      public PortletURL getURLAdd(
81          LiferayPortletRequest liferayPortletRequest,
82          LiferayPortletResponse liferayPortletResponse) {
83  
84          ThemeDisplay themeDisplay =
85              (ThemeDisplay)liferayPortletRequest.getAttribute(
86                  WebKeys.THEME_DISPLAY);
87  
88          PortletURL addAssetURL = null;
89  
90          if (JournalPermission.contains(
91                  themeDisplay.getPermissionChecker(),
92                  themeDisplay.getScopeGroupId(), ActionKeys.ADD_ARTICLE)) {
93  
94              addAssetURL = liferayPortletResponse.createRenderURL(
95                  PortletKeys.JOURNAL);
96  
97              addAssetURL.setParameter("struts_action", "/journal/edit_article");
98              addAssetURL.setParameter(
99                  "groupId", String.valueOf(themeDisplay.getScopeGroupId()));
100         }
101 
102         return addAssetURL;
103     }
104 
105     protected String getIconPath(ThemeDisplay themeDisplay) {
106         return themeDisplay.getPathThemeImages() + "/common/history.png";
107     }
108 
109 }