001
014
015 package com.liferay.portlet.journal.action;
016
017 import com.liferay.portal.kernel.util.ContentTypes;
018 import com.liferay.portal.kernel.util.ParamUtil;
019 import com.liferay.portal.util.PortalUtil;
020 import com.liferay.portlet.journal.model.JournalTemplateConstants;
021 import com.liferay.portlet.journal.util.JournalUtil;
022 import com.liferay.util.JS;
023 import com.liferay.util.servlet.ServletResponseUtil;
024
025 import javax.servlet.http.HttpServletRequest;
026 import javax.servlet.http.HttpServletResponse;
027
028 import org.apache.struts.action.Action;
029 import org.apache.struts.action.ActionForm;
030 import org.apache.struts.action.ActionForward;
031 import org.apache.struts.action.ActionMapping;
032
033
036 public class GetTemplateContentAction extends Action {
037
038 public ActionForward execute(
039 ActionMapping mapping, ActionForm form, HttpServletRequest request,
040 HttpServletResponse response)
041 throws Exception {
042
043 try {
044 String xslContent = JS.decodeURIComponent(
045 ParamUtil.getString(request, "xslContent"));
046 boolean formatXsl = ParamUtil.getBoolean(request, "formatXsl");
047 String langType = ParamUtil.getString(
048 request, "langType", JournalTemplateConstants.LANG_TYPE_XSL);
049
050 if (formatXsl) {
051 if (langType.equals(JournalTemplateConstants.LANG_TYPE_VM)) {
052 xslContent = JournalUtil.formatVM(xslContent);
053 }
054 else {
055 xslContent = JournalUtil.formatXML(xslContent);
056 }
057 }
058
059 String fileName = "template." + langType;
060 byte[] bytes = xslContent.getBytes();
061
062 ServletResponseUtil.sendFile(
063 request, response, fileName, bytes, ContentTypes.TEXT_XML_UTF8);
064
065 return null;
066 }
067 catch (Exception e) {
068 PortalUtil.sendError(e, request, response);
069
070 return null;
071 }
072 }
073
074 }