1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.journal.action;
16  
17  import com.liferay.portal.kernel.upload.UploadServletRequest;
18  import com.liferay.portal.kernel.util.ContentTypes;
19  import com.liferay.portal.kernel.util.ParamUtil;
20  import com.liferay.portal.util.PortalUtil;
21  import com.liferay.portlet.journal.util.JournalUtil;
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="GetArticleContentAction.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Brian Wing Shun Chan
36   */
37  public class GetArticleContentAction extends Action {
38  
39      public ActionForward execute(
40              ActionMapping mapping, ActionForm form, HttpServletRequest request,
41              HttpServletResponse response)
42          throws Exception {
43  
44          try {
45              UploadServletRequest uploadRequest =
46                  PortalUtil.getUploadServletRequest(request);
47  
48              String xml = ParamUtil.getString(uploadRequest, "xml");
49  
50              xml = JournalUtil.formatXML(xml);
51  
52              String fileName = "article.xml";
53              byte[] bytes = xml.getBytes();
54  
55              ServletResponseUtil.sendFile(
56                  request, response, fileName, bytes, ContentTypes.TEXT_XML_UTF8);
57  
58              return null;
59          }
60          catch (Exception e) {
61              PortalUtil.sendError(e, request, response);
62  
63              return null;
64          }
65      }
66  
67  }