use of org.thymeleaf.context.ProcessingContext in project thymeleaf-tests by thymeleaf.
the class HtmlBulkTester method main.
public static void main(final String[] args) throws Exception {
if (args.length != 1) {
System.err.println("Syntax: java " + HtmlBulkTester.class.getName() + " [test_folder]");
System.exit(1);
}
final String testFolderName = args[0];
final File testFolder = new File(testFolderName);
if (!testFolder.exists() || !testFolder.isDirectory()) {
System.err.println("Folder " + testFolderName + " does not exist or is not a folder");
System.exit(1);
}
System.out.println("Using temporary folder for output: " + System.getProperty("java.io.tmpdir"));
final File[] filesInTestFolder = testFolder.listFiles();
for (final File fileInTestFolder : filesInTestFolder) {
if (!fileInTestFolder.getName().endsWith(".html")) {
continue;
}
final String fileInTestFolderName = fileInTestFolder.getName();
final FileInputStream fileInTestFolderStream = new FileInputStream(fileInTestFolder);
final InputStreamReader fileInTestFolderReader = new InputStreamReader(fileInTestFolderStream, "UTF-8");
final File testOutput = File.createTempFile("thymeleaf-testing-" + fileInTestFolderName + "-", ".html");
testOutput.deleteOnExit();
final FileOutputStream testOutputStream = new FileOutputStream(testOutput);
final OutputStreamWriter testOutputWriter = new OutputStreamWriter(testOutputStream, "UTF-8");
final ITemplateHandler handler = new OutputTemplateHandler(testOutputWriter);
handler.setProcessingContext(new ProcessingContext(TEMPLATE_ENGINE_CONFIGURATION, fileInTestFolderName, TemplateMode.HTML, Locale.US, null));
System.out.print(fileInTestFolderName);
System.out.print("[PARSING]");
PARSER.parse(TEMPLATE_ENGINE_CONFIGURATION, TemplateMode.HTML, new ReaderResource(fileInTestFolderName, fileInTestFolderReader), handler);
// Input stream will be closed by parser
testOutputWriter.close();
testOutputStream.close();
System.out.print("[PARSED]");
final FileInputStream testOutputCheckStream = new FileInputStream(testOutput);
final List<String> outputLines = IOUtils.readLines(testOutputCheckStream, "UTF-8");
final FileInputStream testInputCheckStream = new FileInputStream(fileInTestFolder);
final List<String> inputLines = IOUtils.readLines(testInputCheckStream, "UTF-8");
System.out.print("[CHECKING]");
if (outputLines.equals(inputLines)) {
System.out.print("[OK]");
} else {
System.out.print("[KO]");
}
System.out.println();
}
}
use of org.thymeleaf.context.ProcessingContext in project thymeleaf-tests by thymeleaf.
the class ExpressionBenchmark method main.
public static void main(String[] args) throws Exception {
final Map<String, String> expressionsMap = ExpressionBenchmarkDefinitions.createExpressionsMap();
final Configuration configuration = new Configuration();
final IProcessingContext processingContext = new ProcessingContext(new Context());
final IStandardExpressionParser parser = new StandardExpressionParser();
for (final Map.Entry<String, String> expressionEntry : expressionsMap.entrySet()) {
final String expression = expressionEntry.getKey();
final String expectedParsingResult = expressionEntry.getValue();
final IStandardExpression parsedExpression = parser.parseExpression(configuration, processingContext, expression);
Assert.assertNotNull(parsedExpression);
final String exp = parsedExpression.getStringRepresentation();
Assert.assertEquals(expectedParsingResult, exp);
}
final StopWatch sw = new StopWatch();
sw.start();
for (int x = 0; x < 1000; x++) for (final String expression : expressionsMap.keySet()) parser.parseExpression(configuration, processingContext, expression);
sw.stop();
System.out.println("First pass: " + sw.toString());
sw.reset();
sw.start();
for (int x = 0; x < 1000; x++) for (final String expression : expressionsMap.keySet()) parser.parseExpression(configuration, processingContext, expression);
sw.stop();
System.out.println("Second pass: " + sw.toString());
}
use of org.thymeleaf.context.ProcessingContext in project thymeleaf-tests by thymeleaf.
the class BareHtmlEngineTest method check.
private static void check(final String input, final String output, final String[] blockSelectors) throws Exception {
final String templateName = "test";
final StringWriter writer = new StringWriter();
final ITemplateHandler handler = new OutputTemplateHandler(writer);
handler.setProcessingContext(new ProcessingContext(TEMPLATE_ENGINE_CONFIGURATION, templateName, TemplateMode.HTML, Locale.US, null));
if (blockSelectors != null) {
PARSER.parse(TEMPLATE_ENGINE_CONFIGURATION, TemplateMode.HTML, new StringResource(templateName, input), blockSelectors, handler);
} else {
PARSER.parse(TEMPLATE_ENGINE_CONFIGURATION, TemplateMode.HTML, new StringResource(templateName, input), handler);
}
Assert.assertEquals("Test failed for file: " + templateName, output, writer.toString());
}
Aggregations