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.layoutprototypes.action;
016    
017    import com.liferay.portal.NoSuchLayoutPrototypeException;
018    import com.liferay.portal.kernel.util.ParamUtil;
019    import com.liferay.portal.model.LayoutPrototype;
020    import com.liferay.portal.service.LayoutPrototypeServiceUtil;
021    import com.liferay.portal.util.PortalUtil;
022    import com.liferay.portal.util.WebKeys;
023    
024    import javax.portlet.PortletRequest;
025    
026    import javax.servlet.http.HttpServletRequest;
027    
028    /**
029     * @author Jorge Ferrer
030     */
031    public class ActionUtil {
032    
033            public static void getLayoutPrototype(HttpServletRequest request)
034                    throws Exception {
035    
036                    long layoutPrototypeId = ParamUtil.getLong(
037                            request, "layoutPrototypeId");
038    
039                    LayoutPrototype layoutPrototype = null;
040    
041                    try {
042                            layoutPrototype = LayoutPrototypeServiceUtil.getLayoutPrototype(
043                                    layoutPrototypeId);
044                    }
045                    catch (NoSuchLayoutPrototypeException nslpe) {
046                    }
047    
048                    request.setAttribute(WebKeys.LAYOUT_PROTOTYPE, layoutPrototype);
049            }
050    
051            public static void getLayoutPrototype(PortletRequest portletRequest)
052                    throws Exception {
053    
054                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
055                            portletRequest);
056    
057                    getLayoutPrototype(request);
058            }
059    
060    }