001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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    /**
035     * @author Raymond Aug??
036     * @author Brian Wing Shun Chan
037     */
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    }