org.springframework.web.servlet.view.freemarker.FreeMarkerConfig Java Examples

The following examples show how to use org.springframework.web.servlet.view.freemarker.FreeMarkerConfig. 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: WebFtlsContextConfig.java    From onetwo with Apache License 2.0 6 votes vote down vote up
@Bean
	@ConditionalOnMissingBean({FreeMarkerConfig.class, FreeMarkerViewResolver.class})
	public FreeMarkerConfigurer freeMarkerConfigurer() {
		PluginFreeMarkerConfigurer configurer = new PluginFreeMarkerConfigurer();
		applyProperties(configurer);
		String[] paths = this.properties.getTemplateLoaderPath();
//		paths = ArrayUtils.add(paths, WEBFTLS_PATH);
		configurer.setTemplateLoaderPaths(paths);
		
		List<WithAnnotationBeanData<FreeMarkerViewTools>> tools = SpringUtils.getBeansWithAnnotation(applicationContext, FreeMarkerViewTools.class);
		tools.forEach(t->{
			String name = t.getAnnotation().value();
			if(StringUtils.isBlank(name)){
				name = t.getBean().getClass().getSimpleName();
			}
			configurer.setFreemarkerVariable(name, t.getBean());
			logger.info("registered FreeMarkerViewTools : {}", name);
		});
		return configurer;
	}
 
Example #2
Source File: SimpleFreeMarkerView.java    From Lottery with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 自动检测FreeMarkerConfig
 * 
 * @return
 * @throws BeansException
 */
protected FreeMarkerConfig autodetectConfiguration() throws BeansException {
	try {
		return (FreeMarkerConfig) BeanFactoryUtils
				.beanOfTypeIncludingAncestors(getApplicationContext(),
						FreeMarkerConfig.class, true, false);
	} catch (NoSuchBeanDefinitionException ex) {
		throw new ApplicationContextException(
				"Must define a single FreeMarkerConfig bean in this web application context "
						+ "(may be inherited): FreeMarkerConfigurer is the usual implementation. "
						+ "This bean may be given any name.", ex);
	}
}
 
Example #3
Source File: CrafterFreeMarkerView.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Instead of returning the same bean from the application context, a {@link FreeMarkerConfig} is returned for
 * the current {@link SiteContext}.
 */
@Override
protected FreeMarkerConfig autodetectConfiguration() throws BeansException {
    SiteContext siteContext = SiteContext.getCurrent();
    if (siteContext != null) {
        return siteContext.getFreeMarkerConfig();
    } else {
        return super.autodetectConfiguration();
    }
}
 
Example #4
Source File: SecurityServiceImpl.java    From studio with GNU General Public License v3.0 4 votes vote down vote up
public ObjectFactory<FreeMarkerConfig> getFreeMarkerConfig() {
    return freeMarkerConfig;
}
 
Example #5
Source File: SecurityServiceImpl.java    From studio with GNU General Public License v3.0 4 votes vote down vote up
public void setFreeMarkerConfig(ObjectFactory<FreeMarkerConfig> freeMarkerConfig) {
    this.freeMarkerConfig = freeMarkerConfig;
}
 
Example #6
Source File: UserServiceImpl.java    From studio with GNU General Public License v3.0 4 votes vote down vote up
public ObjectFactory<FreeMarkerConfig> getFreeMarkerConfig() {
    return freeMarkerConfig;
}
 
Example #7
Source File: UserServiceImpl.java    From studio with GNU General Public License v3.0 4 votes vote down vote up
public void setFreeMarkerConfig(ObjectFactory<FreeMarkerConfig> freeMarkerConfig) {
    this.freeMarkerConfig = freeMarkerConfig;
}
 
Example #8
Source File: SiteContextResolvingFilter.java    From engine with GNU General Public License v3.0 4 votes vote down vote up
@Required
public void setFreeMarkerConfigFactory(final ObjectFactory<FreeMarkerConfig> freeMarkerConfigFactory) {
    this.freeMarkerConfigFactory = freeMarkerConfigFactory;
}
 
Example #9
Source File: SiteContext.java    From engine with GNU General Public License v3.0 4 votes vote down vote up
public FreeMarkerConfig getFreeMarkerConfig() {
    return freeMarkerConfig;
}
 
Example #10
Source File: SiteContext.java    From engine with GNU General Public License v3.0 4 votes vote down vote up
public void setFreeMarkerConfig(FreeMarkerConfig freeMarkerConfig) {
    this.freeMarkerConfig = freeMarkerConfig;
}
 
Example #11
Source File: SiteContextFactory.java    From engine with GNU General Public License v3.0 4 votes vote down vote up
@Required
public void setFreeMarkerConfigFactory(ObjectFactory<FreeMarkerConfig> freeMarkerConfigFactory) {
    this.freeMarkerConfigFactory = freeMarkerConfigFactory;
}
 
Example #12
Source File: SimpleFreeMarkerView.java    From Lottery with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Invoked on startup. Looks for a single FreeMarkerConfig bean to find the
 * relevant Configuration for this factory.
 * <p>
 * Checks that the template for the default Locale can be found: FreeMarker
 * will check non-Locale-specific templates if a locale-specific one is not
 * found.
 * 
 * @see freemarker.cache.TemplateCache#getTemplate
 */
protected void initApplicationContext() throws BeansException {
	super.initApplicationContext();

	if (getConfiguration() == null) {
		FreeMarkerConfig config = autodetectConfiguration();
		setConfiguration(config.getConfiguration());
	}
	checkTemplate();
}