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.journal.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.journal.model.JournalStructure;
022    import com.liferay.portlet.journal.service.JournalStructureServiceUtil;
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 Brian Wing Shun Chan
034     * @author Raymond Aug??
035     */
036    public class GetStructureAction extends Action {
037    
038            @Override
039            public ActionForward execute(
040                            ActionMapping actionMapping, ActionForm actionForm,
041                            HttpServletRequest request, HttpServletResponse response)
042                    throws Exception {
043    
044                    try {
045                            long groupId = ParamUtil.getLong(request, "groupId");
046                            String structureId = ParamUtil.getString(request, "structureId");
047    
048                            JournalStructure structure =
049                                    JournalStructureServiceUtil.getStructure(
050                                            groupId, structureId, true);
051    
052                            String fileName = null;
053                            byte[] bytes = structure.getXsd().getBytes();
054    
055                            ServletResponseUtil.sendFile(
056                                    request, response, fileName, bytes, ContentTypes.TEXT_XML_UTF8);
057    
058                            return null;
059                    }
060                    catch (Exception e) {
061                            PortalUtil.sendError(e, request, response);
062    
063                            return null;
064                    }
065            }
066    
067    }