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.portletconfiguration.action;
16  
17  import com.liferay.portal.kernel.util.ParamUtil;
18  import com.liferay.portal.model.Layout;
19  import com.liferay.portal.security.permission.ActionKeys;
20  import com.liferay.portal.security.permission.PermissionChecker;
21  import com.liferay.portal.service.permission.PortletPermissionUtil;
22  import com.liferay.portal.struts.JSONAction;
23  import com.liferay.portal.theme.ThemeDisplay;
24  import com.liferay.portal.util.WebKeys;
25  import com.liferay.portlet.PortletPreferencesFactoryUtil;
26  import com.liferay.portlet.PortletSetupUtil;
27  
28  import javax.portlet.PortletPreferences;
29  
30  import javax.servlet.http.HttpServletRequest;
31  import javax.servlet.http.HttpServletResponse;
32  
33  import org.apache.struts.action.ActionForm;
34  import org.apache.struts.action.ActionMapping;
35  
36  /**
37   * <a href="GetLookAndFeelAction.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   */
41  public class GetLookAndFeelAction extends JSONAction {
42  
43      public String getJSON(
44              ActionMapping mapping, ActionForm form, HttpServletRequest request,
45              HttpServletResponse response)
46          throws Exception {
47  
48          ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
49              WebKeys.THEME_DISPLAY);
50  
51          Layout layout = themeDisplay.getLayout();
52  
53          PermissionChecker permissionChecker =
54              themeDisplay.getPermissionChecker();
55  
56          String portletId = ParamUtil.getString(request, "portletId");
57  
58          if (!PortletPermissionUtil.contains(
59                  permissionChecker, themeDisplay.getPlid(), portletId,
60                  ActionKeys.CONFIGURATION)) {
61  
62              return null;
63          }
64  
65          PortletPreferences portletSetup =
66              PortletPreferencesFactoryUtil.getLayoutPortletSetup(
67                  layout, portletId);
68  
69          return PortletSetupUtil.cssToString(portletSetup);
70      }
71  
72  }