001    /**
002     * Copyright (c) 2000-2010 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            public String getJSON(
042                            ActionMapping mapping, ActionForm form, HttpServletRequest request,
043                            HttpServletResponse response)
044                    throws Exception {
045    
046                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
047                            WebKeys.THEME_DISPLAY);
048    
049                    Layout layout = themeDisplay.getLayout();
050    
051                    PermissionChecker permissionChecker =
052                            themeDisplay.getPermissionChecker();
053    
054                    String portletId = ParamUtil.getString(request, "portletId");
055    
056                    if (!PortletPermissionUtil.contains(
057                                    permissionChecker, themeDisplay.getPlid(), portletId,
058                                    ActionKeys.CONFIGURATION)) {
059    
060                            return null;
061                    }
062    
063                    PortletPreferences portletSetup =
064                            PortletPreferencesFactoryUtil.getLayoutPortletSetup(
065                                    layout, portletId);
066    
067                    return PortletSetupUtil.cssToString(portletSetup);
068            }
069    
070    }