public DomWalker(DomExtensionFactory domExtensionFactory, InjectionClassBuilder classBuilder, ElementDescriptorFactory elementDescriptorFactory, StyleExtensionManager styleExtensionManager, LocalizationProvider localizationProvider)
 {
     this.domExtensionFactory = domExtensionFactory;
     this.elementDescriptorFactory = elementDescriptorFactory;
     this.styleExtensionManager = styleExtensionManager;
     this.localizationProvider = localizationProvider;
     this.classBuilder = classBuilder;
 }
Esempio n. 2
0
        public void walkChildren(Node parentNode, InjectionClassBuilder classBuilder, AbstractBehavior parentBehavior = null)
        {
            var node = parentNode.firstChild;

            while (node != null) {
                investigateNode(node, classBuilder, parentBehavior);
                node = node.nextSibling;
            }
        }
Esempio n. 3
0
        public InjectionClassBuilder buildChildClassBuilder(InjectionClassBuilder classBuilder, HtmlElement element, JsString contextClassName)
        {
            var module = (GuiceModule)classBuilder.buildClass(contextClassName);
            var injector = (ChildInjector)classBuilder.buildClass("guice.ChildInjector");
            var guiceJs = new GuiceJs();
            guiceJs.configureInjector(injector, module);

            //Setup a new InjectionClassBuilder
            return (InjectionClassBuilder)injector.getInstance(typeof(InjectionClassBuilder));
        }
Esempio n. 4
0
        private void investigateDomElement(HtmlElement element, InjectionClassBuilder classBuilder, AbstractBehavior parentBehavior)
        {
            var currentBehavior = parentBehavior;

            var id = element.getAttribute("id");

            if (id != null) {
                //we have a reference to the element now, so remove the id so we dont have to deal with conflicts and clashes
                element.removeAttribute("id");
            }

            var elementDescriptor = elementDescriptorFactory.describeElement( element );

            if (elementDescriptor.context != null) {
                //change the class builder for everything under this point in the DOM
                classBuilder = domExtensionFactory.buildChildClassBuilder(classBuilder, element, elementDescriptor.context);
            }

            if (elementDescriptor.behavior != null) {
                //build a context for this behavior IF it turns out that this particular element defines one
                currentBehavior = domExtensionFactory.buildBehavior( classBuilder, element, elementDescriptor.behavior );

                //we have a new behavior, this effectively causes us to use a new context for the nodes below it
                //Make sure we add ourselves to our parent though
                if (id != null && parentBehavior != null) {
                    parentBehavior.injectPotentialNode(id, currentBehavior);
                }
            } else {
                if (id != null && currentBehavior != null) {
                    currentBehavior.injectPotentialNode(id, jQueryContext.J(element));
                }
            }

            if (elementDescriptor.fragment != null) {
                //build a context for this behavior IF it turns out that this particular element defines one
                domExtensionFactory.buildNewContent(element, elementDescriptor.fragment);
            }

            walkChildren(element, classBuilder, currentBehavior);

            //Now that we have figured out all of the items under this dom element, setup the behavior
            if (currentBehavior != null && currentBehavior != parentBehavior) {
                currentBehavior.verifyAndRegister();
            }
        }
        public AbstractBehavior buildBehavior(InjectionClassBuilder classBuilder, HtmlElement element, JsString behaviorClassName )
        {
            AbstractBehavior behavior = null;

            var resolution = classResolver.resolveClassName(behaviorClassName);

            if ( resolution.builtIn ) {
                /** If we have a type which was not created via Randori, we send it out to get created. In this way
                 * we dont worry about injection data and we allow for any crazy creation mechanism the client can
                 * consider **/
                behavior = externalBehaviorFactory.createExternalBehavior(element, behaviorClassName, resolution.type);
            } else {
                behavior = (AbstractBehavior)classBuilder.buildClass(behaviorClassName);
                behavior.provideDecoratedElement(element);
            }

            return behavior;
        }
Esempio n. 6
0
 public AbstractBehavior buildBehavior(InjectionClassBuilder classBuilder, HtmlElement element, JsString behaviorClassName )
 {
     var behavior = (AbstractBehavior)classBuilder.buildClass(behaviorClassName);
     behavior.provideDecoratedElement(element);
     return behavior;
 }
Esempio n. 7
0
 public void walkDomFragment(Node node, InjectionClassBuilder classBuilder, AbstractBehavior parentBehavior = null)
 {
     investigateNode(node, classBuilder, parentBehavior);
 }
Esempio n. 8
0
        private void investigateNode(Node node, InjectionClassBuilder classBuilder, AbstractBehavior parentBehavior)
        {
            if (node.nodeType == Node.ELEMENT_NODE) {

                //Just an optimization, need to create constants for all of these things
                if (node.nodeName == "SCRIPT" || node.nodeName == "META") {
                    return;
                }

                if ( node.nodeName == "LINK" ) {
                    investigateLinkElement(node.As<HtmlLinkElement>());
                } else {
                    investigateDomElement(node.As<HtmlElement>(), classBuilder, parentBehavior);
                }

            } else if (node.nodeType == Node.TEXT_NODE) {
                //This is a text node, check to see if it needs internationalization
                localizationProvider.investigateTextNode(node);
            } else {
                walkChildren(node, classBuilder, parentBehavior);
            }
        }
Esempio n. 9
0
 public TemplateRenderer(InjectionClassBuilder classBuilder, DomWalker domWalker, TemplateBuilder templateBuilder)
 {
     this.domWalker = domWalker;
     this.classBuilder = classBuilder;
     this.templateBuilder = templateBuilder;
 }