001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.layoutsetprototypes.action;
016    
017    import com.liferay.portal.NoSuchLayoutSetPrototypeException;
018    import com.liferay.portal.kernel.util.ParamUtil;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.portal.model.Group;
021    import com.liferay.portal.model.LayoutSetPrototype;
022    import com.liferay.portal.service.LayoutSetPrototypeLocalServiceUtil;
023    import com.liferay.portal.service.LayoutSetPrototypeServiceUtil;
024    import com.liferay.portal.theme.ThemeDisplay;
025    import com.liferay.portal.util.PortalUtil;
026    import com.liferay.portal.util.WebKeys;
027    
028    import javax.portlet.PortletRequest;
029    
030    import javax.servlet.http.HttpServletRequest;
031    
032    /**
033     * @author Brian Wing Shun Chan
034     * @author Eduardo Garcia
035     */
036    public class ActionUtil {
037    
038            public static void getLayoutSetPrototype(HttpServletRequest request)
039                    throws Exception {
040    
041                    LayoutSetPrototype layoutSetPrototype = null;
042    
043                    try {
044                            long layoutSetPrototypeId = ParamUtil.getLong(
045                                    request, "layoutSetPrototypeId");
046    
047                            if (Validator.isNotNull(layoutSetPrototypeId)) {
048                                    layoutSetPrototype =
049                                            LayoutSetPrototypeServiceUtil.getLayoutSetPrototype(
050                                                    layoutSetPrototypeId);
051                            }
052                            else {
053                                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
054                                            WebKeys.THEME_DISPLAY);
055    
056                                    Group group = themeDisplay.getScopeGroup();
057    
058                                    if (group.isLayoutSetPrototype()) {
059                                            layoutSetPrototype =
060                                                    LayoutSetPrototypeLocalServiceUtil.
061                                                            getLayoutSetPrototype(group.getClassPK());
062                                    }
063                            }
064                    }
065                    catch (NoSuchLayoutSetPrototypeException nslspe) {
066                    }
067    
068                    request.setAttribute(WebKeys.LAYOUT_PROTOTYPE, layoutSetPrototype);
069            }
070    
071            public static void getLayoutSetPrototype(PortletRequest portletRequest)
072                    throws Exception {
073    
074                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
075                            portletRequest);
076    
077                    getLayoutSetPrototype(request);
078            }
079    
080    }