001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.portletconfiguration.action;
016    
017    import com.liferay.portal.kernel.util.ParamUtil;
018    import com.liferay.portal.model.Layout;
019    import com.liferay.portal.security.permission.ActionKeys;
020    import com.liferay.portal.security.permission.PermissionChecker;
021    import com.liferay.portal.service.permission.PortletPermissionUtil;
022    import com.liferay.portal.struts.JSONAction;
023    import com.liferay.portal.theme.ThemeDisplay;
024    import com.liferay.portal.util.WebKeys;
025    import com.liferay.portlet.PortletPreferencesFactoryUtil;
026    import com.liferay.portlet.PortletSetupUtil;
027    
028    import javax.portlet.PortletPreferences;
029    
030    import javax.servlet.http.HttpServletRequest;
031    import javax.servlet.http.HttpServletResponse;
032    
033    import org.apache.struts.action.ActionForm;
034    import org.apache.struts.action.ActionMapping;
035    
036    /**
037     * @author Brian Wing Shun Chan
038     */
039    public class GetLookAndFeelAction extends JSONAction {
040    
041            @Override
042            public String getJSON(
043                            ActionMapping actionMapping, ActionForm actionForm,
044                            HttpServletRequest request, HttpServletResponse response)
045                    throws Exception {
046    
047                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
048                            WebKeys.THEME_DISPLAY);
049    
050                    Layout layout = themeDisplay.getLayout();
051    
052                    PermissionChecker permissionChecker =
053                            themeDisplay.getPermissionChecker();
054    
055                    String portletId = ParamUtil.getString(request, "portletId");
056    
057                    if (!PortletPermissionUtil.contains(
058                                    permissionChecker, layout, portletId,
059                                    ActionKeys.CONFIGURATION)) {
060    
061                            return null;
062                    }
063    
064                    PortletPreferences portletSetup =
065                            PortletPreferencesFactoryUtil.getStrictLayoutPortletSetup(
066                                    layout, portletId);
067    
068                    return PortletSetupUtil.cssToJSONString(portletSetup);
069            }
070    
071    }