Java Code Examples for org.tio.http.common.HttpConfig#getPageRoot()

The following examples show how to use org.tio.http.common.HttpConfig#getPageRoot() . 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: FreemarkerConfig.java    From t-io with Apache License 2.0 5 votes vote down vote up
public FreemarkerConfig(HttpConfig httpConfig, ModelGenerator modelGenerator, String[] suffixes, ConfigurationCreater configurationCreater) throws IOException {
	super();
	this.configurationCreater = configurationCreater;

	String pageRoot = httpConfig.getPageRoot();
	if (pageRoot == null) {
		throw new IOException("没有配置pageRoot");
	}

	httpConfig.setFreemarkerConfig(this);

	this.httpConfig = httpConfig;
	this.modelGenerator = modelGenerator;
	this.setSuffixes(suffixes);

	this.configuration = createConfiguration(httpConfig, pageRoot);

	Map<String, String> domainPageMap = httpConfig.getDomainPageMap();
	if (domainPageMap != null && domainPageMap.size() > 0) {
		Set<Entry<String, String>> set = domainPageMap.entrySet();
		for (Entry<String, String> entry : set) {
			String domain = entry.getKey();
			String file = entry.getValue();
			//				Configuration cfg = createConfiguration(httpConfig, file);
			addDomainConfiguration(domain, file);
		}
	}
}
 
Example 2
Source File: FreemarkerConfig.java    From t-io with Apache License 2.0 5 votes vote down vote up
/**
	 * 
	 * @param httpConfig
	 * @param root
	 * @return
	 * @throws IOException
	 */
	private Configuration createConfiguration(HttpConfig httpConfig, String root) throws IOException {
		if (httpConfig.getPageRoot() == null) {
			return null;
		}

		if (configurationCreater != null) {
			return configurationCreater.createConfiguration(httpConfig, root);
		}

		Configuration cfg = new Configuration(Configuration.getVersion());

		if (httpConfig.isPageInClasspath()) {
			cfg.setClassForTemplateLoading(this.getClass(), "/" + root/**.substring("classpath:".length())*/
			);
			//cfg.setClassForTemplateLoading(FreemarkerUtil.class, "/template");
		} else {
			cfg.setDirectoryForTemplateLoading(new File(root));
		}
		cfg.setDefaultEncoding(httpConfig.getCharset());
		//		cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
		cfg.setLogTemplateExceptions(false);
		cfg.setWrapUncheckedExceptions(true);
		cfg.setTemplateExceptionHandler(ShortMessageTemplateExceptionHandler.me);
		cfg.setLocale(Locale.SIMPLIFIED_CHINESE);
		cfg.setNumberFormat("#");
//		cfg.setClassicCompatible(true);
		return cfg;
	}