001
014
015 package com.liferay.portlet.journal.action;
016
017 import com.liferay.portal.kernel.language.LanguageUtil;
018 import com.liferay.portal.kernel.util.ContentTypes;
019 import com.liferay.portal.kernel.util.ParamUtil;
020 import com.liferay.portal.kernel.workflow.WorkflowConstants;
021 import com.liferay.portal.util.PortalUtil;
022 import com.liferay.portlet.journal.model.JournalArticle;
023 import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
024 import com.liferay.util.servlet.ServletResponseUtil;
025
026 import javax.servlet.http.HttpServletRequest;
027 import javax.servlet.http.HttpServletResponse;
028
029 import org.apache.struts.action.Action;
030 import org.apache.struts.action.ActionForm;
031 import org.apache.struts.action.ActionForward;
032 import org.apache.struts.action.ActionMapping;
033
034
038 public class GetLatestArticleContentAction extends Action {
039
040 public ActionForward execute(
041 ActionMapping mapping, ActionForm form, HttpServletRequest request,
042 HttpServletResponse response)
043 throws Exception {
044
045 try {
046 long groupId = ParamUtil.getLong(request, "groupId");
047 String articleId = ParamUtil.getString(request, "articleId");
048
049 String languageId = LanguageUtil.getLanguageId(request);
050
051 JournalArticle article =
052 JournalArticleLocalServiceUtil.getLatestArticle(
053 groupId, articleId, WorkflowConstants.STATUS_APPROVED);
054
055 String fileName = "content.xml";
056 byte[] bytes = article.getContentByLocale(languageId).getBytes();
057
058 ServletResponseUtil.sendFile(
059 request, response, fileName, bytes, ContentTypes.TEXT_XML_UTF8);
060
061 return null;
062 }
063 catch (Exception e) {
064 PortalUtil.sendError(e, request, response);
065
066 return null;
067 }
068 }
069
070 }