Search in sources :

Example 1 with Props

use of org.febit.wit.util.Props in project hutool by looly.

the class WitEngine method createEngine.

/**
 * 创建引擎
 *
 * @param config 模板配置
 * @return {@link Engine}
 */
private static Engine createEngine(TemplateConfig config) {
    final Props configProps = Engine.createConfigProps("");
    Dict dict = null;
    if (null != config) {
        dict = Dict.create();
        // 自定义编码
        dict.set("DEFAULT_ENCODING", config.getCharset());
        switch(config.getResourceMode()) {
            case CLASSPATH:
                configProps.set("pathLoader.root", config.getPath());
                configProps.set("routeLoader.defaultLoader", "classpathLoader");
                break;
            case STRING:
                configProps.set("routeLoader.defaultLoader", "stringLoader");
                break;
            case FILE:
                configProps.set("pathLoader.root", config.getPath());
                configProps.set("routeLoader.defaultLoader", "fileLoader");
                break;
            case WEB_ROOT:
                final File root = FileUtil.file(FileUtil.getWebRoot(), config.getPath());
                configProps.set("pathLoader.root", FileUtil.getAbsolutePath(root));
                configProps.set("routeLoader.defaultLoader", "fileLoader");
                break;
        }
    }
    return Engine.create(configProps, dict);
}
Also used : Dict(cn.hutool.core.lang.Dict) Props(org.febit.wit.util.Props) File(java.io.File)

Example 2 with Props

use of org.febit.wit.util.Props in project hutool by dromara.

the class WitEngine method createEngine.

/**
 * 创建引擎
 *
 * @param config 模板配置
 * @return {@link Engine}
 */
private static Engine createEngine(TemplateConfig config) {
    final Props configProps = Engine.createConfigProps("");
    Dict dict = null;
    if (null != config) {
        dict = Dict.create();
        // 自定义编码
        dict.set("DEFAULT_ENCODING", config.getCharset());
        switch(config.getResourceMode()) {
            case CLASSPATH:
                configProps.set("pathLoader.root", config.getPath());
                configProps.set("routeLoader.defaultLoader", "classpathLoader");
                break;
            case STRING:
                configProps.set("routeLoader.defaultLoader", "stringLoader");
                break;
            case FILE:
                configProps.set("pathLoader.root", config.getPath());
                configProps.set("routeLoader.defaultLoader", "fileLoader");
                break;
            case WEB_ROOT:
                final File root = FileUtil.file(FileUtil.getWebRoot(), config.getPath());
                configProps.set("pathLoader.root", FileUtil.getAbsolutePath(root));
                configProps.set("routeLoader.defaultLoader", "fileLoader");
                break;
        }
    }
    return Engine.create(configProps, dict);
}
Also used : Dict(cn.hutool.core.lang.Dict) Props(org.febit.wit.util.Props) File(java.io.File)

Aggregations

Dict (cn.hutool.core.lang.Dict)2 File (java.io.File)2 Props (org.febit.wit.util.Props)2