1
14
15 package com.liferay.portlet.journal.action;
16
17 import com.liferay.portal.kernel.util.ContentTypes;
18 import com.liferay.portal.kernel.util.ParamUtil;
19 import com.liferay.portal.util.PortalUtil;
20 import com.liferay.portlet.journal.model.JournalTemplateConstants;
21 import com.liferay.portlet.journal.util.JournalUtil;
22 import com.liferay.util.JS;
23 import com.liferay.util.servlet.ServletResponseUtil;
24
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
27
28 import org.apache.struts.action.Action;
29 import org.apache.struts.action.ActionForm;
30 import org.apache.struts.action.ActionForward;
31 import org.apache.struts.action.ActionMapping;
32
33
38 public class GetTemplateContentAction extends Action {
39
40 public ActionForward execute(
41 ActionMapping mapping, ActionForm form, HttpServletRequest request,
42 HttpServletResponse response)
43 throws Exception {
44
45 try {
46 String xslContent = JS.decodeURIComponent(
47 ParamUtil.getString(request, "xslContent"));
48 boolean formatXsl = ParamUtil.getBoolean(request, "formatXsl");
49 String langType = ParamUtil.getString(
50 request, "langType", JournalTemplateConstants.LANG_TYPE_XSL);
51
52 if (formatXsl) {
53 if (langType.equals(JournalTemplateConstants.LANG_TYPE_VM)) {
54 xslContent = JournalUtil.formatVM(xslContent);
55 }
56 else {
57 xslContent = JournalUtil.formatXML(xslContent);
58 }
59 }
60
61 String fileName = "template." + langType;
62 byte[] bytes = xslContent.getBytes();
63
64 ServletResponseUtil.sendFile(
65 response, fileName, bytes, ContentTypes.TEXT_XML_UTF8);
66
67 return null;
68 }
69 catch (Exception e) {
70 PortalUtil.sendError(e, request, response);
71
72 return null;
73 }
74 }
75
76 }