Class Foreach

    • Field Detail

      • uberInfo

        protected Info uberInfo
        immutable, so create in init
    • Constructor Detail

      • Foreach

        public Foreach()
    • Method Detail

      • getName

        public java.lang.String getName()
        Return name of this directive.
        Specified by:
        getName in class Directive
        Returns:
        The name of this directive.
      • getType

        public int getType()
        Return type of this directive.
        Specified by:
        getType in class Directive
        Returns:
        The type of this directive.
      • put

        protected void put​(InternalContextAdapter context,
                           java.lang.String key,
                           java.lang.Object value)
        Extension hook to allow subclasses to control whether loop vars are set locally or not. So, those in favor of VELOCITY-285, can make that happen easily by overriding this and having it use context.localPut(k,v). See VELOCITY-630 for more on this.
        Parameters:
        context -
        key -
        value -
      • getIterator

        protected java.util.Iterator getIterator​(java.lang.Object iterable,
                                                 Node node)
        Retrieve the contextual iterator.
        Parameters:
        iterable -
        node -
        Returns:
        iterator
      • render

        public boolean render​(InternalContextAdapter context,
                              java.io.Writer writer,
                              Node node)
                       throws java.io.IOException
        renders the #foreach() block
        Specified by:
        render in class Directive
        Parameters:
        context -
        writer -
        node -
        Returns:
        True if the directive rendered successfully.
        Throws:
        java.io.IOException
      • renderBlock

        protected void renderBlock​(InternalContextAdapter context,
                                   java.io.Writer writer,
                                   Node block)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • checkArgs

        public void checkArgs​(java.util.ArrayList<java.lang.Integer> argtypes,
                              Token t,
                              java.lang.String templateName)
                       throws ParseException
        We do not allow a word token in any other arg position except for the 2nd since we are looking for the pattern #foreach($foo in $bar).
        Overrides:
        checkArgs in class Directive
        Parameters:
        argtypes - type, Array of argument types of each argument to the directive for example StandardParserTreeConstants.JJTWORD
        t - token of directive
        templateName - the name of the template this directive is referenced in.
        Throws:
        ParseException