Search in sources :

Example 6 with AppConfig

use of act.conf.AppConfig in project actframework by actframework.

the class ActHttpHandler method createActionContext.

private ActionContext createActionContext(HttpServerExchange exchange) {
    App app = client.app();
    AppConfig config = app.config();
    return ActionContext.create(app, req(exchange, config), resp(exchange, config));
}
Also used : App(act.app.App) AppConfig(act.conf.AppConfig)

Example 7 with AppConfig

use of act.conf.AppConfig 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)7 App (act.app.App)2 File (java.io.File)2 NamedPort (act.app.util.NamedPort)1 Router (act.route.Router)1 VarDef (act.view.VarDef)1 Field (java.lang.reflect.Field)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 BeforeClass (org.junit.BeforeClass)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 org.osgl.$ (org.osgl.$)1 H (org.osgl.http.H)1 RythmEngine (org.rythmengine.RythmEngine)1 ISourceCodeEnhancer (org.rythmengine.extension.ISourceCodeEnhancer)1 ClasspathResourceLoader (org.rythmengine.resource.ClasspathResourceLoader)1