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.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    }