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