Package com.alibaba.citrus.turbine

Examples of com.alibaba.citrus.turbine.Context


        assertEquals(null, rundata.getAction());
    }

    @Test
    public void getContext() {
        Context context1 = rundata.getContext();
        Context context2 = rundata.getContext("app2");

        // getContext()取得当前component的context。
        assertSame(rundata.getContext("app1"), rundata.getContext());
        assertSame(rundata.getContext("app1"), context1);
View Full Code Here


            fail();
        } catch (IllegalStateException e) {
            assertThat(e, exception("can't popContext without pushContext"));
        }

        Context context1 = rundata.getContext("app1");
        Context context2 = rundata.getContext("app2");

        try {
            rundata.pushContext(null);
            fail();
        } catch (IllegalArgumentException e) {
View Full Code Here

        TurbineRunDataInternal rundata = (TurbineRunDataInternal) getTurbineRunData(request);
        String target = assertNotNull(rundata.getTarget(), "Target was not specified");

        // 检查重定向标志,如果是重定向,则不需要将页面输出。
        if (!rundata.isRedirected()) {
            Context context = rundata.getContext();

            renderTemplate(getScreenTemplate(target), context, rundata);

            // layout可被禁用。
            if (rundata.isLayoutEnabled()) {
                String layoutTemplateOverride = rundata.getLayoutTemplateOverride();

                if (layoutTemplateOverride != null) {
                    target = layoutTemplateOverride;
                }

                String layoutTemplate = getLayoutTemplate(target);

                if (templateService.exists(layoutTemplate)) {
                    String screenContent = defaultIfNull(bufferedRequestContext.popCharBuffer(), EMPTY_STRING);
                    context.put(SCREEN_PLACEHOLDER_KEY, screenContent);

                    renderTemplate(layoutTemplate, context, rundata);
                }
            }
        }
View Full Code Here

        Substitution subst = getSubstitution(pipelineContext);

        String template = trimToNull(subst.substitute(templateName));
        String module = trimToNull(subst.substitute(moduleName));

        Context context = rundata.getContext();
        ControlTool controlTool = getControlTool(context, template, module, rundata);

        // render control
        rundata.getResponse().getWriter(); // 必须先预备好buffer
        String content = controlTool.render();

        // 设置context,以便后续模块能够读取
        context.put("controlContent", content); // controlContent为control渲染的结果
        context.put("controlTarget", template != null ? template : module);

        // 重定向至controlExporter target
        rundata.setRedirectTarget(controlExporterTarget);

        pipelineContext.invokeNext();
View Full Code Here

        TurbineRunDataInternal rundata = (TurbineRunDataInternal) getTurbineRunData(request);
        String target = assertNotNull(rundata.getTarget(), "Target was not specified");

        // 检查重定向标志,如果是重定向,则不需要将页面输出。
        if (!rundata.isRedirected()) {
            Context context = rundata.getContext();

            renderTemplate(getScreenTemplate(target), context, rundata);

            // layout可被禁用。
            if (rundata.isLayoutEnabled() && bufferedRequestContext.isBuffering()) {
                String layoutTemplateOverride = rundata.getLayoutTemplateOverride();

                if (layoutTemplateOverride != null) {
                    target = layoutTemplateOverride;
                }

                String layoutTemplate = getLayoutTemplate(target);

                if (templateService.exists(layoutTemplate)) {
                    String screenContent = defaultIfNull(bufferedRequestContext.popCharBuffer(), EMPTY_STRING);
                    context.put(SCREEN_PLACEHOLDER_KEY, screenContent);

                    renderTemplate(layoutTemplate, context, rundata);
                }
            }
        }
View Full Code Here

    public static TurbineRunData getTurbineRunData(HttpServletRequest request, boolean create) {
        TurbineRunData rundata = (TurbineRunData) request.getAttribute(TURBINE_RUNDATA_KEY);

        if (rundata == null && create) {
            Context context = (Context) request.getAttribute(TURBINE_RUNDATA_CONTEXT_KEY);

            rundata = new TurbineRunDataImpl(request, context);
            request.setAttribute(TURBINE_RUNDATA_KEY, rundata);
        }
View Full Code Here

            this.name = name;
        }

        public Object resolve() {
            TurbineRunDataInternal rundata = (TurbineRunDataInternal) TurbineUtil.getTurbineRunData(request);
            Context turbineContext = rundata.getCurrentContext();

            if (turbineContext == null) {
                turbineContext = rundata.getContext(); // 默认取得screen context
            }

            Class<?> paramType = context.getTypeInfo().getRawType();
            Object value = turbineContext.get(name);

            if (paramType.isPrimitive()) {
                // 将null值转换成primitive默认值,避免出错。
                if (value == null && paramType.isPrimitive()) {
                    value = getPrimitiveDefaultValue(paramType);
View Full Code Here

            try {
                controlParameterStack.addFirst(new ControlParameters()); // 支持control的嵌套

                TurbineRunDataInternal rundata = (TurbineRunDataInternal) TurbineUtil.getTurbineRunData(this.request);
                Context contextForControl = createContextForControl(params, componentName);

                rundata.pushContext(contextForControl, templateName);

                try {
                    if (controlModule != null) {
View Full Code Here

    }

    private Context createContextForControl(ControlParameters params, String componentName) {
        // get parent context
        TurbineRunDataInternal rundata = (TurbineRunDataInternal) TurbineUtil.getTurbineRunData(this.request);
        Context screenContext = rundata.getContext(componentName);
        final Context callerContext = rundata.getCurrentContext();
        final Set<String> exportVars = params.exportVars == null ? Collections.<String>emptySet() : params.exportVars;

        // create control context
        MappedContext context = new MappedContext(screenContext) {
            @Override
            protected void internalPut(String key, Object value) {
                if (isExport(key)) {
                    callerContext.put(key, value);
                }

                super.internalPut(key, value);
            }

            @Override
            protected void internalRemove(String key) {
                if (isExport(key)) {
                    callerContext.remove(key);
                }

                super.internalRemove(key);
            }
View Full Code Here

        this.pullServices = createHashMap();
        this.contexts = createHashMap();

        if (context != null) {
            // 将context中的内容复制到新的context中,但是不要包含pull tools。
            Context newContext = getContext();
            Set<String> keys;

            if (context instanceof PullableMappedContext) {
                keys = ((PullableMappedContext) context).keySetWithoutPulling();
            } else {
                keys = context.keySet();
            }

            for (String key : keys) {
                newContext.put(key, context.get(key));
            }
        }
    }
View Full Code Here

TOP

Related Classes of com.alibaba.citrus.turbine.Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.