001    /**
002     * Copyright (c) 2000-2011 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.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    }