001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
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    /**
035     * @author Raymond Augé
036     * @author Brian Wing Shun Chan
037     */
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    }