本文整理汇总了Java中groovy.text.markup.MarkupTemplateEngine类的典型用法代码示例。如果您正苦于以下问题:Java MarkupTemplateEngine类的具体用法?Java MarkupTemplateEngine怎么用?Java MarkupTemplateEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MarkupTemplateEngine类属于groovy.text.markup包,在下文中一共展示了MarkupTemplateEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveTemplate
import groovy.text.markup.MarkupTemplateEngine; //导入依赖的package包/类
/**
* Resolve a template from the given template path.
* <p>The default implementation uses the Locale associated with the current request,
* as obtained through {@link org.springframework.context.i18n.LocaleContextHolder LocaleContextHolder},
* to find the template file. Effectively the locale configured at the engine level is ignored.
* @see LocaleContextHolder
* @see #setLocale
*/
protected URL resolveTemplate(ClassLoader classLoader, String templatePath) throws IOException {
MarkupTemplateEngine.TemplateResource resource = MarkupTemplateEngine.TemplateResource.parse(templatePath);
Locale locale = LocaleContextHolder.getLocale();
URL url = classLoader.getResource(resource.withLocale(locale.toString().replace("-", "_")).toString());
if (url == null) {
url = classLoader.getResource(resource.withLocale(locale.getLanguage()).toString());
}
if (url == null) {
url = classLoader.getResource(resource.withLocale(null).toString());
}
if (url == null) {
throw new IOException("Unable to load template:" + templatePath);
}
return url;
}
示例2: isUsingGroovyAllJar
import groovy.text.markup.MarkupTemplateEngine; //导入依赖的package包/类
/**
* MarkupTemplateEngine could be loaded from groovy-templates or groovy-all.
* Unfortunately it's quite common for people to use groovy-all and not actually
* need templating support. This method check attempts to check the source jar so
* that we can skip the {@code /template} folder check for such cases.
* @return true if the groovy-all jar is used
*/
private boolean isUsingGroovyAllJar() {
try {
ProtectionDomain domain = MarkupTemplateEngine.class
.getProtectionDomain();
CodeSource codeSource = domain.getCodeSource();
if (codeSource != null
&& codeSource.getLocation().toString().contains("-all")) {
return true;
}
return false;
}
catch (Exception ex) {
return false;
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:23,代码来源:GroovyTemplateAutoConfiguration.java
示例3: resolveTemplate
import groovy.text.markup.MarkupTemplateEngine; //导入依赖的package包/类
@Override
public URL resolveTemplate(final String templatePath) throws IOException {
MarkupTemplateEngine.TemplateResource templateResource = MarkupTemplateEngine.TemplateResource
.parse(templatePath);
URL resource = this.templateClassLoader.getResource(templateResource
.withLocale(LocaleContextHolder.getLocale().toString().replace("-", "_"))
.toString());
if (resource == null) {
// no resource found with the default locale, try without any locale
resource = this.templateClassLoader
.getResource(templateResource.withLocale(null).toString());
}
if (resource == null) {
throw new IOException("Unable to load template:" + templatePath);
}
return resource;
}
示例4: autodetectMarkupTemplateEngine
import groovy.text.markup.MarkupTemplateEngine; //导入依赖的package包/类
/**
* Autodetect a MarkupTemplateEngine via the ApplicationContext.
* Called if a MarkupTemplateEngine has not been manually configured.
*/
protected MarkupTemplateEngine autodetectMarkupTemplateEngine() throws BeansException {
try {
return BeanFactoryUtils.beanOfTypeIncludingAncestors(getApplicationContext(),
GroovyMarkupConfig.class, true, false).getTemplateEngine();
}
catch (NoSuchBeanDefinitionException ex) {
throw new ApplicationContextException("Expected a single GroovyMarkupConfig bean in the current " +
"Servlet web application context or the parent root context: GroovyMarkupConfigurer is " +
"the usual implementation. This bean may have any name.", ex);
}
}
示例5: createTemplateEngine
import groovy.text.markup.MarkupTemplateEngine; //导入依赖的package包/类
protected MarkupTemplateEngine createTemplateEngine() throws IOException {
if (this.templateEngine == null) {
ClassLoader templateClassLoader = createTemplateClassLoader();
this.templateEngine = new MarkupTemplateEngine(templateClassLoader, this, new LocaleTemplateResolver());
}
return this.templateEngine;
}
示例6: defaultTemplateEngine
import groovy.text.markup.MarkupTemplateEngine; //导入依赖的package包/类
@Test
public void defaultTemplateEngine() throws Exception {
this.configurer.setApplicationContext(this.applicationContext);
this.configurer.afterPropertiesSet();
TemplateEngine engine = this.configurer.getTemplateEngine();
assertNotNull(engine);
assertEquals(MarkupTemplateEngine.class, engine.getClass());
MarkupTemplateEngine markupEngine = (MarkupTemplateEngine) engine;
TemplateConfiguration configuration = markupEngine.getTemplateConfiguration();
assertNotNull(configuration);
assertEquals(GroovyMarkupConfigurer.class, configuration.getClass());
}
示例7: customTemplateConfiguration
import groovy.text.markup.MarkupTemplateEngine; //导入依赖的package包/类
@Test
public void customTemplateConfiguration() throws Exception {
this.configurer.setApplicationContext(this.applicationContext);
this.configurer.setCacheTemplates(false);
this.configurer.afterPropertiesSet();
TemplateEngine engine = this.configurer.getTemplateEngine();
assertNotNull(engine);
assertEquals(MarkupTemplateEngine.class, engine.getClass());
MarkupTemplateEngine markupEngine = (MarkupTemplateEngine) engine;
TemplateConfiguration configuration = markupEngine.getTemplateConfiguration();
assertNotNull(configuration);
assertFalse(configuration.isCacheTemplates());
}
示例8: GroovyMarkupConfiguration
import groovy.text.markup.MarkupTemplateEngine; //导入依赖的package包/类
public GroovyMarkupConfiguration(ApplicationContext applicationContext,
GroovyTemplateProperties properties,
ObjectProvider<MarkupTemplateEngine> templateEngineProvider) {
this.applicationContext = applicationContext;
this.properties = properties;
this.templateEngine = templateEngineProvider.getIfAvailable();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:GroovyTemplateAutoConfiguration.java
示例9: renderTemplate
import groovy.text.markup.MarkupTemplateEngine; //导入依赖的package包/类
@Test
public void renderTemplate() throws Exception {
registerAndRefreshContext();
GroovyMarkupConfig config = this.context.getBean(GroovyMarkupConfig.class);
MarkupTemplateEngine engine = config.getTemplateEngine();
Writer writer = new StringWriter();
engine.createTemplate(new ClassPathResource("templates/message.tpl").getFile())
.make(new HashMap<String, Object>(
Collections.singletonMap("greeting", "Hello World")))
.writeTo(writer);
assertThat(writer.toString()).contains("Hello World");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:GroovyTemplateAutoConfigurationTests.java
示例10: GroovyMarkupTemplateGenerator
import groovy.text.markup.MarkupTemplateEngine; //导入依赖的package包/类
public GroovyMarkupTemplateGenerator(final String template) {
try {
this.template = new MarkupTemplateEngine().createTemplate(template);
} catch (ClassNotFoundException | IOException e) {
throw new BootException(e);
}
this.templateText = template;
}
示例11: renderTemplate
import groovy.text.markup.MarkupTemplateEngine; //导入依赖的package包/类
@Test
public void renderTemplate() throws Exception {
registerAndRefreshContext();
GroovyMarkupConfig config = this.context.getBean(GroovyMarkupConfig.class);
MarkupTemplateEngine engine = config.getTemplateEngine();
Writer writer = new StringWriter();
engine.createTemplate(new ClassPathResource("templates/message.tpl").getFile())
.make(new HashMap<String, Object>(
Collections.singletonMap("greeting", "Hello World")))
.writeTo(writer);
assertThat(writer.toString(), containsString("Hello World"));
}
示例12: getEngine
import groovy.text.markup.MarkupTemplateEngine; //导入依赖的package包/类
public MarkupTemplateEngine getEngine(Locale locale) {
String localeString = locale.toString();
MarkupTemplateEngine engine = engines.get(localeString);
if (engine!=null) {
return engine;
}
return lazyLoadEngine(locale);
}
示例13: init
import groovy.text.markup.MarkupTemplateEngine; //导入依赖的package包/类
@Override
public void init(Application application) {
super.init(application);
PippoSettings pippoSettings = getPippoSettings();
TemplateConfiguration configuration = new TemplateConfiguration();
configuration.setBaseTemplateClass(PippoGroovyTemplate.class);
configuration.setAutoEscape(true);
if (pippoSettings.isDev()) {
// Do not cache templates in dev mode
configuration.setCacheTemplates(false);
} else {
configuration.setAutoIndent(true);
configuration.setAutoNewLine(true);
configuration.setAutoIndentString(" ");
}
String pathPrefix = getTemplatePathPrefix();
pathPrefix = StringUtils.removeStart(pathPrefix, "/");
pathPrefix = StringUtils.removeEnd(pathPrefix, "/");
GroovyTemplateResolver cachingResolver = new GroovyTemplateResolver(pathPrefix);
ClassLoader classLoader = getClass().getClassLoader();
// allow custom initialization
init(application, configuration);
engine = new MarkupTemplateEngine(classLoader, configuration, cachingResolver);
}
示例14: PippoGroovyTemplate
import groovy.text.markup.MarkupTemplateEngine; //导入依赖的package包/类
public PippoGroovyTemplate(final MarkupTemplateEngine templateEngine, final Map model,
final Map<String, String> modelTypes, final TemplateConfiguration configuration) {
super(templateEngine, model, modelTypes, configuration);
this.modelTypes = modelTypes;
this.engine = templateEngine;
this.webjarsPatternRef = new AtomicReference<>();
this.publicPatternRef = new AtomicReference<>();
}
示例15: initializeTemplateEngine
import groovy.text.markup.MarkupTemplateEngine; //导入依赖的package包/类
private void initializeTemplateEngine() {
templateEngine = new MarkupTemplateEngine(MarkupTemplateEngine.class.getClassLoader(),templatesPath,templateConfiguration);
}