本文整理汇总了Java中freemarker.template.Configuration.setClassLoaderForTemplateLoading方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.setClassLoaderForTemplateLoading方法的具体用法?Java Configuration.setClassLoaderForTemplateLoading怎么用?Java Configuration.setClassLoaderForTemplateLoading使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类freemarker.template.Configuration
的用法示例。
在下文中一共展示了Configuration.setClassLoaderForTemplateLoading方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
import freemarker.template.Configuration; //导入方法依赖的package包/类
public void render(String modelType) throws IOException {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setClassLoaderForTemplateLoading(SimpleModel.class.getClassLoader(), "/");
if (!outDir.getParentFile().exists())
outDir.getParentFile().mkdirs();
String modelTypeName = modelType.substring(0, 1).toUpperCase() + modelType.substring(1);
Map<String, Object> params = new HashMap<String, Object>();
params.put("packageName", packageName);
params.put("models", models);
writeFile(packageName, modelTypeName, getTemplate(cfg, modelType), params);
for (SimpleModel model : models) {
if (model.isRender()) {
params = new HashMap<>();
params.put("model", model);
writeFile(model.getPackageName(), model.getName(), getModelTemplate(cfg), params);
}
}
}
示例2: templateConfiguration
import freemarker.template.Configuration; //导入方法依赖的package包/类
private static Configuration templateConfiguration() {
Configuration configuration = new Configuration(Configuration.VERSION_2_3_26);
configuration.setDefaultEncoding("UTF-8");
configuration.setLogTemplateExceptions(false);
try {
configuration.setSetting("object_wrapper",
"DefaultObjectWrapper(2.3.26, forceLegacyNonListCollections=false, "
+ "iterableSupport=true, exposeFields=true)");
} catch (TemplateException e) {
e.printStackTrace();
}
configuration.setAPIBuiltinEnabled(true);
configuration.setClassLoaderForTemplateLoading(ClassLoader.getSystemClassLoader(),
"templates/ccda");
return configuration;
}
示例3: getConfigurationByClassLoader
import freemarker.template.Configuration; //导入方法依赖的package包/类
public static Configuration getConfigurationByClassLoader(ClassLoader classLoader, String prefix)
{
try
{
Configuration configuration = new Configuration(Configuration.VERSION_2_3_25);
configuration.setClassLoaderForTemplateLoading(classLoader, prefix);
//等价于下面这种方法
// configuration.setTemplateLoader( new ClassTemplateLoader(paramClass,prefix));
configuration.setObjectWrapper(new DefaultObjectWrapper(Configuration.VERSION_2_3_25));
configuration.setDefaultEncoding(CharEncoding.UTF_8);
configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
configuration.setObjectWrapper(new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25).build());
return configuration;
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
示例4: JoomlaHugoConverter
import freemarker.template.Configuration; //导入方法依赖的package包/类
public JoomlaHugoConverter(NastyContentChecker nastyContentChecker,
JdbcTemplate template, String pathToOutput, String dbExtension,
boolean buildTags) throws IOException {
this.dbExtension = dbExtension;
this.nastyContentChecker = nastyContentChecker;
this.template = template;
this.pathToOutput = pathToOutput;
this.buildTags = buildTags;
Configuration cfg = new Configuration(Configuration.getVersion());
cfg.setClassLoaderForTemplateLoading(ClassLoader.getSystemClassLoader(), "/");
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setLogTemplateExceptions(false);
categoryTemplate = cfg.getTemplate("categoryPage.toml.ftl");
contentTemplate = cfg.getTemplate("defaultPage.toml.ftl");
buildTags();
}
示例5: init
import freemarker.template.Configuration; //导入方法依赖的package包/类
private void init() {
if (inited) {
return;
}
lock.lock();
try {
if (!inited) {
cfg = new Configuration(Configuration.VERSION_2_3_25);
cfg.setDefaultEncoding(encode);
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setClassLoaderForTemplateLoading(ClassLoader.getSystemClassLoader(), tmplPath);
}
} finally {
lock.unlock();
}
}
示例6: processIndexPageTemplate
import freemarker.template.Configuration; //导入方法依赖的package包/类
private void processIndexPageTemplate(ProjectDescriptor projectDescriptor, CustomData customData) throws IOException, URISyntaxException, TemplateException {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);
cfg.setClassLoaderForTemplateLoading(getClass().getClassLoader(), "template");
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setLogTemplateExceptions(false);
Map<String, Object> root = new HashMap<String, Object>();
root.put("project", projectDescriptor);
root.put("customData", customData);
Template template = cfg.getTemplate("index.ftl");
template.process(root, new FileWriter(new File(outputDir, "index.html")));
}
示例7: createConfiguration
import freemarker.template.Configuration; //导入方法依赖的package包/类
private void createConfiguration(String basePackagePath) {
cfg = new Configuration(Configuration.VERSION_2_3_26);
cfg.setClassLoaderForTemplateLoading(getClass().getClassLoader(), basePackagePath);
cfg.setLogTemplateExceptions(false);
setDefaultEncoding("UTF-8");
setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
}
示例8: render
import freemarker.template.Configuration; //导入方法依赖的package包/类
public void render() throws IOException {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setClassLoaderForTemplateLoading(getClass().getClassLoader(), "/");
renderPersistence(cfg);
renderContentProvider(cfg);
renderDbHelper(cfg);
renderModels(cfg);
renderMappers(cfg);
}
示例9: init
import freemarker.template.Configuration; //导入方法依赖的package包/类
@PostConstruct
public void init()
{
Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
cfg.setDefaultEncoding("UTF-8");
String templatePath = _config.get("view.freemarker.templates",
"classpath:/templates");
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (templatePath.startsWith("classpath:")) {
String path = templatePath.substring(("classpath:").length());
cfg.setClassLoaderForTemplateLoading(loader, path);
}
else {
throw new UnsupportedOperationException();
}
cfg.setAutoFlush(false);
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
_cfg = cfg;
}
示例10: createTemplateConfiguration
import freemarker.template.Configuration; //导入方法依赖的package包/类
private static Configuration createTemplateConfiguration() {
// The templates rendered by this demo application are based on Apache Freemarker.
Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
cfg.setClassLoaderForTemplateLoading(TotpExample.class.getClassLoader(), ResourcesHome.class.getPackage().getName().replace(".", "/"));
cfg.setDefaultEncoding("UTF-8");
// SECURITY NOTE: You should use the TemplateExceptionHandler.RETHROW_HANDLER in production!
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
return cfg;
}
示例11: renderModelBindings
import freemarker.template.Configuration; //导入方法依赖的package包/类
void renderModelBindings() throws Exception {
if (bindings.size() == 0 && allModels.size() == 0)
return;
Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setClassLoaderForTemplateLoading(getClass().getClassLoader(), "/");
Template bindingTemplate = cfg.getTemplate("templates/java/binding.ftl");
for (IntentBinding binding : bindings) {
String name = (binding.getPackageName() != null ? binding.getPackageName() + "." : "")
+ binding.getName() + "Binding";
JavaFileObject file = this.processingEnv.getFiler()
.createSourceFile(name, binding.getElement());
Writer writer = file.openWriter();
try {
Map<String, Object> model = new HashMap<>();
model.put("binding", binding);
model.put("cyto", "true".equals(processingEnv.getOptions().get(UI)));
bindingTemplate.process(model, writer);
writer.flush();
} catch (TemplateException err) {
throw new IOException(err);
}
writer.close();
}
if (allModels.size() > 0) {
Element[] elements = new Element[allModels.size()];
int ix = 0;
for (SimpleModel simpleModel : allModels.values()) {
elements[ix++] = simpleModel.getElement();
if (simpleModel instanceof ArrayModel) {
ArrayModel arrayModel = (ArrayModel) simpleModel;
if (arrayModel.getModel() == null)
((ArrayModel) simpleModel).setModel(allModels.get(arrayModel.getModelId()));
continue;
}
if (simpleModel.getParentId() != null && simpleModel.getParent() == null) {
simpleModel.setParent(allModels.get(simpleModel.getParentId()));
simpleModel.getProperties().addAll(simpleModel.getParent().getProperties());
}
for (Property property : simpleModel.getProperties()) {
if (property.getModelId() != null) {
property.setModel(allModels.get(property.getModelId()));
if (property.getModel() == null)
throw new Exception("Model (" + property.getModelId() + ") not found");
}
}
}
String modelTypes = processingEnv.getOptions().get(MODEL_TYPES);
if (modelTypes != null) {
for (String modelType : modelTypes.split(",")) {
String packageName = processingEnv.getOptions().get(DEFAULT_PACKAGE);
if (packageName == null)
packageName = "nuclei.data";
Context context = new Context(allModels.values(), packageName, null);
context.render(cfg, modelType, processingEnv.getFiler());
}
}
}
}