private String getTemplateContents( final String templateName, final TemplateDataDictionary dataDictionary) { try { final TemplateLoader templateLoader = TemplateResourceLoader.create(); final Template template = templateLoader.getTemplate(templateName); return template.renderToString(dataDictionary); } catch (final TemplateException e) { throw new IllegalStateException(e); } }
public ClassOrInterfaceTypeDetails getTemplateDetails( final TemplateDataDictionary dataDictionary, final String templateFile, final JavaType templateType, final String moduleName) { try { final TemplateLoader templateLoader = TemplateResourceLoader.create(); final Template template = templateLoader.getTemplate(templateFile); Validate.notNull(template, "Template required for '" + templateFile + "'"); final String templateContents = template.renderToString(dataDictionary); final String templateId = PhysicalTypeIdentifier.createIdentifier( templateType, LogicalPath.getInstance(Path.SRC_MAIN_JAVA, moduleName)); return typeParsingService.getTypeFromString(templateContents, templateId, templateType); } catch (final Exception e) { throw new IllegalStateException(e); } }
private String renderByTemplate( T_Transaction transaction, T_AppInfo appInfo, int userID, HttpServletRequest request) throws TemplateException { TemplateLoader templateLoader = TemplateResourceLoader.create("view/"); Template template = templateLoader.getTemplate("m_layout"); TemplateDataDictionary dic = TemplateDictionary.create(); dic.setVariable("PAYTITLE", Configuration.SYSTEM_REQUESTFORM_TITLE); dic.setVariable("PAYURL", Configuration.SYSTEM_URL); dic.setVariable("STATIC_URL", Configuration.STATIC_URL); dic.setVariable("APPICON", appInfo.getIconPath()); dic.setVariable("APPID", appInfo.getAppID()); dic.setVariable("APPNAME", appInfo.getAppName()); dic.setVariable("REFID", transaction.getRefID()); dic.setVariable("USERID", userID + ""); dic.setVariable("USERNAME", request.getAttribute("zme.viewerName").toString()); dic.setVariable("DATA", request.getParameter("data")); dic.setVariable("PTOKEN", request.getAttribute("pToken").toString()); String[] arrItemID = transaction.getItemIDs().split(ITEM_SEPARATE); String[] arrItemNames = transaction.getItemNames().split(ITEM_SEPARATE); String[] arrQty = transaction.getItemQuantities().split(ITEM_SEPARATE); String[] arrPrice = transaction.getItemPrices().split(ITEM_SEPARATE); String[] arrAmount = (transaction.getAmount() + "").split(ITEM_SEPARATE); double total = 0.0; for (int i = 0; i < arrItemID.length; i++) { double childamount = Double.parseDouble(arrAmount[i]); total += childamount; TemplateDataDictionary itemDic = dic.addSection("ITEM"); itemDic.setVariable("ITEMNAME", arrItemNames[i]); itemDic.setVariable("QUANTITY", arrQty[i]); itemDic.setVariable("PRICE", arrPrice[i]); itemDic.setVariable("AMOUNT", Utils.removeDouble(childamount)); } dic.setVariable("PAYTOTAL", Utils.removeDouble(total)); dic.showSection("m_top"); dic.showSection("m_header"); dic.addSection("BILLING_REQUEST_FORM"); dic.showSection("m_billing"); TemplateDataDictionary footer = dic.addSection("m_footer"); footer.setVariable("APPURL", Utils.removeHTTP(appInfo.appURL)); return template.renderToString(dic); }