本文整理了Java中freemarker.cache.WebappTemplateLoader
类的一些代码示例,展示了WebappTemplateLoader
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebappTemplateLoader
类的具体详情如下:
包路径:freemarker.cache.WebappTemplateLoader
类名称:WebappTemplateLoader
[英]A TemplateLoader that uses streams reachable through ServletContext#getResource(String) as its source of templates.
[中]一个TemplateLoader,它使用可通过ServletContext#getResource(String)访问的流作为模板源。
代码示例来源:origin: jersey/jersey
public FreemarkerDefaultConfigurationFactory(ServletContext servletContext) {
super();
// Create different loaders.
final List<TemplateLoader> loaders = new ArrayList<>();
if (servletContext != null) {
loaders.add(new WebappTemplateLoader(servletContext));
}
loaders.add(new ClassTemplateLoader(FreemarkerDefaultConfigurationFactory.class, "/"));
try {
loaders.add(new FileTemplateLoader(new File("/")));
} catch (IOException e) {
// NOOP
}
// Create Base configuration.
configuration = new Configuration();
configuration.setTemplateLoader(new MultiTemplateLoader(loaders.toArray(new TemplateLoader[loaders.size()])));
}
代码示例来源:origin: org.freemarker/freemarker
/**
* Show class name and some details that are useful in template-not-found errors.
*
* @since 2.3.21
*/
@Override
public String toString() {
return TemplateLoaderUtils.getClassNameForToString(this)
+ "(subdirPath=" + StringUtil.jQuote(subdirPath)
+ ", servletContext={contextPath=" + StringUtil.jQuote(getContextPath())
+ ", displayName=" + StringUtil.jQuote(servletContext.getServletContextName()) + "})";
}
代码示例来源:origin: org.freemarker/freemarker
public Object findTemplateSource(String name) throws IOException {
String fullPath = subdirPath + name;
if (attemptFileAccess) {
// First try to open as plain file (to bypass servlet container resource caches).
try {
String realPath = servletContext.getRealPath(fullPath);
if (realPath != null) {
File file = new File(realPath);
if (file.canRead() && file.isFile()) {
return file;
}
}
} catch (SecurityException e) {
;// ignore
}
}
// If it fails, try to open it with servletContext.getResource.
URL url = null;
try {
url = servletContext.getResource(fullPath);
} catch (MalformedURLException e) {
LOG.warn("Could not retrieve resource " + StringUtil.jQuoteNoXSS(fullPath),
e);
return null;
}
return url == null ? null : new URLTemplateSource(url, getURLConnectionUsesCaches());
}
代码示例来源:origin: org.freemarker/freemarker
throw new TemplatePathParsingException("Template paths starting with \"{\" are reseved for future purposes");
} else {
templateLoader = new WebappTemplateLoader(srvCtx, pureTemplatePath);
代码示例来源:origin: org.freemarker/freemarker-gae
/**
* Show class name and some details that are useful in template-not-found errors.
*
* @since 2.3.21
*/
@Override
public String toString() {
return TemplateLoaderUtils.getClassNameForToString(this)
+ "(subdirPath=" + StringUtil.jQuote(subdirPath)
+ ", servletContext={contextPath=" + StringUtil.jQuote(getContextPath())
+ ", displayName=" + StringUtil.jQuote(servletContext.getServletContextName()) + "})";
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.freemarker
public Object findTemplateSource(String name) throws IOException {
String fullPath = subdirPath + name;
if (attemptFileAccess) {
// First try to open as plain file (to bypass servlet container resource caches).
try {
String realPath = servletContext.getRealPath(fullPath);
if (realPath != null) {
File file = new File(realPath);
if (file.canRead() && file.isFile()) {
return file;
}
}
} catch (SecurityException e) {
;// ignore
}
}
// If it fails, try to open it with servletContext.getResource.
URL url = null;
try {
url = servletContext.getResource(fullPath);
} catch (MalformedURLException e) {
LOG.warn("Could not retrieve resource " + StringUtil.jQuoteNoXSS(fullPath),
e);
return null;
}
return url == null ? null : new URLTemplateSource(url, getURLConnectionUsesCaches());
}
代码示例来源:origin: vivo-project/Vitro
private Template loadFreemarkerTemplate() throws IOException {
Configuration cfg = new Configuration();
cfg.setTemplateLoader(new WebappTemplateLoader(ctx));
return cfg.getTemplate(TEMPLATE_PATH);
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.freemarker
/**
* Show class name and some details that are useful in template-not-found errors.
*
* @since 2.3.21
*/
@Override
public String toString() {
return TemplateLoaderUtils.getClassNameForToString(this)
+ "(subdirPath=" + StringUtil.jQuote(subdirPath)
+ ", servletContext={contextPath=" + StringUtil.jQuote(getContextPath())
+ ", displayName=" + StringUtil.jQuote(servletContext.getServletContextName()) + "})";
}
代码示例来源:origin: org.freemarker/freemarker-gae
public Object findTemplateSource(String name) throws IOException {
String fullPath = subdirPath + name;
if (attemptFileAccess) {
// First try to open as plain file (to bypass servlet container resource caches).
try {
String realPath = servletContext.getRealPath(fullPath);
if (realPath != null) {
File file = new File(realPath);
if (file.canRead() && file.isFile()) {
return file;
}
}
} catch (SecurityException e) {
;// ignore
}
}
// If it fails, try to open it with servletContext.getResource.
URL url = null;
try {
url = servletContext.getResource(fullPath);
} catch (MalformedURLException e) {
LOG.warn("Could not retrieve resource " + StringUtil.jQuoteNoXSS(fullPath),
e);
return null;
}
return url == null ? null : new URLTemplateSource(url, getURLConnectionUsesCaches());
}
代码示例来源:origin: org.glassfish.jersey.ext/jersey-mvc-freemarker
public FreemarkerDefaultConfigurationFactory(ServletContext servletContext) {
super();
// Create different loaders.
final List<TemplateLoader> loaders = new ArrayList<>();
if (servletContext != null) {
loaders.add(new WebappTemplateLoader(servletContext));
}
loaders.add(new ClassTemplateLoader(FreemarkerDefaultConfigurationFactory.class, "/"));
try {
loaders.add(new FileTemplateLoader(new File("/")));
} catch (IOException e) {
// NOOP
}
// Create Base configuration.
configuration = new Configuration();
configuration.setTemplateLoader(new MultiTemplateLoader(loaders.toArray(new TemplateLoader[loaders.size()])));
}
代码示例来源:origin: org.apache.drill.exec/drill-java-exec
/**
* 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;
}
代码示例来源:origin: info.magnolia.core/magnolia-freemarker-support
@Override
protected TemplateLoader newDelegate() {
final WebContext webCtx = MgnlContext.getWebContextOrNull();
if (webCtx != null) {
final ServletContext sc = webCtx.getServletContext();
if (sc != null) {
return new WebappTemplateLoader(sc, "");
}
}
return null;
}
}
代码示例来源:origin: org.freemarker/com.springsource.freemarker
/**
* Create the template loader. The default implementation will create a
* {@link ClassTemplateLoader} if the template path starts with "class://",
* a {@link FileTemplateLoader} if the template path starts with "file://",
* and a {@link WebappTemplateLoader} otherwise.
* @param templatePath the template path to create a loader for
* @return a newly created template loader
* @throws IOException
*/
protected TemplateLoader createTemplateLoader(String templatePath) throws IOException
{
if (templatePath.startsWith("class://")) {
// substring(7) is intentional as we "reuse" the last slash
return new ClassTemplateLoader(getClass(), templatePath.substring(7));
} else {
if (templatePath.startsWith("file://")) {
templatePath = templatePath.substring(7);
return new FileTemplateLoader(new File(templatePath));
} else {
return new WebappTemplateLoader(this.getServletContext(), templatePath);
}
}
}
代码示例来源:origin: com.opensymphony/webwork
new MultiTemplateLoader(new TemplateLoader[]{
templatePathLoader,
new WebappTemplateLoader(servletContext),
new WebWorkClassTemplateLoader()
})
: new MultiTemplateLoader(new TemplateLoader[]{
new WebappTemplateLoader(servletContext),
new WebWorkClassTemplateLoader()
});
代码示例来源:origin: com.netflix.pytheas/pytheas-core
new MultiTemplateLoader(
new TemplateLoader[]{
new WebappTemplateLoader( context, ROOT_PATH ),
new ClassTemplateLoader( getClass(), "/"),
new URLTemplateLoader() {
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.freemarker
throw new TemplatePathParsingException("Template paths starting with \"{\" are reseved for future purposes");
} else {
templateLoader = new WebappTemplateLoader(srvCtx, pureTemplatePath);
代码示例来源:origin: org.freemarker/freemarker-gae
throw new TemplatePathParsingException("Template paths starting with \"{\" are reseved for future purposes");
} else {
templateLoader = new WebappTemplateLoader(srvCtx, pureTemplatePath);
内容来源于网络,如有侵权,请联系作者删除!