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.messageboards.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.messageboards.model.MBMessage;
28  import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
29  import com.liferay.portlet.messageboards.service.permission.MBPermission;
30  
31  import javax.portlet.PortletURL;
32  
33  /**
34   * <a href="MBMessageAssetRendererFactory.java.html"><b><i>View Source</i></b>
35   * </a>
36   *
37   * @author Julio Camarero
38   */
39  public class MBMessageAssetRendererFactory extends BaseAssetRendererFactory {
40  
41      public static final String CLASS_NAME = MBMessage.class.getName();
42  
43      public static final String TYPE = "message";
44  
45      public AssetRenderer getAssetRenderer(long classPK)
46          throws PortalException, SystemException {
47  
48          MBMessage message = MBMessageLocalServiceUtil.getMessage(classPK);
49  
50          return new MBMessageAssetRenderer(message);
51      }
52  
53      public String getClassName() {
54          return CLASS_NAME;
55      }
56  
57      public String getType() {
58          return TYPE;
59      }
60  
61      public PortletURL getURLAdd(
62          LiferayPortletRequest liferayPortletRequest,
63          LiferayPortletResponse liferayPortletResponse) {
64  
65          ThemeDisplay themeDisplay =
66              (ThemeDisplay)liferayPortletRequest.getAttribute(
67                  WebKeys.THEME_DISPLAY);
68  
69          PortletURL addAssetURL = null;
70  
71          if (MBPermission.contains(
72                  themeDisplay.getPermissionChecker(),
73                  themeDisplay.getScopeGroupId(), ActionKeys.ADD_MESSAGE)) {
74  
75              addAssetURL = liferayPortletResponse.createRenderURL(
76                  PortletKeys.MESSAGE_BOARDS);
77  
78              addAssetURL.setParameter(
79                  "struts_action", "/message_boards/view");
80              addAssetURL.setParameter(
81                  "groupId", String.valueOf(themeDisplay.getScopeGroupId()));
82          }
83  
84          return addAssetURL;
85      }
86  
87  }