001
014
015 package com.liferay.portlet.dynamicdatamapping.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.GetterUtil;
020 import com.liferay.portal.kernel.util.ParamUtil;
021 import com.liferay.portal.util.PortalUtil;
022 import com.liferay.portlet.dynamicdatamapping.model.DDMTemplate;
023 import com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants;
024 import com.liferay.portlet.dynamicdatamapping.service.DDMTemplateServiceUtil;
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 GetTemplateAction extends Action {
038
039 @Override
040 public ActionForward execute(
041 ActionMapping mapping, ActionForm form, HttpServletRequest request,
042 HttpServletResponse response)
043 throws Exception {
044
045 try {
046 long templateId = ParamUtil.getLong(request, "templateId");
047
048 DDMTemplate template = DDMTemplateServiceUtil.getTemplate(
049 templateId);
050
051 String extension = GetterUtil.getString(
052 template.getLanguage(), DDMTemplateConstants.LANG_TYPE_VM);
053
054 String script = template.getScript();
055
056 String contentType = null;
057
058 if (extension.equals(DDMTemplateConstants.LANG_TYPE_XSD)) {
059 contentType = ContentTypes.TEXT_XML_UTF8;
060 }
061 else {
062 contentType = ContentTypes.TEXT_PLAIN_UTF8;
063 }
064
065 ServletResponseUtil.sendFile(
066 request, response, null, script.getBytes(), contentType);
067
068 return null;
069 }
070 catch (Exception e) {
071 PortalUtil.sendError(e, request, response);
072
073 return null;
074 }
075 }
076
077 }