001
014
015 package com.liferay.portlet.journal.action;
016
017 import com.liferay.portal.kernel.language.LanguageUtil;
018 import com.liferay.portal.kernel.servlet.ServletResponseUtil;
019 import com.liferay.portal.kernel.util.ContentTypes;
020 import com.liferay.portal.kernel.util.ParamUtil;
021 import com.liferay.portal.kernel.workflow.WorkflowConstants;
022 import com.liferay.portal.util.PortalUtil;
023 import com.liferay.portlet.journal.model.JournalArticle;
024 import com.liferay.portlet.journal.service.JournalArticleServiceUtil;
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 @Override
041 public ActionForward execute(
042 ActionMapping actionMapping, ActionForm actionForm,
043 HttpServletRequest request, HttpServletResponse response)
044 throws Exception {
045
046 try {
047 long groupId = ParamUtil.getLong(request, "groupId");
048 String articleId = ParamUtil.getString(request, "articleId");
049
050 String languageId = LanguageUtil.getLanguageId(request);
051
052 JournalArticle article = JournalArticleServiceUtil.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 }