Search in sources :

Example 1 with ClasspathResourceLoader

use of org.rythmengine.resource.ClasspathResourceLoader 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

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