freemarker.cache.ClassTemplateLoader Java Examples
The following examples show how to use
freemarker.cache.ClassTemplateLoader.
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: DrillRestServer.java From Bats with Apache License 2.0 | 7 votes |
/** * Creates freemarker configuration settings, * default output format to trigger auto-escaping policy * and template loaders. * * @param servletContext servlet context * @return freemarker configuration settings */ private Configuration getFreemarkerConfiguration(ServletContext servletContext) { Configuration configuration = new Configuration(Configuration.VERSION_2_3_26); configuration.setOutputFormat(HTMLOutputFormat.INSTANCE); List<TemplateLoader> loaders = new ArrayList<>(); loaders.add(new WebappTemplateLoader(servletContext)); loaders.add(new ClassTemplateLoader(DrillRestServer.class, "/")); try { loaders.add(new FileTemplateLoader(new File("/"))); } catch (IOException e) { logger.error("Could not set up file template loader.", e); } configuration.setTemplateLoader(new MultiTemplateLoader(loaders.toArray(new TemplateLoader[loaders.size()]))); return configuration; }
Example #2
Source File: FreemarkerTemplateEngine.java From enkan with Eclipse Public License 1.0 | 6 votes |
private TemplateLoader createTemplateLoader() { TemplateLoader classTemplateLoader = new ClassTemplateLoader(classLoader, prefix); if (templateLoader != null) { if (templateLoader instanceof MultiTemplateLoader) { MultiTemplateLoader mtl = (MultiTemplateLoader) templateLoader; TemplateLoader[] loaders = new TemplateLoader[mtl.getTemplateLoaderCount() + 1]; for(int i=0; i < mtl.getTemplateLoaderCount(); i++) { loaders[i] = mtl.getTemplateLoader(i); } loaders[mtl.getTemplateLoaderCount() + 1] = classTemplateLoader; return new MultiTemplateLoader(loaders); } else { return new MultiTemplateLoader(new TemplateLoader[]{templateLoader, classTemplateLoader}); } } else { return classTemplateLoader; } }
Example #3
Source File: TckComparisonReport.java From openCypher with Apache License 2.0 | 6 votes |
public static void generate(File outputDir, Diff diff) throws IOException, TemplateException { File report = new File(outputDir, "comparison.html"); Configuration cfg = new Configuration(VERSION_2_3_23); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(RETHROW_HANDLER); ClassTemplateLoader templateLoader = new ClassTemplateLoader(TckComparisonReport.class, ""); cfg.setTemplateLoader(templateLoader); Map<String, Object> input = new HashMap<>(); input.put("diff", diff); try (Writer fileWriter = new FileWriter(report)) { Template template = cfg.getTemplate("ComparisonReport.ftl"); template.process(input, fileWriter); System.out.println("\nComparison report saved to " + report.toURI()); } }
Example #4
Source File: CreateExtensionMojo.java From quarkus with Apache License 2.0 | 6 votes |
static TemplateLoader createTemplateLoader(File basedir, String templatesUriBase) throws IOException { final TemplateLoader defaultLoader = new ClassTemplateLoader(CreateExtensionMojo.class, DEFAULT_TEMPLATES_URI_BASE.substring(CLASSPATH_PREFIX.length())); if (DEFAULT_TEMPLATES_URI_BASE.equals(templatesUriBase)) { return defaultLoader; } else if (templatesUriBase.startsWith(CLASSPATH_PREFIX)) { return new MultiTemplateLoader( // new TemplateLoader[] { // new ClassTemplateLoader(CreateExtensionMojo.class, templatesUriBase.substring(CLASSPATH_PREFIX.length())), // defaultLoader // }); } else if (templatesUriBase.startsWith(FILE_PREFIX)) { final Path resolvedTemplatesDir = basedir.toPath().resolve(templatesUriBase.substring(FILE_PREFIX.length())); return new MultiTemplateLoader( // new TemplateLoader[] { // new FileTemplateLoader(resolvedTemplatesDir.toFile()), defaultLoader // }); } else { throw new IllegalStateException(String.format( "Cannot handle templatesUriBase '%s'; only value starting with '%s' or '%s' are supported", templatesUriBase, CLASSPATH_PREFIX, FILE_PREFIX)); } }
Example #5
Source File: FreeMarkerFormatter.java From ofexport2 with Apache License 2.0 | 6 votes |
public FreeMarkerFormatter(String templateName) throws IOException { // If the resource doesn't exist abort so we can look elsewhere try ( InputStream in = this.getClass().getResourceAsStream(TEMPLATES + "/" + templateName)) { if (in == null) { throw new IOException("Resource not found:" + templateName); } } this.templateName = templateName; Configuration cfg = new Configuration(Configuration.VERSION_2_3_21); TemplateLoader templateLoader = new ClassTemplateLoader(this.getClass(), TEMPLATES); cfg.setTemplateLoader(templateLoader); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); // This is fatal - bomb out of application try { template = cfg.getTemplate(templateName); } catch (IOException e) { throw new IllegalArgumentException(e); } }
Example #6
Source File: Freemarker.java From freeacs with MIT License | 6 votes |
/** * Inits the freemarker. * * @return the configuration */ public static Configuration initFreemarker() { try { Configuration config = new Configuration(); config.setTemplateLoader(new ClassTemplateLoader(Freemarker.class, "/templates")); config.setTemplateUpdateDelay(0); config.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER); config.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER); config.setDefaultEncoding("ISO-8859-1"); config.setOutputEncoding("ISO-8859-1"); config.setNumberFormat("0"); config.setSetting("url_escaping_charset", "ISO-8859-1"); config.setLocale(Locale.ENGLISH); setAutoImport(config); setSharedVariables(config); return config; } catch (Throwable e) { throw new RuntimeException("Could not initialise Freemarker configuration", e); } }
Example #7
Source File: FreemarkerEmailTemplate.java From LuckyFrameClient with GNU Affero General Public License v3.0 | 6 votes |
/** * ģ���������� */ public String getText(String templateId, Map<Object, Object> parameters) { @SuppressWarnings("deprecation") Configuration configuration = new Configuration(); configuration.setTemplateLoader(new ClassTemplateLoader(FreemarkerEmailTemplate.class, TEMPLATE_PATH)); configuration.setDefaultEncoding("gbk"); //configuration.setEncoding(Locale.getDefault(), "UTF-8"); configuration.setDateFormat("yyyy-MM-dd HH:mm:ss"); String templateFile = templateId + SUFFIX; try { Template template = TEMPLATE_CACHE.get(templateFile); if (template == null) { template = configuration.getTemplate(templateFile); TEMPLATE_CACHE.put(templateFile, template); } StringWriter stringWriter = new StringWriter(); parameters.put("webip", WEB_IP); parameters.put("webport", WEB_PORT); template.process(parameters, stringWriter); return stringWriter.toString(); } catch (Exception e) { LogUtil.APP.error("��ȡ�ʼ�ģ���������ó����쳣",e); throw new RuntimeException(e); } }
Example #8
Source File: FreeMarkerRenderer.java From opoopress with Apache License 2.0 | 6 votes |
private TemplateLoader buildTemplateLoader(Site site) { try { List<TemplateLoader> loaders = new ArrayList<TemplateLoader>(); loaders.add(new FileTemplateLoader(workingTemplateDir)); loaders.add(new FileTemplateLoader(templateDir)); loaders.add(new ClassTemplateLoader(AbstractFreeMarkerRenderer.class, "/org/opoo/press/templates")); //template registered by plugins List<TemplateLoader> instances = site.getFactory().getPluginManager().getObjectList(TemplateLoader.class); if (instances != null && !instances.isEmpty()) { loaders.addAll(instances); } TemplateLoader[] loadersArray = loaders.toArray(new TemplateLoader[loaders.size()]); return new MultiTemplateLoader(loadersArray); } catch (IOException e) { throw new IllegalArgumentException(e); } }
Example #9
Source File: HeaderSampler.java From log-synth with Apache License 2.0 | 6 votes |
private void setupTemplate() throws IOException { Configuration cfg = new Configuration(Configuration.VERSION_2_3_21); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); cfg.setTemplateLoader(new ClassTemplateLoader(getClass(), "/web-headers")); String templateName = "header"; switch (headerType) { case MAL3: templateName = "mal3"; break; case ABABIL: templateName = "ababil"; break; default: break; } template = cfg.getTemplate(templateName); }
Example #10
Source File: AdminFreemarkerTemplateProvider.java From karyon with Apache License 2.0 | 6 votes |
@PostConstruct public void commonConstruct() { // Just look for files in the class path fmConfig.setTemplateLoader(new MultiTemplateLoader(new TemplateLoader[]{ new ViewableResourceTemplateLoader(), new ClassTemplateLoader(getClass(), "/"), })); fmConfig.setNumberFormat("0"); fmConfig.setLocalizedLookup(false); fmConfig.setTemplateUpdateDelay(0); try { if (manager != null) { fmConfig.setSharedVariable("Global", manager.getGlobalModel()); fmConfig.setSharedVariable("Explorers", manager); } fmConfig.setSharedVariable("toJson", new ToJsonMethod()); } catch (TemplateModelException e) { throw new RuntimeException(e); } }
Example #11
Source File: FreemarkerAftBase.java From rice with Educational Community License v2.0 | 5 votes |
@Override @Before public void testSetUp() { super.testSetUp(); // generated load users and group resources cfg = new Configuration(); cfg.setTemplateLoader(new ClassTemplateLoader(getClass().getClassLoader().getClass(), getTemplateDir())); }
Example #12
Source File: XmlIngester.java From rice with Educational Community License v2.0 | 5 votes |
@Override public void testSetUp() { super.testSetUp(); // generated load users and group resources cfg = new Configuration(); cfg.setTemplateLoader(new ClassTemplateLoader(getClass().getClassLoader().getClass(), DIR_TMPL)); }
Example #13
Source File: TextReporter.java From revapi with Apache License 2.0 | 5 votes |
/** * Creates a new FreeMarker configuration. * By default, it is configured as follows: * <ul> * <li>compatibility level is set to 2.3.23 * <li>the object wrapper is configured to expose fields * <li>API builtins are enabled * <li>there are 2 template loaders - 1 for loading templates from /META-INF using a classloader and a second * one to load templates from files. * </ul> * @return */ protected Configuration createFreeMarkerConfiguration() { DefaultObjectWrapperBuilder bld = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_23); bld.setExposeFields(true); Configuration freeMarker = new Configuration(Configuration.VERSION_2_3_23); freeMarker.setObjectWrapper(bld.build()); freeMarker.setAPIBuiltinEnabled(true); freeMarker.setTemplateLoader(new MultiTemplateLoader( new TemplateLoader[]{new ClassTemplateLoader(getClass(), "/META-INF"), new NaiveFileTemplateLoader()})); return freeMarker; }
Example #14
Source File: MolgenisWebAppConfig.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
/** * Configure freemarker. All freemarker templates should be on the classpath in a package called * 'freemarker' */ @Bean public FreeMarkerConfigurer freeMarkerConfigurer() { FreeMarkerConfigurer result = new FreeMarkerConfigurer() { @Override protected void postProcessConfiguration(Configuration config) { config.setObjectWrapper(new MolgenisFreemarkerObjectWrapper(VERSION_2_3_23)); } @Override protected void postProcessTemplateLoaders(List<TemplateLoader> templateLoaders) { templateLoaders.add(new ClassTemplateLoader(FreeMarkerConfigurer.class, "")); } }; result.setPreferFileSystemAccess(false); result.setTemplateLoaderPath("classpath:/templates/"); result.setDefaultEncoding("UTF-8"); Properties freemarkerSettings = new Properties(); freemarkerSettings.setProperty(Configuration.LOCALIZED_LOOKUP_KEY, Boolean.FALSE.toString()); freemarkerSettings.setProperty(Configuration.NUMBER_FORMAT_KEY, "computer"); result.setFreemarkerSettings(freemarkerSettings); Map<String, Object> freemarkerVariables = Maps.newHashMap(); freemarkerVariables.put("hasPermission", new HasPermissionDirective(permissionService)); freemarkerVariables.put("notHasPermission", new NotHasPermissionDirective(permissionService)); addFreemarkerVariables(freemarkerVariables); result.setFreemarkerVariables(freemarkerVariables); return result; }
Example #15
Source File: Freemarker.java From template-benchmark with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Setup public void setup() throws IOException { Configuration configuration = new Configuration(Configuration.VERSION_2_3_22); configuration.setTemplateLoader(new ClassTemplateLoader(getClass(), "/")); template = configuration.getTemplate("templates/stocks.freemarker.html"); this.context = getContext(); }
Example #16
Source File: MailTestCases.java From kaif with Apache License 2.0 | 5 votes |
@Before public void mailSetup() { configuration = new Configuration(Configuration.VERSION_2_3_21); configuration.setDefaultEncoding("UTF-8"); configuration.setTemplateLoader(new ClassTemplateLoader(MailComposer.class, "/mail")); //keep config same as application.yml and WebConfiguration.java messageSource = new ResourceBundleMessageSource(); messageSource.setBasename("i18n/messages"); messageSource.setDefaultEncoding("UTF-8"); messageSource.setFallbackToSystemLocale(false); }
Example #17
Source File: ViewBuilder.java From docker-elastic-agents-plugin with Apache License 2.0 | 5 votes |
private ViewBuilder() { configuration = new Configuration(Configuration.VERSION_2_3_23); configuration.setTemplateLoader(new ClassTemplateLoader(getClass(), "/")); configuration.setDefaultEncoding("UTF-8"); configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); configuration.setLogTemplateExceptions(false); configuration.setDateTimeFormat("iso"); }
Example #18
Source File: PluginStatusReportViewBuilder.java From docker-swarm-elastic-agent-plugin with Apache License 2.0 | 5 votes |
private PluginStatusReportViewBuilder() { configuration = new Configuration(Configuration.VERSION_2_3_23); configuration.setTemplateLoader(new ClassTemplateLoader(getClass(), "/")); configuration.setDefaultEncoding("UTF-8"); configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); configuration.setLogTemplateExceptions(false); configuration.setDateTimeFormat("iso"); }
Example #19
Source File: CqUtils.java From camel-quarkus with Apache License 2.0 | 5 votes |
static TemplateLoader createTemplateLoader(Path basePath, String defaultUriBase, String templatesUriBase) { final TemplateLoader defaultLoader = new ClassTemplateLoader(CqUtils.class, defaultUriBase.substring(CLASSPATH_PREFIX.length())); if (defaultUriBase.equals(templatesUriBase)) { return defaultLoader; } else if (templatesUriBase.startsWith(CLASSPATH_PREFIX)) { return new MultiTemplateLoader( // new TemplateLoader[] { // new ClassTemplateLoader(CqUtils.class, templatesUriBase.substring(CLASSPATH_PREFIX.length())), // defaultLoader // }); } else if (templatesUriBase.startsWith(FILE_PREFIX)) { final Path resolvedTemplatesDir = basePath.resolve(templatesUriBase.substring(FILE_PREFIX.length())); try { return new MultiTemplateLoader( // new TemplateLoader[] { // new FileTemplateLoader(resolvedTemplatesDir.toFile()), defaultLoader // }); } catch (IOException e) { throw new RuntimeException(e); } } else { throw new IllegalStateException(String.format( "Cannot handle templatesUriBase '%s'; only value starting with '%s' or '%s' are supported", templatesUriBase, CLASSPATH_PREFIX, FILE_PREFIX)); } }
Example #20
Source File: BaseDocumentationTest.java From connect-utils with Apache License 2.0 | 5 votes |
@BeforeAll public static void loadTemplates() { loader = new ClassTemplateLoader( BaseDocumentationTest.class, "templates" ); configuration = new Configuration(Configuration.getVersion()); configuration.setDefaultEncoding("UTF-8"); configuration.setTemplateLoader(loader); configuration.setObjectWrapper(new BeansWrapper(Configuration.getVersion())); configuration.setNumberFormat("computer"); }
Example #21
Source File: PluginStatusReportViewBuilder.java From kubernetes-elastic-agents with Apache License 2.0 | 5 votes |
private PluginStatusReportViewBuilder() { configuration = new Configuration(Configuration.VERSION_2_3_23); configuration.setTemplateLoader(new ClassTemplateLoader(getClass(), "/")); configuration.setDefaultEncoding("UTF-8"); configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); configuration.setLogTemplateExceptions(false); configuration.setDateTimeFormat("iso"); }
Example #22
Source File: TemplateWrapperFactory.java From sailfish-core with Apache License 2.0 | 5 votes |
public TemplateWrapperFactory(String templatesPackagePath) { configuration = new Configuration(Configuration.VERSION_2_3_24); configuration.setTemplateLoader(new ClassTemplateLoader(HtmlReport.class, templatesPackagePath)); configuration.setDefaultEncoding("UTF-8"); configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); configuration.setAPIBuiltinEnabled(true); configuration.setObjectWrapper(new BeansWrapperBuilder(Configuration.VERSION_2_3_24).build()); configuration.setRecognizeStandardFileExtensions(true); }
Example #23
Source File: HelpTemplateWrapperFactory.java From sailfish-core with Apache License 2.0 | 5 votes |
public HelpTemplateWrapperFactory(String templatesPackagePath) throws IOException { configuration = new Configuration(Configuration.VERSION_2_3_24); configuration.setTemplateLoader(new ClassTemplateLoader(HelpBuilder.class, templatesPackagePath)); configuration.setDefaultEncoding("UTF-8"); configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); configuration.setAPIBuiltinEnabled(true); configuration.setRecognizeStandardFileExtensions(true); }
Example #24
Source File: FreeMarkerConfig.java From Spring-Boot-2.0-Projects with MIT License | 5 votes |
@Bean public freemarker.template.Configuration configuration(){ final freemarker.template.Configuration cfg = new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_22); cfg.setTemplateLoader(new ClassTemplateLoader(getClass(), "/templates")); cfg.setDefaultEncoding(StandardCharsets.UTF_8.name()); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.IGNORE_HANDLER); return cfg; }
Example #25
Source File: JestTemplate.java From doov with Apache License 2.0 | 5 votes |
static Configuration getConfiguration() { if (CONFIGURATION == null) { Configuration configuration = new Configuration(Configuration.VERSION_2_3_20); configuration.setDefaultEncoding("UTF-8"); configuration.setTemplateLoader(new ClassTemplateLoader(JestTemplate.class, "/")); CONFIGURATION = configuration; } return CONFIGURATION; }
Example #26
Source File: Freemarker.java From freeacs with MIT License | 5 votes |
public Configuration initFreemarker() { Configuration config = new Configuration(); config.setTemplateLoader(new ClassTemplateLoader(Freemarker.class, "/templates")); config.setTemplateUpdateDelay(0); config.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER); config.setObjectWrapper(ObjectWrapper.DEFAULT_WRAPPER); config.setDefaultEncoding("UTF-8"); config.setOutputEncoding("UTF-8"); return config; }
Example #27
Source File: GenerateHQL.java From occurrence with Apache License 2.0 | 4 votes |
public static void main(String[] args) { try { Preconditions.checkState(1 == args.length, "Output path for HQL files is required"); File outDir = new File(args[0]); Preconditions.checkState(outDir.exists() && outDir.isDirectory(), "Output directory must exist"); // create the sub directories into which we will write File createTablesDir = new File(outDir, CREATE_TABLES_DIR); File downloadDir = new File(outDir, DOWNLOAD_DIR); File simpleCsvDownloadDir = new File(outDir, SIMPLE_CSV_DOWNLOAD_DIR); File simpleWithVerbatimAvroDownloadDir = new File(outDir, SIMPLE_WITH_VERBATIM_AVRO_DOWNLOAD_DIR); File simpleAvroDownloadDir = new File(outDir, SIMPLE_AVRO_DOWNLOAD_DIR); File iucnDownloadDir = new File(outDir, IUCN_DOWNLOAD_DIR); File mapOfLifeDownloadDir = new File(outDir, MAP_OF_LIFE_DOWNLOAD_DIR); File avroSchemasDir = new File(outDir, AVRO_SCHEMAS_DIR); createTablesDir.mkdirs(); downloadDir.mkdirs(); simpleCsvDownloadDir.mkdirs(); simpleAvroDownloadDir.mkdirs(); simpleWithVerbatimAvroDownloadDir.mkdirs(); iucnDownloadDir.mkdirs(); mapOfLifeDownloadDir.mkdirs(); avroSchemasDir.mkdirs(); Configuration cfg = new Configuration(); cfg.setTemplateLoader(new ClassTemplateLoader(GenerateHQL.class, "/templates")); generateOccurrenceAvroSchema(avroSchemasDir); generateOccurrenceAvroTableHQL(cfg, createTablesDir); // generates HQL executed at actual download time (tightly coupled to table definitions above, hence this is // co-located) generateQueryHQL(cfg, downloadDir); generateSimpleCsvQueryHQL(cfg, simpleCsvDownloadDir); generateSimpleAvroQueryHQL(cfg, simpleAvroDownloadDir); generateSimpleAvroSchema(cfg, simpleAvroDownloadDir.getParentFile()); generateSimpleWithVerbatimAvroQueryHQL(cfg, simpleWithVerbatimAvroDownloadDir); generateSimpleWithVerbatimAvroSchema(cfg, simpleWithVerbatimAvroDownloadDir.getParentFile()); generateIucnQueryHQL(cfg, iucnDownloadDir); generateMapOfLifeQueryHQL(cfg, mapOfLifeDownloadDir); generateMapOfLifeSchema(cfg, mapOfLifeDownloadDir.getParentFile()); } catch (Exception e) { // Hard exit for safety, and since this is used in build pipelines, any generation error could have // catastrophic effects - e.g. partially complete scripts being run, and resulting in inconsistent // data. System.err.println("*** Aborting JVM ***"); System.err.println("Unexpected error building the templated HQL files. " + "Exiting JVM as a precaution, after dumping technical details."); e.printStackTrace(); System.exit(-1); } }
Example #28
Source File: FreeMarkerConfigurer.java From spring-analysis-note with MIT License | 4 votes |
/** * This implementation registers an additional ClassTemplateLoader * for the Spring-provided macros, added to the end of the list. */ @Override protected void postProcessTemplateLoaders(List<TemplateLoader> templateLoaders) { templateLoaders.add(new ClassTemplateLoader(FreeMarkerConfigurer.class, "")); }
Example #29
Source File: FreeMarkerConfigurer.java From spring-analysis-note with MIT License | 4 votes |
/** * This implementation registers an additional ClassTemplateLoader * for the Spring-provided macros, added to the end of the list. */ @Override protected void postProcessTemplateLoaders(List<TemplateLoader> templateLoaders) { templateLoaders.add(new ClassTemplateLoader(FreeMarkerConfigurer.class, "")); }
Example #30
Source File: CrafterFreeMarkerConfigurer.java From engine with GNU General Public License v3.0 | 4 votes |
@Override protected void postProcessTemplateLoaders(List<TemplateLoader> templateLoaders) { // Overwrote to get rid of the log.info templateLoaders.add(new ClassTemplateLoader(FreeMarkerConfigurer.class, "")); }