1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
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  }