1
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
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 }