Package com.google.sitebricks.rendering.control

Examples of com.google.sitebricks.rendering.control.WidgetChain


        PageCompilingContext pc = new PageCompilingContext();
        pc.page = page;
        pc.template = template;
        pc.lexicalScopes.push(new MvelEvaluatorCompiler(page));
     
        WidgetChain widgetChain;
        widgetChain = walk(pc, HtmlParser.parse(template.getText()));

        // TODO - get the errors when !(isValid)
        if (!pc.errors.isEmpty() || !pc.warnings.isEmpty()) {
            // If there were any errors we must track them.
View Full Code Here


      return widgetChain;
    }

    private WidgetChain walk(PageCompilingContext pc, List<Node> nodes) {
        WidgetChain chain = Chains.proceeding();

        for (Node n: nodes)
            chain.addWidget(widgetize(pc, n, walk(pc, n)));

        return chain;
    }
View Full Code Here

    /**
     * Walks the DOM recursively, and converts elements into corresponding sitebricks widgets.
     */
    @NotNull
    private <N extends Node> WidgetChain walk(PageCompilingContext pc, N node) {
        WidgetChain widgetChain = Chains.proceeding();
        for (Node n: node.childNodes()) {
            if (n instanceof Element) {
                final Element child = (Element) n;

                //push form if this is a form tag
                if (child.tagName().equals("form"))
                    pc.form = (Element) n;

                //setup a lexical scope if we're going into a repeat widget (by reading the previous node)
                final boolean shouldPopScope = lexicalClimb(pc, child);

                //continue recursing down, perform a post-order, depth-first traversal of the DOM
                WidgetChain childsChildren;
                try {
                    childsChildren = walk(pc, child);

                    //process the widget itself into a Renderable with child tree
                    widgetChain.addWidget(widgetize(pc, child, childsChildren));
                } finally {
                    lexicalDescend(pc, child, shouldPopScope);
                }

            } else if (n instanceof TextNode) {
              TextNode child = (TextNode)n;
              Renderable textWidget;
             
                //setup a lexical scope if we're going into a repeat widget (by reading the previous node)
                final boolean shouldPopScope = lexicalClimb(pc, child);

                // construct the text widget
                try {
                  textWidget = registry.textWidget(cleanHtml(n), pc.lexicalScopes.peek());
                 
                  // if there are no annotations, add the text widget to the chain
                  if (!child.hasAttr(ANNOTATION_KEY))  {
                    widgetChain.addWidget(textWidget);
                  }
                  else  {
                    // construct a new widget chain for this text node
                    WidgetChain childsChildren = Chains.proceeding().addWidget(textWidget);
                   
                    // make a new widget for the annotation, making the text chain the child
                    String widgetName = child.attr(ANNOTATION_KEY).toLowerCase();
                    Renderable annotationWidget = registry.newWidget(widgetName, child.attr(ANNOTATION_CONTENT), childsChildren, pc.lexicalScopes.peek());
                    widgetChain.addWidget(annotationWidget);
View Full Code Here

        this.lexicalScopes.push(compiler);
    }

    public Renderable compile(String template) {
        WidgetChain widgetChain;
        widgetChain = walk(HtmlParser.parse(template));

        // TODO - get the errors when !(isValid)
        if (!errors.isEmpty() || !warnings.isEmpty()) {
            // If there were any errors we must track them.
View Full Code Here

      return widgetChain;
    }

    private WidgetChain walk(List<Node> nodes) {
        WidgetChain chain = Chains.proceeding();

        for (Node n: nodes)
            chain.addWidget(widgetize(n, walk(n)));

        return chain;
    }
View Full Code Here

     * Walks the DOM recursively, and converts elements into corresponding sitebricks widgets.
     */
    @NotNull
    private <N extends Node> WidgetChain walk(N node) {

        WidgetChain widgetChain = Chains.proceeding();
        for (Node n: node.childNodes()) {
            if (n instanceof Element) {
                final Element child = (Element) n;

                //push form if this is a form tag
                if (child.tagName().equals("form"))
                    form = (Element) n;

                //setup a lexical scope if we're going into a repeat widget (by reading the previous node)
                final boolean shouldPopScope = lexicalClimb(child);

                //continue recursing down, perform a post-order, depth-first traversal of the DOM
                WidgetChain childsChildren;
                try {
                    childsChildren = walk(child);

                    //process the widget itself into a Renderable with child tree
                    widgetChain.addWidget(widgetize(child, childsChildren));
                } finally {
                    lexicalDescend(child, shouldPopScope);
                }

            } else if (n instanceof TextNode) {
              TextNode child = (TextNode)n;
              Renderable textWidget = null;
             
                //setup a lexical scope if we're going into a repeat widget (by reading the previous node)
                final boolean shouldPopScope = lexicalClimb(child);

                // construct the text widget
                try {
                  textWidget = registry.textWidget(cleanHtml(n), lexicalScopes.peek());
                 
                  // if there are no annotations, add the text widget to the chain
                  if (!child.hasAttr(ANNOTATION_KEY))  {
                    widgetChain.addWidget(textWidget);
                  }
                  else  {
                    // construct a new widget chain for this text node
                    WidgetChain childsChildren = Chains.proceeding().addWidget(textWidget);
                   
                    // make a new widget for the annotation, making the text chain the child
                    String widgetName = child.attr(ANNOTATION_KEY).toLowerCase();
                    Renderable annotationWidget = registry.newWidget(widgetName, child.attr(ANNOTATION_CONTENT), childsChildren, lexicalScopes.peek());
                    widgetChain.addWidget(annotationWidget);
View Full Code Here

        this.lexicalScopes.push(compiler);
    }

    public Renderable compile(String template) {
        WidgetChain widgetChain;
        try {
            final SAXReader reader = new SAXReader();
            reader.setMergeAdjacentText(true);
            reader.setXMLFilter(Dom.newLineNumberFilter());
            reader.setValidation(false);
View Full Code Here

        return widgetChain;
    }

    private WidgetChain walk(Document document) {
        WidgetChain chain = Chains.proceeding();
        handleDocType(document, chain);
        final WidgetChain docChain = walk(document.getRootElement());

        chain.addWidget(widgetize(null, document.getRootElement(), docChain));

        return chain;
    }
View Full Code Here

     *  corresponding sitebricks widgets.
     */
    @SuppressWarnings({"JavaDoc"}) @NotNull
    private WidgetChain walk(Element element) {

        WidgetChain widgetChain = Chains.proceeding();

        for (int i = 0, size = element.nodeCount(); i < size; i++) {
            Node node = element.node(i);

            if (Dom.isElement(node)) {
                final Element child = (Element) node;

                //push form if this is a form tag
                if (Dom.isForm(node))
                    form = (Element) node;


                //setup a lexical scope if we're going into a repeat widget (by reading the previous node)
                final boolean shouldPopScope = lexicalClimb(element, i);

                //continue recursing down, perform a post-order, depth-first traversal of the DOM
                WidgetChain childsChildren;
                try {
                    childsChildren = walk(child);

                    //process the widget itself into a Renderable with child tree
                    if (i > 0)
View Full Code Here

TOP

Related Classes of com.google.sitebricks.rendering.control.WidgetChain

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.