Package org.auraframework.system

Examples of org.auraframework.system.AuraContext


    }

    @Override
    public void writeCollection(Collection<? extends ControllerDef> values, Appendable out) throws IOException,
            QuickFixException {
        AuraContext context = Aura.getContextService().getCurrentContext();
        Json.serialize(values, out, context.getJsonSerializationContext());
    }
View Full Code Here


    }

    @Override
    public String getHTML5ShivURL() {
        String ret = null;
        AuraContext context = Aura.getContextService().getCurrentContext();
        String ua = context != null ? context.getClient().getUserAgent() : null;
        BrowserInfo b = new BrowserInfo(ua);
        if (b.isIE7() || b.isIE8()) {
            String nonce = context.getFrameworkUID();
            String contextPath = context.getContextPath();
            ret = String.format("%s/auraFW/resources/%s/html5shiv/html5shiv.js", contextPath, nonce);
        }

        return ret;
    }
View Full Code Here

    }

    @Override
    public void writeCollection(Collection<? extends LibraryDef> values, Appendable out) throws IOException,
            QuickFixException {
        AuraContext context = Aura.getContextService().getCurrentContext();
        Json.serialize(values, out, context.getJsonSerializationContext());
    }
View Full Code Here

@Provider
public class IfProvider implements ComponentConfigProvider {

    @Override
    public ComponentConfig provide() throws QuickFixException {
        AuraContext context = Aura.getContextService().getCurrentContext();
        BaseComponent<?, ?> component = context.getCurrentComponent();
        InstanceStack iStack = context.getInstanceStack();
        ComponentConfig cc = new ComponentConfig();
        List<Component> components = new ArrayList<Component>();
        Map<String, Object> m = Maps.newHashMapWithExpectedSize(1);
        m.put("body", components);
        cc.setAttributes(m);
View Full Code Here

    }

    @Override
    public void write(Object value, Map<String, Object> attributes, Appendable out) throws IOException {
        Message message = (Message) value;
        AuraContext c = Aura.getContextService().getCurrentContext();
        Map<String, Object> m = new HashMap<String, Object>();
        if (attributes != null) {
            m.putAll(attributes);
        }

        m.put("actions", message.getActions());
        m.put("context", c);
        Json.serialize(m, out, c.getJsonSerializationContext());
    }
View Full Code Here

    // FIXME - move to builder
    @Override
    protected void injectComponent() throws QuickFixException {
        if (this.intfDescriptor != null) {
            AuraContext context = Aura.getContextService().getCurrentContext();
            context.pushCallingDescriptor(descriptor);
            BaseComponent<?, ?> oldComponent = context.setCurrentComponent(new ProtoComponentImpl(descriptor,
                    getGlobalId(), attributeSet));
            try {
                RootDefinition root = intfDescriptor.getDef();
                ProviderDef providerDef = root.getLocalProviderDef();
                if (providerDef == null) {
                    providerDef = root.getProviderDef();
                    if (providerDef != null) {
                        // In this case, we have a 'remote' provider (i.e. client side) and we simply
                        // continue on as if nothing happened.
                    } else {
                      throw new InvalidDefinitionException(String.format("%s cannot be instantiated directly.",
                            descriptor), root.getLocation());
                    }
                }

                if (providerDef.isLocal()) {
                    ComponentConfig config = providerDef.provide(intfDescriptor);
                    if (config != null) {
                        ProviderDef remoteProviderDef = root.getProviderDef();
                        if (remoteProviderDef == null || remoteProviderDef.isLocal()) {
                            hasLocalDependencies = true;
                        }

                        DefDescriptor<ComponentDef> d = config.getDescriptor();
                        if (d != null) {
                            descriptor = d;
                        }

                        try {
                            if (descriptor.getDefType() != DefType.COMPONENT) {
                                throw new AuraRuntimeException(String.format("%s is not a component", descriptor));
                            }

                            ComponentDef c = descriptor.getDef();
                            if (c.isAbstract()) {
                                throw new AuraRuntimeException(String.format("%s cannot be instantiated directly.",
                                        descriptor));
                            }
                           
                            // new component may have its own controllerdef so add that one
                            ControllerDef cd = c.getControllerDef();
                            if (cd != null) {
                                this.valueProviders.put(ValueProviderType.CONTROLLER.getPrefix(), cd);
                            }
                        } catch (DefinitionNotFoundException dnfe) {
                            throw new AuraRuntimeException(String.format("%s did not provide a valid component",
                                    providerDef.getDescriptor()), dnfe);
                        }

                        attributeSet.setRootDefDescriptor(descriptor);

                        Map<String, Object> providedAttributes = config.getAttributes();
                        if (providedAttributes != null) {
                            // if there is a remote provider and attributes were
                            // set, we assume/pray the remote provider does too
                            hasProvidedAttributes = true;
                            attributeSet.startTrackingDirtyValues();
                            attributeSet.set(providedAttributes);
                        }
                    }

                } else {
                    remoteProvider = true;
                }

            } finally {
                context.popCallingDescriptor();
                context.setCurrentComponent(oldComponent);
            }
        }
    }
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();
View Full Code Here

        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();
            }
View Full Code Here

       
        if (!event.getEventType().canBeFired()) {
            throw new InvalidDefinitionException("Cannot fire event of type: " + getEventDescriptor(), getLocation());
        }
       
        AuraContext context = Aura.getContextService().getCurrentContext();
        DefDescriptor<?> referencingDesc = context.getCurrentCallingDescriptor();
      if (referencingDesc != null) {
          MasterDefRegistry registry = Aura.getDefinitionService().getDefRegistry();
        registry.assertAccess(referencingDesc, event);
      }       
    }
View Full Code Here

    @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

TOP

Related Classes of org.auraframework.system.AuraContext

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.