StringWriter bodyWriter = new StringWriter();
MapStack<String> screenContext = MapStack.create();
screenContext.put("locale", locale);
ScreenRenderer screens = new ScreenRenderer(bodyWriter, screenContext, htmlScreenRenderer);
screens.populateContextForService(dctx, bodyParameters);
screenContext.putAll(bodyParameters);
if (bodyScreenUri != null) {
try {
screens.render(bodyScreenUri);
} catch (GeneralException e) {
Debug.logError(e, "Error rendering screen for email: " + e.toString(), module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonEmailSendRenderingScreenEmailError", UtilMisc.toMap("errorString", e.toString()), locale));
} catch (IOException e) {
Debug.logError(e, "Error rendering screen for email: " + e.toString(), module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonEmailSendRenderingScreenEmailError", UtilMisc.toMap("errorString", e.toString()), locale));
} catch (SAXException e) {
Debug.logError(e, "Error rendering screen for email: " + e.toString(), module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonEmailSendRenderingScreenEmailError", UtilMisc.toMap("errorString", e.toString()), locale));
} catch (ParserConfigurationException e) {
Debug.logError(e, "Error rendering screen for email: " + e.toString(), module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonEmailSendRenderingScreenEmailError", UtilMisc.toMap("errorString", e.toString()), locale));
}
}
boolean isMultiPart = false;
// check if attachment screen location passed in
if (UtilValidate.isNotEmpty(xslfoAttachScreenLocationList)) {
List<Map<String, ? extends Object>> bodyParts = FastList.newInstance();
if (bodyText != null) {
bodyText = FlexibleStringExpander.expandString(bodyText, screenContext, locale);
bodyParts.add(UtilMisc.<String, Object>toMap("content", bodyText, "type", "text/html"));
} else {
bodyParts.add(UtilMisc.<String, Object>toMap("content", bodyWriter.toString(), "type", "text/html"));
}
for (int i = 0; i < xslfoAttachScreenLocationList.size(); i++) {
String xslfoAttachScreenLocation = xslfoAttachScreenLocationList.get(i);
String attachmentName = "Details.pdf";
if (UtilValidate.isNotEmpty(attachmentNameList) && attachmentNameList.size() >= i) {
attachmentName = attachmentNameList.get(i);
}
isMultiPart = true;
// start processing fo pdf attachment
try {
Writer writer = new StringWriter();
MapStack<String> screenContextAtt = MapStack.create();
// substitute the freemarker variables...
ScreenRenderer screensAtt = new ScreenRenderer(writer, screenContext, foScreenRenderer);
screensAtt.populateContextForService(dctx, bodyParameters);
screenContextAtt.putAll(bodyParameters);
screensAtt.render(xslfoAttachScreenLocation);
/*
try { // save generated fo file for debugging
String buf = writer.toString();
java.io.FileWriter fw = new java.io.FileWriter(new java.io.File("/tmp/file1.xml"));