freemarker.core.ParseException Java Examples
The following examples show how to use
freemarker.core.ParseException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FreemarkerParseFactory.java From jeecg-cloud with Apache License 2.0 | 6 votes |
/** * 判断模板是否存在 * * @throws Exception */ public static boolean isExistTemplate(String tplName) throws Exception { try { Template mytpl = _tplConfig.getTemplate(tplName, "UTF-8"); if (mytpl == null) { return false; } } catch (Exception e) { //update-begin--Author:scott Date:20180320 for:解决问题 - 错误提示sql文件不存在,实际问题是sql freemarker用法错误----- if (e instanceof ParseException) { log.error(e.getMessage(), e.fillInStackTrace()); throw new Exception(e); } log.debug("----isExistTemplate----" + e.toString()); //update-end--Author:scott Date:20180320 for:解决问题 - 错误提示sql文件不存在,实际问题是sql freemarker用法错误------ return false; } return true; }
Example #2
Source File: FreemarkerParseFactory.java From teaching with Apache License 2.0 | 6 votes |
/** * 判断模板是否存在 * * @throws Exception */ public static boolean isExistTemplate(String tplName) throws Exception { try { Template mytpl = _tplConfig.getTemplate(tplName, "UTF-8"); if (mytpl == null) { return false; } } catch (Exception e) { //update-begin--Author:scott Date:20180320 for:解决问题 - 错误提示sql文件不存在,实际问题是sql freemarker用法错误----- if (e instanceof ParseException) { log.error(e.getMessage(), e.fillInStackTrace()); throw new Exception(e); } log.debug("----isExistTemplate----" + e.toString()); //update-end--Author:scott Date:20180320 for:解决问题 - 错误提示sql文件不存在,实际问题是sql freemarker用法错误------ return false; } return true; }
Example #3
Source File: FreemarkerParseFactory.java From jeecg-boot with Apache License 2.0 | 6 votes |
/** * 判断模板是否存在 * * @throws Exception */ public static boolean isExistTemplate(String tplName) throws Exception { try { Template mytpl = _tplConfig.getTemplate(tplName, "UTF-8"); if (mytpl == null) { return false; } } catch (Exception e) { //update-begin--Author:scott Date:20180320 for:解决问题 - 错误提示sql文件不存在,实际问题是sql freemarker用法错误----- if (e instanceof ParseException) { log.error(e.getMessage(), e.fillInStackTrace()); throw new Exception(e); } log.debug("----isExistTemplate----" + e.toString()); //update-end--Author:scott Date:20180320 for:解决问题 - 错误提示sql文件不存在,实际问题是sql freemarker用法错误------ return false; } return true; }
Example #4
Source File: HtmlReport.java From sailfish-core with Apache License 2.0 | 6 votes |
private void writeStatus(Writer writer, StatusDescription status, int indentSize) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException { logger.debug("writeStatus - context: {}, status: {}, description: {}", currentContext, status.getStatus(), status.getDescription()); if(status.getStatus() != PASSED) { createNode(writer, "Status", NodeType.STATUS, status.getStatus(), null, indentSize); TemplateWrapper statusTableTemplate = templateWrapperFactory.createWrapper("status_table.ftlh"); statusTableTemplate.setData("status", status.getStatus()); statusTableTemplate.setData("description", status.getDescription()); statusTableTemplate.setData("exception", status.getCause()); statusTableTemplate.setData("id", ++nodeId * 1000); statusTableTemplate.write(writer, indentSize + 2); closeNode(writer, indentSize); } }
Example #5
Source File: FreemarkerUtils.java From t-io with Apache License 2.0 | 6 votes |
/** * @param templateFilePath * @param destFilePath * @param configuration * @param model * @param override * @param append * @throws ParseException * @throws MalformedTemplateNameException * @throws IOException * @throws TemplateException */ public static void generateFileByFile(String templateFilePath, String destFilePath, Configuration configuration, Object model, boolean override, boolean append) throws MalformedTemplateNameException, ParseException, IOException, TemplateException { Template t = configuration.getTemplate(templateFilePath); File destFile = new File(destFilePath); if (override || append || !destFile.exists()) { File parent = destFile.getParentFile(); if (null != parent) { parent.mkdirs(); } try (FileOutputStream outputStream = new FileOutputStream(destFile, append); FileLock fileLock = outputStream.getChannel().tryLock();) { Writer out = new OutputStreamWriter(outputStream, DEFAULT_CHARSET); t.process(model, out); } log.info(destFilePath + " saved!"); } else { log.error(destFilePath + " already exists!"); } }
Example #6
Source File: ExceptionUtils.java From freemarker-online-tester with Apache License 2.0 | 6 votes |
/** * The error message (and sometimes also the class), and then the same with the cause exception, and so on. Doesn't * contain the stack trace or other location information. */ public static String getMessageWithCauses(final Throwable exc) { StringBuilder sb = new StringBuilder(); Throwable curExc = exc; while (curExc != null) { if (curExc != exc) { sb.append("\n\nCaused by:\n"); } String msg = curExc.getMessage(); if (msg == null || !(curExc instanceof TemplateException || curExc instanceof ParseException)) { sb.append(curExc.getClass().getName()).append(": "); } sb.append(msg); curExc = curExc.getCause(); } return sb.toString(); }
Example #7
Source File: HtmlReport.java From sailfish-core with Apache License 2.0 | 5 votes |
private void writeParametersTable(int id, String messageName, List<ActionParameter> parameters, boolean hasHeaders) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException { createNode(testCaseWriter, "Input Parameters", NodeType.INPUT, null, null, 7); TemplateWrapper testCaseActionParametersTemplate = templateWrapperFactory.createWrapper("test_case_parameters_table.ftlh"); testCaseActionParametersTemplate.setData("tableId", id); testCaseActionParametersTemplate.setData("message_name", messageName); testCaseActionParametersTemplate.setData("parameters", parameters); testCaseActionParametersTemplate.setData("hasHeaders", hasHeaders); testCaseActionParametersTemplate.write(testCaseWriter, 9); closeNode(testCaseWriter, 7); }
Example #8
Source File: FreeMarkerServiceTest.java From freemarker-online-tester with Apache License 2.0 | 5 votes |
@Test public void testTemplateWithSyntaxError() { FreeMarkerServiceResponse serviceResponse = getService().executeTemplate(new ExecuteTemplateArgs() .templateSourceCode("test ${xx").dataModel(Collections.emptyMap())); assertThat(serviceResponse.isSuccesful(), is(false)); assertThat(serviceResponse.getFailureReason(), instanceOf(ParseException.class)); }
Example #9
Source File: ObjectRenderer.java From Repeat with Apache License 2.0 | 5 votes |
private String internalRender(String templateFile, Map<String, Object> data) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException { if (!templateFile.endsWith(TEMPLATE_EXTENSION)) { templateFile += TEMPLATE_EXTENSION; } Template template = config.getTemplate(templateFile); Writer output = new StringWriter(); template.process(data, output); return output.toString(); }
Example #10
Source File: FreemarkerTemplate.java From extentreports-java with Apache License 2.0 | 4 votes |
public Template createTemplate(String templatePath) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException { return freemarkerConfig.getTemplate(templatePath); }
Example #11
Source File: TemplateWrapperFactory.java From sailfish-core with Apache License 2.0 | 4 votes |
public TemplateWrapper createWrapper(String templateName) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException { return new TemplateWrapper(configuration.getTemplate(templateName)); }
Example #12
Source File: HtmlReport.java From sailfish-core with Apache License 2.0 | 4 votes |
private void writeElements(Writer writer, List<Object> elements, int indentSize) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException { List<Verification> verifications = new ArrayList<>(); for(Object element : elements) { if(element instanceof Message) { if(!verifications.isEmpty()) { writeVerifications(writer, verifications, indentSize); verifications.clear(); } writeMessage(writer, (Message)element, indentSize); } else if(element instanceof Verification) { verifications.add((Verification)element); } else if(element instanceof ReportTable) { if(!verifications.isEmpty()) { writeVerifications(writer, verifications, indentSize); verifications.clear(); } writeTable(writer, null, (ReportTable)element, indentSize); } else if(element instanceof Action) { writeAction((Action)element); } else if (element instanceof ActionGroup) { ActionGroup group = (ActionGroup) element; createNode(testCaseWriter, group.getName(), group.getDescription(), NodeType.ACTION, group.getStatus(), null, 5, null, null, Collections.emptyList(), null, true); writeElements(writer, group.getElements(), indentSize); String linkToReport = group.getLinkToReport(); if(StringUtils.isNotBlank(linkToReport)) { createNode(testCaseWriter, "Report", NodeType.DESCRIPTION, null, null, 7); writeLine(testCaseWriter, "<a href='" + linkToReport + "'>Link to report</a>", 9); closeNode(testCaseWriter, 7); } closeNode(testCaseWriter, 7); } else if(element instanceof Throwable) { writeException(testCaseWriter, (Throwable)element); } else if(element instanceof ParametersTable) { ParametersTable table = (ParametersTable)element; writeParametersTable(table.getId(), table.getMessageName(), table.getParameters(), table.isHasHeaders()); } } if(!verifications.isEmpty()) { writeVerifications(writer, verifications, indentSize); verifications.clear(); } }
Example #13
Source File: AbstractHandler.java From gd-generator with MIT License | 4 votes |
protected String renderTemplate(String tmplName, Map<String, Object> model) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException { StringWriter out = new StringWriter(); Template template = freemarkerConfiguration.getTemplate(tmplName + ".ftl"); template.process(model, out); return out.toString(); }
Example #14
Source File: MailSender.java From voj with GNU General Public License v3.0 | 3 votes |
/** * 解析电子邮件模板内容. * @param templateLocation - 电子邮件模板相对路径 * @param model - 电子邮件的附加信息 * @return 解析后的电子邮件内容 * @throws TemplateException * @throws IOException * @throws ParseException * @throws MalformedTemplateNameException * @throws TemplateNotFoundException */ public String getMailContent(String templateLocation, Map<String, Object> model) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException { model.put("baseUrl", baseUrl); return FreeMarkerTemplateUtils.processTemplateIntoString( freeMarkerConfigurer.getConfiguration().getTemplate(templateLocation), model); }
Example #15
Source File: FreemarkerUtils.java From t-io with Apache License 2.0 | 2 votes |
/** * @param writer * @param template * @param configuration * @param model * @throws TemplateNotFoundException * @throws MalformedTemplateNameException * @throws ParseException * @throws IOException * @throws TemplateException */ public static void generateStringByPath(Writer writer, String template, Configuration configuration, Object model) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException { Template tpl = configuration.getTemplate(template, null, null, null, true, true); tpl.process(model, writer); }