Search in sources :

Example 1 with RythmEngine

use of org.rythmengine.RythmEngine in project docx4j-template by vindell.

the class WordprocessingMLRythmTemplate method getInternalEngine.

protected RythmEngine getInternalEngine() throws IOException {
    Properties props = ConfigUtils.filterWithPrefix("docx4j.rythm.", "docx4j.rythm.", Docx4jProperties.getProperties(), false);
    props.put("engine.mode", Rythm.Mode.valueOf(props.getProperty("engine.mode", "dev")));
    props.put("log.enabled", false);
    props.put("feature.smart_escape.enabled", false);
    props.put("feature.transform.enabled", false);
    try {
        props.put("home.template", Rythm.class.getResource(props.getProperty("home.template")).toURI().toURL().getFile());
    } catch (URISyntaxException e) {
        // ignore
        props.put("home.tmp", "/");
    }
    props.put("codegen.dynamic_exp.enabled", true);
    props.put("built_in.code_type", "false");
    props.put("built_in.transformer", "false");
    props.put("engine.file_write", "false");
    props.put("codegen.compact.enabled", "false");
    return new RythmEngine(props);
}
Also used : URISyntaxException(java.net.URISyntaxException) Docx4jProperties(org.docx4j.Docx4jProperties) Properties(java.util.Properties) RythmEngine(org.rythmengine.RythmEngine)

Example 2 with RythmEngine

use of org.rythmengine.RythmEngine in project actframework by actframework.

the class RythmView method getEngine.

public RythmEngine getEngine(App app) {
    RythmEngine engine = engines.get(app);
    if (null == engine) {
        RythmEngine newEngine = createEngine(app);
        engine = engines.putIfAbsent(app, newEngine);
        if (null == engine) {
            engine = newEngine;
        } else {
            newEngine.shutdown();
        }
    }
    return engine;
}
Also used : RythmEngine(org.rythmengine.RythmEngine)

Example 3 with RythmEngine

use of org.rythmengine.RythmEngine in project actframework by actframework.

the class RythmView method createEngine.

private RythmEngine createEngine(App app) {
    AppConfig config = app.config();
    Properties p = new Properties();
    p.put(ENGINE_MODE.getKey(), Act.mode().isDev() ? Rythm.Mode.dev : Rythm.Mode.prod);
    p.put(ENGINE_PLUGIN_VERSION.getKey(), Act.VERSION.getVersion());
    p.put(ENGINE_CLASS_LOADER_PARENT_IMPL.getKey(), app.classLoader());
    p.put(HOME_TMP.getKey(), createTempHome(app));
    Map map = config.rawConfiguration();
    for (Object k : map.keySet()) {
        String key = k.toString();
        if (key.startsWith("rythm.")) {
            p.put(key, map.get(key));
        }
    }
    String appRestricted = p.getProperty("rythm.sandbox.restricted_classes", "");
    appRestricted += ";act.*";
    p.put(SANDBOX_RESTRICTED_CLASS.getKey(), appRestricted);
    p.put(HOME_TEMPLATE.getKey(), templateRootDir());
    p.put(CODEGEN_SOURCE_CODE_ENHANCER.getKey(), new ISourceCodeEnhancer() {

        @Override
        public List<String> imports() {
            return C.list();
        }

        @Override
        public String sourceCode() {
            return "";
        }

        @Override
        public Map<String, ?> getRenderArgDescriptions() {
            Map<String, String> map = new HashMap<>();
            for (VarDef var : Act.viewManager().implicitActionViewVariables()) {
                map.put(var.name(), var.type());
            }
            return map;
        }

        @Override
        public void setRenderArgs(ITemplate iTemplate) {
        // no need to set render args here as
        // it's all done at TemplateBase#exposeImplicitVariables
        }
    });
    RythmEngine engine = new RythmEngine(p);
    engine.resourceManager().prependResourceLoader(new ClasspathResourceLoader(engine, ID));
    if (config.defaultView() == this) {
        String home = config.templateHome();
        if (S.neq("default", home) && S.neq(ID, home)) {
            engine.resourceManager().prependResourceLoader(new ClasspathResourceLoader(engine, home));
        }
    }
    Tags tags = app.getInstance(Tags.class);
    tags.register(engine);
    return engine;
}
Also used : AppConfig(act.conf.AppConfig) Properties(java.util.Properties) RythmEngine(org.rythmengine.RythmEngine) ISourceCodeEnhancer(org.rythmengine.extension.ISourceCodeEnhancer) VarDef(act.view.VarDef) List(java.util.List) ClasspathResourceLoader(org.rythmengine.resource.ClasspathResourceLoader) ITemplate(org.rythmengine.template.ITemplate) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Aggregations

RythmEngine (org.rythmengine.RythmEngine)3 Properties (java.util.Properties)2 AppConfig (act.conf.AppConfig)1 VarDef (act.view.VarDef)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Docx4jProperties (org.docx4j.Docx4jProperties)1 ISourceCodeEnhancer (org.rythmengine.extension.ISourceCodeEnhancer)1 ClasspathResourceLoader (org.rythmengine.resource.ClasspathResourceLoader)1 ITemplate (org.rythmengine.template.ITemplate)1