freemarker.template.TemplateNotFoundException Java Examples

The following examples show how to use freemarker.template.TemplateNotFoundException. 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: HtmlReport.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
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 #2
Source File: HtmlReport.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
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 #3
Source File: ObjectRenderer.java    From Repeat with Apache License 2.0 5 votes vote down vote up
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 #4
Source File: AzureCredentialAppCreationCommandTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenerateWhenFreemarkerConfigGetTemplateThrowsTemplateNotFoundExceptionThenCloudConnectorExceptionComesForAppCreationCommandTemplate()
        throws IOException, TemplateException {
    doThrow(new TemplateNotFoundException(TEMPLATE_NAME, new Object(), TEMPLATE_NOT_FOUND_EXCEPTION_MESSAGE)).when(freemarkerConfiguration)
            .getTemplate(APP_CREATION_COMMAND_TEMPLATE_PATH, ENCODING);

    thrown.expect(CloudConnectorException.class);
    thrown.expectMessage(format(GENERATE_EXCEPTION_MESSAGE_FORMAT, APP_CREATION_COMMAND_TEMPLATE_PATH));

    underTest.generate(DEPLOYMENT_ADDRESS);

    verify(template, times(0)).process(any(), any(StringWriter.class));
    verify(freemarkerConfiguration, times(1)).getTemplate(anyString(), anyString());
    verify(freemarkerConfiguration, times(1)).getTemplate(APP_CREATION_COMMAND_TEMPLATE_PATH, ENCODING);
}
 
Example #5
Source File: AzureCredentialAppCreationCommandTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenerateWhenFreemarkerConfigGetTemplateThrowsTemplateNotFoundExceptionThenCloudConnectorExceptionComesForAppCreationJsonTemplate()
        throws IOException, TemplateException {
    doThrow(new TemplateNotFoundException(TEMPLATE_NAME, new Object(), TEMPLATE_NOT_FOUND_EXCEPTION_MESSAGE)).when(freemarkerConfiguration)
            .getTemplate(APP_CREATION_JSON_TEMPLATE_PATH, ENCODING);

    thrown.expect(CloudConnectorException.class);
    thrown.expectMessage(format(GENERATE_EXCEPTION_MESSAGE_FORMAT, APP_CREATION_JSON_TEMPLATE_PATH));

    underTest.generateJSON(DEPLOYMENT_ADDRESS);

    verify(template, times(0)).process(any(), any(StringWriter.class));
    verify(freemarkerConfiguration, times(1)).getTemplate(anyString(), anyString());
    verify(freemarkerConfiguration, times(1)).getTemplate(APP_CREATION_JSON_TEMPLATE_PATH, ENCODING);
}
 
Example #6
Source File: FreemarkerTemplate.java    From extentreports-java with Apache License 2.0 4 votes vote down vote up
public Template createTemplate(String templatePath)
        throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException {
    return freemarkerConfig.getTemplate(templatePath);
}
 
Example #7
Source File: TemplateWrapperFactory.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
public TemplateWrapper createWrapper(String templateName) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException {
    return new TemplateWrapper(configuration.getTemplate(templateName));
}
 
Example #8
Source File: HtmlReport.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
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 #9
Source File: MailSender.java    From voj with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 解析电子邮件模板内容.
 * @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 #10
Source File: FreemarkerUtils.java    From t-io with Apache License 2.0 2 votes vote down vote up
/**
 * @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);
}