1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.journal.action;
16  
17  import com.liferay.portal.kernel.util.ContentTypes;
18  import com.liferay.portal.kernel.util.ParamUtil;
19  import com.liferay.portal.util.PortalUtil;
20  import com.liferay.portlet.journal.model.JournalStructure;
21  import com.liferay.portlet.journal.service.JournalStructureLocalServiceUtil;
22  import com.liferay.util.servlet.ServletResponseUtil;
23  
24  import javax.servlet.http.HttpServletRequest;
25  import javax.servlet.http.HttpServletResponse;
26  
27  import org.apache.struts.action.Action;
28  import org.apache.struts.action.ActionForm;
29  import org.apache.struts.action.ActionForward;
30  import org.apache.struts.action.ActionMapping;
31  
32  /**
33   * <a href="GetStructureAction.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Brian Wing Shun Chan
36   * @author Raymond Augé
37   */
38  public class GetStructureAction extends Action {
39  
40      public ActionForward execute(
41              ActionMapping mapping, ActionForm form, HttpServletRequest request,
42              HttpServletResponse response)
43          throws Exception {
44  
45          try {
46              long groupId = ParamUtil.getLong(request, "groupId");
47              String structureId = ParamUtil.getString(request, "structureId");
48  
49              JournalStructure structure =
50                  JournalStructureLocalServiceUtil.getStructure(
51                      groupId, structureId);
52  
53              String fileName = null;
54              byte[] bytes = structure.getXsd().getBytes();
55  
56              ServletResponseUtil.sendFile(
57                  response, fileName, bytes, ContentTypes.TEXT_XML_UTF8);
58  
59              return null;
60          }
61          catch (Exception e) {
62              PortalUtil.sendError(e, request, response);
63  
64              return null;
65          }
66      }
67  
68  }