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.dynamicdatamapping.action;
016    
017    import com.liferay.portal.kernel.util.ParamUtil;
018    import com.liferay.portal.util.PortalUtil;
019    import com.liferay.portal.util.WebKeys;
020    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
021    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplate;
022    import com.liferay.portlet.dynamicdatamapping.service.DDMStructureServiceUtil;
023    import com.liferay.portlet.dynamicdatamapping.service.DDMTemplateLocalServiceUtil;
024    
025    import javax.portlet.PortletRequest;
026    
027    import javax.servlet.http.HttpServletRequest;
028    
029    /**
030     * @author Brian Wing Shun Chan
031     * @author Bruno Basto
032     * @author Eduardo Lundgren
033     */
034    public class ActionUtil {
035    
036            public static void getStructure(HttpServletRequest request)
037                    throws Exception {
038    
039                    long structureId = ParamUtil.getLong(request, "structureId");
040    
041                    DDMStructure structure = null;
042    
043                    if (structureId > 0) {
044                            structure = DDMStructureServiceUtil.getStructure(structureId);
045                    }
046    
047                    request.setAttribute(WebKeys.DYNAMIC_DATA_MAPPING_STRUCTURE, structure);
048            }
049    
050            public static void getStructure(PortletRequest portletRequest)
051                    throws Exception {
052    
053                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
054                            portletRequest);
055    
056                    getStructure(request);
057            }
058    
059            public static void getTemplate(HttpServletRequest request)
060                    throws Exception {
061    
062                    long templateId = ParamUtil.getLong(request, "templateId");
063    
064                    DDMTemplate template = null;
065    
066                    if (templateId > 0) {
067                            template = DDMTemplateLocalServiceUtil.getDDMTemplate(templateId);
068                    }
069    
070                    request.setAttribute(WebKeys.DYNAMIC_DATA_MAPPING_TEMPLATE, template);
071            }
072    
073            public static void getTemplate(PortletRequest portletRequest)
074                    throws Exception {
075    
076                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
077                            portletRequest);
078    
079                    getTemplate(request);
080            }
081    
082    }