freemarker.template.MalformedTemplateNameException Java Examples

The following examples show how to use freemarker.template.MalformedTemplateNameException. 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: FreemarkerUtils.java    From t-io with Apache License 2.0 6 votes vote down vote up
/**
 * @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 #3
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 #4
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 #5
Source File: AzureCredentialAppCreationCommandTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenerateWhenFreemarkerConfigGetTemplateThrowsMalformedTemplateNameExceptionThenCloudConnectorExceptionComesForAppCreationCommandTemplate()
        throws IOException, TemplateException {
    doThrow(new MalformedTemplateNameException(TEMPLATE_NAME, MALFORMED_TEMPLATE_NAMED_EXCEPTION_DESCRIPTION)).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 #6
Source File: AzureCredentialAppCreationCommandTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenerateWhenFreemarkerConfigGetTemplateThrowsMalformedTemplateNameExceptionThenCloudConnectorExceptionComesForAppCreationJsonTemplate()
        throws IOException, TemplateException {
    doThrow(new MalformedTemplateNameException(TEMPLATE_NAME, MALFORMED_TEMPLATE_NAMED_EXCEPTION_DESCRIPTION)).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 #7
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 #8
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 #9
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 #10
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 #11
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);
}