Package org.apache.velocity.runtime.parser.node

Examples of org.apache.velocity.runtime.parser.node.Node


  void closeNodeScope(Node n, boolean condition) {
    if (condition) {
      int a = nodeArity();
      mk = ((Integer)marks.pop()).intValue();
      while (a-- > 0) {
  Node c = popNode();
  c.jjtSetParent(n);
  n.jjtAddChild(c, a);
      }
      n.jjtClose();
      pushNode(n);
      node_created = true;
View Full Code Here


            // return value is really meaningless in Velocity...whatever
            return false;
        }

        // BLOCK is the last child
        Node block = node.jjtGetChild(node.jjtGetNumChildren() - 1);
        block.render(context, writer);
        return true;
    }
View Full Code Here

        if (size == 0) {
            return true;
        }

        // BLOCK is the last child
        Node block = node.jjtGetChild(node.jjtGetNumChildren() - 1);
        String join = (size > 1) ? (String) node.jjtGetChild(0).value(context) : "";
        String prefix = (size > 2) ? (String) node.jjtGetChild(1).value(context) : "";

        // if there is a conditional prefix, use a separate buffer ofr children
        StringWriter childWriter = new StringWriter(30);

        int len = block.jjtGetNumChildren();
        int includedChunks = 0;
        for (int i = 0; i < len; i++) {
            Node child = block.jjtGetChild(i);

            // if this is a "chunk", evaluate its expression and prepend join if included...
            if (child instanceof ASTDirective
                && "chunk".equals(((ASTDirective) child).getDirectiveName())) {

                if (child.jjtGetNumChildren() < 2
                    || child.jjtGetChild(0).evaluate(context)) {

                    if (includedChunks > 0) {
                        childWriter.write(join);
                    }

                    includedChunks++;
                }
            }

            child.render(context, childWriter);
        }

        if (includedChunks > 0) {
            childWriter.flush();
            writer.write(prefix);
View Full Code Here

        if (size == 0) {
            return true;
        }

        // BLOCK is the last child
        Node block = node.jjtGetChild(node.jjtGetNumChildren() - 1);
        String join = (size > 1) ? (String) node.jjtGetChild(0).value(context) : "";
        String prefix = (size > 2) ? (String) node.jjtGetChild(1).value(context) : "";

        // if there is a conditional prefix, use a separate buffer ofr children
        StringWriter childWriter = new StringWriter(30);

        int len = block.jjtGetNumChildren();
        int includedChunks = 0;
        for (int i = 0; i < len; i++) {
            Node child = block.jjtGetChild(i);

            // if this is a "chunk", evaluate its expression and prepend join if included...
            if (child instanceof ASTDirective
                && "chunk".equals(((ASTDirective) child).getDirectiveName())) {

                if (child.jjtGetNumChildren() < 2
                    || child.jjtGetChild(0).evaluate(context)) {

                    if (includedChunks > 0) {
                        childWriter.write(join);
                    }

                    includedChunks++;
                }
            }

            child.render(context, childWriter);
        }

        if (includedChunks > 0) {
            childWriter.flush();
            writer.write(prefix);
View Full Code Here

            // return value is really meaningless in Velocity...whatever
            return false;
        }

        // BLOCK is the last child
        Node block = node.jjtGetChild(node.jjtGetNumChildren() - 1);
        block.render(context, writer);
        return true;
    }
View Full Code Here

        if (size == 0) {
            return true;
        }

        // BLOCK is the last child
        Node block = node.jjtGetChild(node.jjtGetNumChildren() - 1);
        String join = (size > 1) ? (String) node.jjtGetChild(0).value(context) : "";
        String prefix = (size > 2) ? (String) node.jjtGetChild(1).value(context) : "";

        // if there is a conditional prefix, use a separate buffer ofr children
        StringWriter childWriter = new StringWriter(30);

        int len = block.jjtGetNumChildren();
        int includedChunks = 0;
        for (int i = 0; i < len; i++) {
            Node child = block.jjtGetChild(i);

            // if this is a "chunk", evaluate its expression and prepend join if included...
            if (child instanceof ASTDirective
                && "chunk".equals(((ASTDirective) child).getDirectiveName())) {

                if (child.jjtGetNumChildren() < 2
                    || child.jjtGetChild(0).evaluate(context)) {

                    if (includedChunks > 0) {
                        childWriter.write(join);
                    }

                    includedChunks++;
                }
            }

            child.render(context, childWriter);
        }

        if (includedChunks > 0) {
            childWriter.flush();
            writer.write(prefix);
View Full Code Here

        if (o != null)
        {
            return o;
        }

        Node astNode = (Node) vmproxyhash.get(key);

        if (astNode != null)
        {
            int type = astNode.getType();

            // if the macro argument (astNode) is a reference, we need to evaluate it
            // in case it is a multilevel node
            if (type == ParserTreeConstants.JJTREFERENCE)
            {
                ASTReference ref = (ASTReference) astNode;

                if (ref.jjtGetNumChildren() > 0)
                {
                    return ref.execute(null, innerContext);
                }
                else
                {
                    Object obj = innerContext.get(ref.getRootString());
                    if (obj == null && ref.strictRef)
                    {
                        if (!innerContext.containsKey(ref.getRootString()))
                        {
                            throw new MethodInvocationException("Parameter '" + ref.getRootString()
                                + "' not defined", null, key, ref.getTemplateName(),
                                ref.getLine(), ref.getColumn());
                        }
                    }
                    return obj;
                }
            }
            else if (type == ParserTreeConstants.JJTTEXT)
            {
                // this really shouldn't happen. text is just a throwaway arg for #foreach()
                try
                {
                    StringWriter writer = new StringWriter();
                    astNode.render(innerContext, writer);
                    return writer.toString();
                }
                catch (RuntimeException e)
                {
                    throw e;
                }
                catch (Exception e)
                {
                    String msg = "ProxyVMContext.get() : error rendering reference";
                    rsvc.getLog().error(msg, e);
                    throw new VelocityException(msg, e);
                }
            }
            else
            {
                // use value method to render other dynamic nodes
                return astNode.value(innerContext);
            }
        }

        return super.get(key);
    }
View Full Code Here

        {
            /*
             *  we only handle StringLiterals and References right now
             */

            Node n = node.jjtGetChild(i);

            if ( n.getType() ==  ParserTreeConstants.JJTSTRINGLITERAL ||
                 n.getType() ==  ParserTreeConstants.JJTREFERENCE )
            {
                if (!renderOutput( n, context, writer ))
                    outputErrorToStream( writer, "error with arg " + i
                        + " please see log.");
            }
            else
            {
                String msg = "invalid #include() argument '"
                  + n.toString() + "' at " + Log.formatFileString(this);
                rsvc.getLog().error(msg);
                outputErrorToStream( writer, "error with arg " + i
                    + " please see log.");
                throw new VelocityException(msg);
            }
View Full Code Here

               
        // Validate that none of the arguments are plain words, (VELOCITY-614)
        // they should be string literals, references, inline maps, or inline lists
        for (int n=0; n < node.jjtGetNumChildren(); n++)
        {
            Node child = node.jjtGetChild(n);
            if (child.getType() == ParserTreeConstants.JJTWORD)
            {
                badArgsErrorMsg = "Invalid arg '" + child.getFirstToken().image
                + "' in macro #" + macroName + " at " + Log.formatFileString(child);
             
                if (strictRef// If strict, throw now
                {
                    /* indicate col/line assuming it starts at 0
View Full Code Here

        synchronized (this)
        {
            try
            {
                Node macroRootNode = rsvc.parse(new StringReader(macroBody), sourceTemplate);

                vmManager.addVM(name, macroRootNode, argArray, sourceTemplate, replaceAllowed);
            }
            catch (ParseException ex)
            {
View Full Code Here

TOP

Related Classes of org.apache.velocity.runtime.parser.node.Node

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.