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.language.LanguageUtil;
18  import com.liferay.portal.kernel.util.ContentTypes;
19  import com.liferay.portal.kernel.util.ParamUtil;
20  import com.liferay.portal.kernel.workflow.StatusConstants;
21  import com.liferay.portal.util.PortalUtil;
22  import com.liferay.portlet.journal.model.JournalArticle;
23  import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
24  import com.liferay.util.servlet.ServletResponseUtil;
25  
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.http.HttpServletResponse;
28  
29  import org.apache.struts.action.Action;
30  import org.apache.struts.action.ActionForm;
31  import org.apache.struts.action.ActionForward;
32  import org.apache.struts.action.ActionMapping;
33  
34  /**
35   * <a href="GetLatestArticleContentAction.java.html"><b><i>View Source</i></b>
36   * </a>
37   *
38   * @author Raymond Augé
39   * @author Brian Wing Shun Chan
40   */
41  public class GetLatestArticleContentAction extends Action {
42  
43      public ActionForward execute(
44              ActionMapping mapping, ActionForm form, HttpServletRequest request,
45              HttpServletResponse response)
46          throws Exception {
47  
48          try {
49              long groupId = ParamUtil.getLong(request, "groupId");
50              String articleId = ParamUtil.getString(request, "articleId");
51  
52              String languageId = LanguageUtil.getLanguageId(request);
53  
54              JournalArticle article =
55                  JournalArticleLocalServiceUtil.getLatestArticle(
56                      groupId, articleId, StatusConstants.APPROVED);
57  
58              String fileName = "content.xml";
59              byte[] bytes = article.getContentByLocale(languageId).getBytes();
60  
61              ServletResponseUtil.sendFile(
62                  response, fileName, bytes, ContentTypes.TEXT_XML_UTF8);
63  
64              return null;
65          }
66          catch (Exception e) {
67              PortalUtil.sendError(e, request, response);
68  
69              return null;
70          }
71      }
72  
73  }