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