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 classNameId = ParamUtil.getLong(request, "classNameId");
040                    long classPK = ParamUtil.getLong(request, "classPK");
041    
042                    DDMStructure structure = null;
043    
044                    long structureClassNameId = PortalUtil.getClassNameId(
045                            DDMStructure.class);
046    
047                    if ((structureClassNameId == classNameId) && (classPK > 0)) {
048                            structure = DDMStructureServiceUtil.getStructure(classPK);
049                    }
050    
051                    request.setAttribute(WebKeys.DYNAMIC_DATA_MAPPING_STRUCTURE, structure);
052            }
053    
054            public static void getStructure(PortletRequest portletRequest)
055                    throws Exception {
056    
057                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
058                            portletRequest);
059    
060                    getStructure(request);
061            }
062    
063            public static void getTemplate(HttpServletRequest request)
064                    throws Exception {
065    
066                    long templateId = ParamUtil.getLong(request, "templateId");
067    
068                    DDMTemplate template = null;
069    
070                    if (templateId > 0) {
071                            template = DDMTemplateLocalServiceUtil.getDDMTemplate(templateId);
072                    }
073    
074                    request.setAttribute(WebKeys.DYNAMIC_DATA_MAPPING_TEMPLATE, template);
075            }
076    
077            public static void getTemplate(PortletRequest portletRequest)
078                    throws Exception {
079    
080                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
081                            portletRequest);
082    
083                    getTemplate(request);
084            }
085    
086    }