001
014
015 package com.liferay.portlet.journal.action;
016
017 import com.liferay.portal.kernel.servlet.ServletResponseUtil;
018 import com.liferay.portal.kernel.util.ContentTypes;
019 import com.liferay.portal.kernel.util.ParamUtil;
020 import com.liferay.portal.util.PortalUtil;
021 import com.liferay.portlet.dynamicdatamapping.util.DDMXMLUtil;
022 import com.liferay.portlet.journal.model.JournalTemplateConstants;
023 import com.liferay.portlet.journal.util.JournalUtil;
024 import com.liferay.util.JS;
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
037 public class GetTemplateContentAction extends Action {
038
039 @Override
040 public ActionForward execute(
041 ActionMapping actionMapping, ActionForm actionForm,
042 HttpServletRequest request, HttpServletResponse response)
043 throws Exception {
044
045 try {
046 String xslContent = JS.decodeURIComponent(
047 ParamUtil.getString(request, "xslContent"));
048 boolean formatXsl = ParamUtil.getBoolean(request, "formatXsl");
049 String langType = ParamUtil.getString(
050 request, "langType", JournalTemplateConstants.LANG_TYPE_XSL);
051
052 if (formatXsl) {
053 if (langType.equals(JournalTemplateConstants.LANG_TYPE_VM)) {
054 xslContent = JournalUtil.formatVM(xslContent);
055 }
056 else {
057 xslContent = DDMXMLUtil.formatXML(xslContent);
058 }
059 }
060
061 String fileName = "template." + langType;
062 byte[] bytes = xslContent.getBytes();
063
064 ServletResponseUtil.sendFile(
065 request, response, fileName, bytes, ContentTypes.TEXT_XML_UTF8);
066
067 return null;
068 }
069 catch (Exception e) {
070 PortalUtil.sendError(e, request, response);
071
072 return null;
073 }
074 }
075
076 }