Package org.auraframework.service

Examples of org.auraframework.service.InstanceService


public abstract class BaseComponentDefHTMLFormatAdapter<T extends BaseComponentDef> extends HTMLFormatAdapter<T> {

    @Override
    public void write(Object value, Map<String, Object> componentAttributes, Appendable out) throws IOException {
        try {
            InstanceService instanceService = Aura.getInstanceService();
            RenderingService renderingService = Aura.getRenderingService();
            BaseComponentDef def = (BaseComponentDef) value;

            ComponentDef templateDef = def.getTemplateDef();
            Map<String, Object> attributes = Maps.newHashMap();

            StringBuilder sb = new StringBuilder();
            writeHtmlStyles(AuraServlet.getStyles(), sb);
            attributes.put("auraStyleTags", sb.toString());
            AuraContext context = Aura.getContextService().getCurrentContext();

            DefDescriptor<StyleDef> styleDefDesc = templateDef.getStyleDescriptor();
            if (styleDefDesc != null) {
                attributes.put("auraInlineStyle", styleDefDesc.getDef().getCode());
            }

            String contextPath = context.getContextPath();
            Mode mode = context.getMode();

            if (mode.allowLocalRendering() && def.isLocallyRenderable()) {
                DefType defType = def.getDescriptor().getDefType();
                BaseComponent<?, ?> cmp = null;

                if (defType == DefType.APPLICATION) {
                    cmp = (BaseComponent<?, ?>) instanceService.getInstance((ApplicationDef) def, componentAttributes);
                } else {
                    cmp = (BaseComponent<?, ?>) instanceService.getInstance((ComponentDef) def, componentAttributes);
                }

                attributes.put("body", Lists.<BaseComponent<?, ?>> newArrayList(cmp));
                attributes.put("bodyClass", "");
                attributes.put("defaultBodyClass", "");
                attributes.put("autoInitialize", "false");
            } else {
                if (ManifestUtil.isManifestEnabled()) {
                    attributes.put("manifest", ManifestUtil.getManifestUrl());
                }

                sb.setLength(0);
                writeHtmlScripts(AuraServlet.getBaseScripts(context), sb);
                attributes.put("auraBaseScriptTags", sb.toString());

                sb.setLength(0);
                writeHtmlScripts(AuraServlet.getNamespacesScripts(context), true, sb);
                attributes.put("auraNamespacesScriptTags", sb.toString());

                if(mode != Mode.PROD && mode != Mode.PRODDEBUG &&
                        Aura.getContextService().getCurrentContext().getIsDebugToolEnabled()) {
                    attributes.put("auraInitBlock", "<script>var debugWindow=window.open('/aura/debug.cmp','Aura Debug Tool','width=900,height=305,scrollbars=0,location=0,toolbar=0,menubar=0');$A.util.setDebugToolWindow(debugWindow);</script>");


                }

                Map<String, Object> auraInit = Maps.newHashMap();
                if (componentAttributes != null && !componentAttributes.isEmpty()) {
                    auraInit.put("attributes", componentAttributes);
                }
                auraInit.put("descriptor", def.getDescriptor());
                auraInit.put("deftype", def.getDescriptor().getDefType());
                auraInit.put("host", contextPath);

                StringBuilder contextWriter = new StringBuilder();
                Aura.getSerializationService().write(context, null, AuraContext.class, contextWriter, "HTML");
                auraInit.put("context", new Literal(contextWriter.toString()));

                attributes.put("auraInit", Json.serialize(auraInit));
            }
            Component template = instanceService.getInstance(templateDef.getDescriptor(), attributes);
            renderingService.render(template, out);
        } catch (QuickFixException e) {
            throw new AuraRuntimeException(e);
        }
    }
View Full Code Here


    @Override
    public void write(Object value, Map<String, Object> componentAttributes, Appendable out) throws IOException {
        try {

            AuraContext context = Aura.getContextService().getCurrentContext();
            InstanceService instanceService = Aura.getInstanceService();
            RenderingService renderingService = Aura.getRenderingService();
            BaseComponent<?, ?> cmp = (BaseComponent<?, ?>) value;
            BaseComponentDef def = cmp.getDescriptor().getDef();

            ComponentDef templateDef = def.getTemplateDef();
            Map<String, Object> attributes = Maps.newHashMap();

            StringBuilder sb = new StringBuilder();
            writeHtmlStyles(AuraServlet.getStyles(), sb);
            attributes.put("auraStyleTags", sb.toString());
            sb.setLength(0);
            writeHtmlScripts(AuraServlet.getScripts(), sb);
            DefDescriptor<StyleDef> styleDefDesc = templateDef.getStyleDescriptor();
            if (styleDefDesc != null) {
                attributes.put("auraInlineStyle", styleDefDesc.getDef().getCode());
            }

            String contextPath = context.getContextPath();
            Mode mode = context.getMode();

            if (mode.allowLocalRendering() && def.isLocallyRenderable()) {

                DefType defType = def.getDescriptor().getDefType();

                if (defType == DefType.APPLICATION) {
                    cmp = (BaseComponent<?, ?>) instanceService.getInstance((ApplicationDef) def, componentAttributes);
                } else {
                    cmp = (BaseComponent<?, ?>) instanceService.getInstance((ComponentDef) def, componentAttributes);
                }

                attributes.put("body", Lists.<BaseComponent<?, ?>> newArrayList(cmp));
                attributes.put("bodyClass", "");
                attributes.put("autoInitialize", "false");

                Component template = instanceService.getInstance(templateDef.getDescriptor(), attributes);

                renderingService.render(template, out);
            } else {

                attributes.put("auraScriptTags", sb.toString());
                Map<String, Object> auraInit = Maps.newHashMap();
                if (componentAttributes != null && !componentAttributes.isEmpty()) {
                    auraInit.put("attributes", componentAttributes);
                }
                auraInit.put("descriptor", def.getDescriptor());
                auraInit.put("deftype", def.getDescriptor().getDefType());
                auraInit.put("host", contextPath);

                attributes.put("autoInitialize", "false");
                attributes.put("autoInitializeSync", "true");

                auraInit.put("instance", cmp);
                auraInit.put("token", AuraBaseServlet.getToken());

                StringBuilder contextWriter = new StringBuilder();
                Aura.getSerializationService().write(context, null, AuraContext.class, contextWriter, "JSON");
                auraInit.put("context", new Literal(contextWriter.toString()));

                attributes.put("auraInitSync", Json.serialize(auraInit));

                Component template = instanceService.getInstance(templateDef.getDescriptor(), attributes);
                renderingService.render(template, out);
            }
        } catch (QuickFixException e) {
            throw new AuraRuntimeException(e);
        }
View Full Code Here

            outputDir.mkdirs();
        }

        File html = new File(outputDir, "index.html");

        InstanceService instanceService = Aura.getInstanceService();
        RenderingService renderingService = Aura.getRenderingService();

        ContextService contextService = Aura.getContextService();
        AuraContext context = contextService.getCurrentContext();

        Writer htmlWriter = new FileWriter(html);
        try {
            String uid = context.getDefRegistry().getUid(null, def.getDescriptor());
            Set<DefDescriptor<?>> dependencies = context.getDefRegistry().getDependencies(uid);

            ComponentDef templateDef = def.getTemplateDef();
            Map<String, Object> attributes = Maps.newHashMap();

            StringBuilder sb = new StringBuilder();
            // Get the preload css
            List<String> styles = Lists.newArrayList(String.format("%s.css", appName));
            this.writeHtmlStyles(styles, sb);
            File css = new File(outputDir, String.format("%s.css", appName));
            FileWriter cssWriter = new FileWriter(css);
            try {
                Aura.getServerService().writeAppCss(dependencies, cssWriter);
            } finally {
                cssWriter.close();
            }
            attributes.put("auraStyleTags", sb.toString());

            // Clear sb out
            sb.setLength(0);

            List<String> scripts = Lists.newArrayList("aura.js", String.format("%s.js", appName));
            writeHtmlScripts(scripts, sb);

            // Get the framework js
            File auraJs = new File(outputDir, "aura.js");
            FileWriter auraJsWriter = new FileWriter(auraJs);
            InputStream in = Aura.getConfigAdapter().getResourceLoader()
                    .getResourceAsStream("aura/javascript/aura_dev.js");
            InputStreamReader reader = new InputStreamReader(in);
            try {
                Aura.getConfigAdapter().regenerateAuraJS();
                IOUtil.copyStream(reader, auraJsWriter);
            } finally {
                try {
                    auraJsWriter.close();
                } finally {
                    reader.close();
                }
            }

            Application instance = instanceService.getInstance(def, null);

            // Get the preload js
            File js = new File(outputDir, String.format("%s.js", appName));
            FileWriter jsWriter = new FileWriter(js);
            try {
                Aura.getServerService().writeDefinitions(dependencies, jsWriter);

                // Write the app at the bottom of the same file

                Map<String, Object> auraInit = Maps.newHashMap();

                auraInit.put("instance", instance);
                auraInit.put("token", AuraServlet.getToken());
                auraInit.put("host", context.getContextPath());

                contextService.startContext(Mode.PROD, Format.HTML, Authentication.AUTHENTICATED, def.getDescriptor());
                auraInit.put("context", contextService.getCurrentContext());
                jsWriter.append("\n$A.initConfig($A.util.json.resolveRefs(");
                Json.serialize(auraInit, jsWriter, context.getJsonSerializationContext());
                jsWriter.append("));\n");
            } finally {
                jsWriter.close();
            }

            attributes.put("auraScriptTags", sb.toString());

            DefDescriptor<StyleDef> styleDefDesc = templateDef.getStyleDescriptor();
            if (styleDefDesc != null) {
                attributes.put("auraInlineStyle", styleDefDesc.getDef().getCode());
            }

            attributes.put("autoInitialize", false);
            Component template = instanceService.getInstance(templateDef.getDescriptor(), attributes);
            renderingService.render(template, htmlWriter);
        } catch (QuickFixException e) {
            throw new AuraRuntimeException(e);
        } finally {
            htmlWriter.close();
View Full Code Here

        return ApplicationDef.class;
    }

    @Override
    public void write(Object value, Map<String, Object> componentAttributes, Appendable out) throws IOException {
        InstanceService instanceService = Aura.getInstanceService();
        RenderingService renderingService = Aura.getRenderingService();
        ApplicationDef def = (ApplicationDef) value;
        AuraContext context = Aura.getContextService().getCurrentContext();

        try {
            ComponentDef templateDef = def.getTemplateDef();
            Map<String, Object> attributes = Maps.newHashMap();

            StringBuilder sb = new StringBuilder();
            writeHtmlStyles(AuraServlet.getStyles(), sb);
            attributes.put("auraStyleTags", sb.toString());
            sb.setLength(0);
            writeHtmlScripts(AuraServlet.getScripts(), sb);
            DefDescriptor<StyleDef> styleDefDesc = templateDef.getStyleDescriptor();
            if (styleDefDesc != null) {
                attributes.put("auraInlineStyle", styleDefDesc.getDef().getCode());
            }

            attributes.put("auraScriptTags", sb.toString());
            Map<String, Object> auraInit = Maps.newHashMap();

            Application instance = instanceService.getInstance(def, null);

            auraInit.put("instance", instance);
            auraInit.put("token", AuraBaseServlet.getToken());
            auraInit.put("host", context.getContextPath());

            StringBuilder contextWriter = new StringBuilder();

            Aura.getSerializationService().write(context, null, AuraContext.class, contextWriter, "JSON");

            auraInit.put("context", new Literal(contextWriter.toString()));

            attributes.put("auraInit", Json.serialize(auraInit, context.getJsonSerializationContext()));
            Component template = instanceService.getInstance(templateDef.getDescriptor(), attributes);
            renderingService.render(template, out);
        } catch (QuickFixException e) {
            throw new AuraRuntimeException(e);
        }
    }
View Full Code Here

        Source<?> source = getSource(def.getDescriptor());
        Writer out = source.getWriter();
        try {
            Map<String, Object> attributes = Maps.newHashMap();
            attributes.put("def", def);
            InstanceService instanceService = Aura.getInstanceService();
            DefinitionService definitionService = Aura.getDefinitionService();
            DefDescriptor<ComponentDef> tmplDesc = definitionService.getDefDescriptor("auradev:saveStyle",
                    ComponentDef.class);
            Component tmpl = instanceService.getInstance(tmplDesc, attributes);
            Aura.getRenderingService().render(tmpl, out);
        } catch (QuickFixException x) {
            throw new AuraError(x);
        } catch (IOException x) {
            throw new AuraRuntimeException(x);
View Full Code Here

        SerializationService serializationService = Aura.getSerializationService();
        assertTrue(serializationService instanceof SerializationServiceImpl);
    }

    public void testWriteJson() throws Exception {
        InstanceService instanceService = Aura.getInstanceService();
        SerializationService serializationService = Aura.getSerializationService();

        StringWriter out = new StringWriter();
        Map<String, Object> attributes = new HashMap<>();
        attributes.put("attr", "yo");
        Component c = instanceService.getInstance("test:child1", ComponentDef.class, attributes);
        serializationService.write(c, null, Component.class, out);
        goldFileJson(out.toString());
        attributes.put("invalid", "joe");
        c = instanceService.getInstance("test:child1", ComponentDef.class, attributes);
        serializationService.write(c, null, Component.class, out);
        assertFalse(out.toString().contains("invalid"));
    }
View Full Code Here

    @Override
    public void writeElement(ComponentDef def, Appendable out) throws IOException {
        try {
            Map<String, Object> attributes = Maps.newHashMap();
            attributes.put("def", def);
            InstanceService instanceService = Aura.getInstanceService();
            DefinitionService definitionService = Aura.getDefinitionService();
            DefDescriptor<ComponentDef> tmplDesc = definitionService.getDefDescriptor("auradev:saveComponent",
                    ComponentDef.class);
            Component tmpl = instanceService.getInstance(tmplDesc, attributes);
            Aura.getRenderingService().render(tmpl, out);
        } catch (QuickFixException x) {
            throw new AuraError(x);
        }
    }
View Full Code Here

    @Override
    public void writeElement(ApplicationDef def, Appendable out) throws IOException {
        try {
            Map<String, Object> attributes = Maps.newHashMap();
            attributes.put("def", def);
            InstanceService instanceService = Aura.getInstanceService();
            DefinitionService definitionService = Aura.getDefinitionService();
            DefDescriptor<ComponentDef> tmplDesc = definitionService.getDefDescriptor("auradev:saveApplication",
                    ComponentDef.class);
            Component tmpl = instanceService.getInstance(tmplDesc, attributes);
            Aura.getRenderingService().render(tmpl, out);
        } catch (QuickFixException x) {
            throw new AuraError(x);
        }
    }
View Full Code Here

            }

            attribs.put(RESOURCE_URLS, sw.toString());

            DefinitionService definitionService = Aura.getDefinitionService();
            InstanceService instanceService = Aura.getInstanceService();
            DefDescriptor<ComponentDef> tmplDesc = definitionService
                    .getDefDescriptor("ui:manifest", ComponentDef.class);
            Component tmpl = instanceService.getInstance(tmplDesc, attribs);
            Aura.getRenderingService().render(tmpl, response.getWriter());
        } catch (Exception e) {
            Aura.getExceptionAdapter().handleException(e);
            // Can't throw exception here: to set manifest OBSOLETE
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
View Full Code Here

TOP

Related Classes of org.auraframework.service.InstanceService

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.