org.thymeleaf.templateresolver.FileTemplateResolver Java Examples
The following examples show how to use
org.thymeleaf.templateresolver.FileTemplateResolver.
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: GenerationRunner.java From rdflint with MIT License | 4 votes |
/** * rdflint generation process. */ void execute(RdfLintParameters params, String targetDir) throws IOException { logger.trace("execute: in"); if (params.getGeneration() == null) { logger.trace("execute: exit"); return; } // clear output long errSize = params.getGeneration().stream().map(g -> { File f = new File(targetDir + "/" + g.getOutput()); if (!f.exists()) { return true; } return f.delete(); }).filter(v -> !v).count(); if (errSize > 0) { throw new IOException("rdflint generation, fail to clear existed output."); } // prepare thymeleaf template engine FileTemplateResolver templateResolver = new FileTemplateResolver(); templateResolver.setTemplateMode("TEXT"); templateResolver.setPrefix(targetDir + "/"); TemplateEngine templateEngine = new TemplateEngine(); templateEngine.setTemplateResolver(templateResolver); // prepare rdf dataset Model m = DatasetLoader.loadRdfSet(params, targetDir); params.getGeneration().forEach(g -> { String q = g.getQuery(); try { // execute query and build result set Query query = QueryFactory.create(q); QueryExecution qe = QueryExecutionFactory.create(query, m); ResultSet results = qe.execSelect(); List<Map<String, String>> lst = new LinkedList<>(); List<String> cols = new LinkedList<>(); while (results.hasNext()) { QuerySolution sol = results.next(); Iterator<String> it = sol.varNames(); cols.clear(); while (it.hasNext()) { cols.add(it.next()); } lst.add(cols.stream() .collect(Collectors.toMap( c -> c, c -> sol.get(c).toString() ))); } // apply template Context ctx = new Context(); ctx.setVariable("params", params); ctx.setVariable("rs", lst); templateEngine.process( g.getTemplate(), ctx, Files.newBufferedWriter(Paths.get(targetDir + "/" + g.getOutput())) ); } catch (Exception ex) { ex.printStackTrace(); // NOPMD } }); logger.trace("execute: out"); }
Example #2
Source File: FileResolverAdapter.java From ogham with Apache License 2.0 | 4 votes |
@Override public ITemplateResolver adapt(ResourceResolver resolver) { FileTemplateResolver templateResolver = new FileTemplateResolver(); applyOptions(templateResolver); return templateResolver; }
Example #3
Source File: ThymeleafTemplateEngine.java From jbake with MIT License | 4 votes |
private void initializeTemplateEngine() { templateResolver = new FileTemplateResolver(); templateResolver.setPrefix(config.getTemplateFolder().getAbsolutePath() + File.separatorChar); templateResolver.setCharacterEncoding(config.getTemplateEncoding()); templateResolver.setTemplateMode(DEFAULT_TEMPLATE_MODE); templateEngine = new TemplateEngine(); templateEngine.setTemplateResolver(templateResolver); templateEngine.clearTemplateCache(); }