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.servlet.ServletResponseUtil;
018    import com.liferay.portal.kernel.util.ContentTypes;
019    import com.liferay.portal.kernel.util.ParamUtil;
020    import com.liferay.portal.util.PortalUtil;
021    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
022    import com.liferay.portlet.dynamicdatamapping.service.DDMStructureServiceUtil;
023    
024    import javax.servlet.http.HttpServletRequest;
025    import javax.servlet.http.HttpServletResponse;
026    
027    import org.apache.struts.action.Action;
028    import org.apache.struts.action.ActionForm;
029    import org.apache.struts.action.ActionForward;
030    import org.apache.struts.action.ActionMapping;
031    
032    /**
033     * @author Juan Fern??ndez
034     */
035    public class GetStructureAction extends Action {
036    
037            @Override
038            public ActionForward execute(
039                            ActionMapping actionMapping, ActionForm actionForm,
040                            HttpServletRequest request, HttpServletResponse response)
041                    throws Exception {
042    
043                    try {
044                            long structureId = ParamUtil.getLong(request, "structureId");
045    
046                            DDMStructure structure = DDMStructureServiceUtil.getStructure(
047                                    structureId);
048    
049                            String xsd = structure.getXsd();
050    
051                            ServletResponseUtil.sendFile(
052                                    request, response, null, xsd.getBytes(),
053                                    ContentTypes.TEXT_XML_UTF8);
054    
055                            return null;
056                    }
057                    catch (Exception e) {
058                            PortalUtil.sendError(e, request, response);
059    
060                            return null;
061                    }
062            }
063    
064    }