本文整理汇总了Java中freemarker.cache.FileTemplateLoader类的典型用法代码示例。如果您正苦于以下问题:Java FileTemplateLoader类的具体用法?Java FileTemplateLoader怎么用?Java FileTemplateLoader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileTemplateLoader类属于freemarker.cache包,在下文中一共展示了FileTemplateLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildFreemarkerHelper
import freemarker.cache.FileTemplateLoader; //导入依赖的package包/类
private FreemarkerHelper buildFreemarkerHelper(File templateBaseDir) {
Configuration configuration = new Configuration(new Version(2, 3, 0));
try {
TemplateLoader templateLoader = new FileTemplateLoader(templateBaseDir);
configuration.setTemplateLoader(templateLoader);
} catch (IOException e) {
throw new GeneratorException("构建模板助手出错:" + e.getMessage());
}
configuration.setNumberFormat("###############");
configuration.setBooleanFormat("true,false");
configuration.setDefaultEncoding("UTF-8");
// 自动导入公共文件,用于支持灵活变量
if (autoIncludeFile.exists()) {
List<String> autoIncludeList = new ArrayList<>();
autoIncludeList.add(FREEMARKER_AUTO_INCLUDE_SUFFIX);
configuration.setAutoIncludes(autoIncludeList);
}
return new FreemarkerHelper(configuration);
}
示例2: FreemarkerTemplateContext
import freemarker.cache.FileTemplateLoader; //导入依赖的package包/类
public FreemarkerTemplateContext(File path)
{
config = new Configuration(VERSION);
config.setDefaultEncoding("UTF-8");
config.setTemplateExceptionHandler(TemplateExceptionHandler.IGNORE_HANDLER);
try
{
//Web site location resources
FileTemplateLoader fileLoader = new FileTemplateLoader(path);
//Core common resources
ClassTemplateLoader classLoader = new ClassTemplateLoader(WebSite.class, "/");
config.setTemplateLoader(new MultiTemplateLoader(new TemplateLoader[]
{
fileLoader, classLoader
}));
}
catch (IOException ex)
{
LOG.log(Level.SEVERE, ex.getMessage(), ex);
}
}
示例3: Before
import freemarker.cache.FileTemplateLoader; //导入依赖的package包/类
@Before
public void Before() {
//准备参数
variables();
freemarkerTemplate = new WordprocessingMLFreemarkerTemplate("freemarker.tpl", false );
try {
File dirFile = new File(WordprocessingMLFreemarkerTemplate_Test.class.getResource("/tpl/").getPath());
freemarkerTemplate.setPreTemplateLoaders(new FileTemplateLoader(dirFile));
} catch (IOException e) {
e.printStackTrace();
}
}
示例4: getConfigurationByDirectory
import freemarker.cache.FileTemplateLoader; //导入依赖的package包/类
/**
* 根据模板的路径,获取一个配置文件
* @author [email protected]
* @param templateLoadingPath
* @return
*/
public static Configuration getConfigurationByDirectory(File templateLoadingPath)
{
try
{
Configuration configuration = new Configuration(Configuration.VERSION_2_3_25);
//以下这两种设置方式是等价的
// configuration.setDirectoryForTemplateLoading(templateLoadingPath);
configuration.setTemplateLoader(new FileTemplateLoader(templateLoadingPath));
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;
}
示例5: getFreemarkerConfiguration
import freemarker.cache.FileTemplateLoader; //导入依赖的package包/类
/**
* 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;
}
示例6: createLoaders
import freemarker.cache.FileTemplateLoader; //导入依赖的package包/类
static TemplateLoader[] createLoaders(String[] locations, ServletContext servletContext) {
Collection<TemplateLoader> templateLoaders = new ArrayList<TemplateLoader>();
for (String location : locations) {
String[] prefixAndBase = StringUtils.split(location, ":", 2);
if (prefixAndBase.length != 2) {
throw new OpenGammaRuntimeException("Invalid Freemarker template location: " + location);
}
String prefix = prefixAndBase[0].trim();
String base = prefixAndBase[1].trim();
if (SERVLET_CONTEXT.equals(prefix)) {
templateLoaders.add(new WebappTemplateLoader(servletContext, base));
} else if (FILE.equals(prefix)) {
try {
templateLoaders.add(new FileTemplateLoader(new File(base)));
} catch (IOException e) {
throw new OpenGammaRuntimeException("Unable to load Freemarker templates from " + base, e);
}
} else {
throw new OpenGammaRuntimeException("Invalid Freemarker template location: " + location);
}
}
return templateLoaders.toArray(new TemplateLoader[templateLoaders.size()]);
}
示例7: __doViewInit
import freemarker.cache.FileTemplateLoader; //导入依赖的package包/类
@Override
protected void __doViewInit(IWebMvc owner) {
super.__doViewInit(owner);
// 初始化Freemarker模板引擎配置
if (__freemarkerConfig == null) {
__freemarkerConfig = new Configuration(Configuration.VERSION_2_3_22);
__freemarkerConfig.setDefaultEncoding(owner.getModuleCfg().getDefaultCharsetEncoding());
__freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
//
List<TemplateLoader> _tmpLoaders = new ArrayList<TemplateLoader>();
try {
if (__baseViewPath.startsWith("/WEB-INF")) {
_tmpLoaders.add(new FileTemplateLoader(new File(RuntimeUtils.getRootPath(), StringUtils.substringAfter(__baseViewPath, "/WEB-INF/"))));
} else {
_tmpLoaders.add(new FileTemplateLoader(new File(__baseViewPath)));
}
//
__freemarkerConfig.setTemplateLoader(new MultiTemplateLoader(_tmpLoaders.toArray(new TemplateLoader[_tmpLoaders.size()])));
} catch (IOException e) {
throw new Error(RuntimeUtils.unwrapThrow(e));
}
}
}
示例8: getTemplateLoaderForPath
import freemarker.cache.FileTemplateLoader; //导入依赖的package包/类
public static TemplateLoader getTemplateLoaderForPath(ResourceLoader resourceLoader, String templateLoaderPath) {
try {
Resource path = resourceLoader.getResource(templateLoaderPath);
File file = path.getFile(); // will fail if not resolvable in the file system
if (logger.isDebugEnabled()) {
logger.debug(
"Template loader path [" + path + "] resolved to file path [" + file.getAbsolutePath() + "]");
}
return new FileTemplateLoader(file);
}
catch (IOException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Cannot resolve template loader path [" + templateLoaderPath +
"] to [java.io.File]: using SpringTemplateLoader as fallback", ex);
}
return new SpringTemplateLoader(resourceLoader, templateLoaderPath);
}
}
示例9: setupTemplateLoader
import freemarker.cache.FileTemplateLoader; //导入依赖的package包/类
protected void setupTemplateLoader() {
if (ddlTemplateFileDir != null) {
try {
FileTemplateLoader templateLoader = new FileTemplateLoader(new File("./" + ddlTemplateFileDir));
templateLoaderList.add(templateLoader);
} catch (IOException e) {
// configurationが設定されているにも関わらず到達できない
throw new IllegalArgumentException("failed to reach project resource", e);
}
}
if (url != null) {
String[] urlTokens = StringUtils.split(url, ':');
if(urlTokens.length < 3) {
throw new IllegalArgumentException("url isn't jdbc url format.");
}
templateLoaderList.add(
new ClassTemplateLoader(Erd.class, "/jp/co/tis/gsp/tools/db/template/"
+urlTokens[1]+"/")
);
}
templateLoaderList.add(
new ClassTemplateLoader(AbstractDbObjectParser.class, "/jp/co/tis/gsp/tools/db/template/"));
}
示例10: setupFreemarkerConfig
import freemarker.cache.FileTemplateLoader; //导入依赖的package包/类
private static Configuration setupFreemarkerConfig(Class[] classTemplateLookupPaths, File[] fileTemplateLookupPaths)
throws IOException {
Configuration config = new Configuration();
TemplateLoader[] loaders = new TemplateLoader[classTemplateLookupPaths.length + fileTemplateLookupPaths.length];
for (int i = 0; i < classTemplateLookupPaths.length; i++) {
loaders[i] = new ClassTemplateLoader(classTemplateLookupPaths[i], "");
}
for (int i = 0; i < fileTemplateLookupPaths.length; i++) {
loaders[classTemplateLookupPaths.length + i] = new FileTemplateLoader(fileTemplateLookupPaths[i]);
}
config.setTemplateLoader(new MultiTemplateLoader(loaders));
return config;
}
示例11: setup
import freemarker.cache.FileTemplateLoader; //导入依赖的package包/类
@Before
public void setup() throws IOException {
// Add CommonWeb to the freemarker lookup path. In deployment the files will have been copied to local.
TemplateLoader normalLoader = freemarkerConfig.getConfiguration().getTemplateLoader();
freemarkerConfig.getConfiguration().setTemplateLoader(new MultiTemplateLoader(new TemplateLoader[] {
new FileTemplateLoader(new File("CommonWeb/web/WEB-INF/freemarker")),
normalLoader
}));
// Setup Spring test in standalone mode
this.mockMvc = MockMvcBuilders
.webAppContextSetup(webApplicationContext)
.build();
// Setup user
PublicSiteUser loggedInUser = mock(PublicSiteUser.class);
when(loggedInUser.getId()).thenReturn(1);
AbstractAuthenticatingTests.setupCurrentUser(loggedInUser);
}
示例12: newConfiguration
import freemarker.cache.FileTemplateLoader; //导入依赖的package包/类
@Override
protected Configuration newConfiguration() throws IOException, TemplateException {
configuration = new Configuration(Configuration.VERSION_2_3_25);
configuration.setDefaultEncoding("UTF-8");
try {
List<TemplateLoader> loaders = new ArrayList<>();
File i18nFolder = new File(FileUtils.getUserFolder(), "i18n");
File confFolder1 = new File(FileUtils.getUserFolder(), "config");
File confFolder2 = new File(FileUtils.getUserFolder(), "src/main/config");
if (i18nFolder.exists()) {
loaders.add(new FileTemplateLoader(i18nFolder));
}
if (confFolder1.exists()) {
loaders.add(new FileTemplateLoader(confFolder1));
}
if (confFolder2.exists()) {
loaders.add(new FileTemplateLoader(confFolder2));
}
loaders.add(new ClassTemplateLoader(SiteConfiguration.class.getClassLoader(), ""));
configuration.setTemplateLoader(new MultiTemplateLoader(loaders.toArray(new TemplateLoader[loaders.size()])));
} catch (Exception e) {
LOG.error("Can not configure freemarker", e);
System.exit(-1);
}
return configuration;
}
示例13: TemplateRender
import freemarker.cache.FileTemplateLoader; //导入依赖的package包/类
/**
* Construct specifying dev mode and updateDelay.
*/
public TemplateRender(File inputDir, boolean devMode, int updateDelay) {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setUseExceptionHandler(devMode);
if (!devMode) {
builder.setTemplateUpdateDelay(updateDelay);
}
try {
FileTemplateLoader fileTemplate = new FileTemplateLoader(inputDir);
SyntaxHighlighter filter = new SyntaxHighlighter();
InheritLayoutTemplateLoader templateLoader = new InheritLayoutTemplateLoader(fileTemplate, filter);
builder.setTemplateLoader(templateLoader);
this.configuration = builder.build();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例14: buildTemplateLoader
import freemarker.cache.FileTemplateLoader; //导入依赖的package包/类
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);
}
}
示例15: intializeTemplate
import freemarker.cache.FileTemplateLoader; //导入依赖的package包/类
private void intializeTemplate() throws IOException {
if (template == null) {
// first check if there is a custom update template included on the customization that can be used for the project
String possibleUpdateKmlLocation = localPropertiesService.getProjectFolder() + File.separatorChar + STANDARD_KML_FOR_UPDATES_FILENAME;
File possibleKmlFile = new File( possibleUpdateKmlLocation );
if( possibleKmlFile.exists() ){
/*
* We need to create a new TemplateLoader and use it momentarily as by default the Template loader
* uses the basedir of the project which causes problems when loading file from outside the project folder
*/
cfg.setTemplateLoader( new FileTemplateLoader( new File( possibleKmlFile.getParent() ) ) );
template = cfg.getTemplate( STANDARD_KML_FOR_UPDATES_FILENAME );
}else{
// No specific updatekml template found on the project folder, fall back to the general one
// Load template from the resource folder
cfg.setTemplateLoader( new FileTemplateLoader( new File( "." ) ) );
template = cfg.getTemplate(GENERIC_KML_FOR_UPDATES);
}
}
}