public boolean render()

in velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Evaluate.java [141:238]


    public boolean render(InternalContextAdapter context, Writer writer,
                          Node node) throws IOException, ResourceNotFoundException,
            ParseErrorException, MethodInvocationException
    {

        /*
         * Evaluate the string with the current context.  We know there is
         * exactly one argument and it is a string or reference.
         */

        Object value = node.jjtGetChild(0).value( context );
        String sourceText;
        if ( value != null )
        {
            sourceText = value.toString();
        }
        else
        {
            sourceText = "";
        }

        /*
         * The new string needs to be parsed since the text has been dynamically generated.
         */
        String templateName = context.getCurrentTemplateName();
        Template template = (Template)context.getCurrentResource();
        if (template == null)
        {
            template = new Template();
            template.setName(templateName);
        }
        SimpleNode nodeTree = null;

        try
        {
            nodeTree = rsvc.parse(new StringReader(sourceText), template);
        }
        catch (ParseException | TemplateInitException pex)
        {
            // use the line/column from the template
            Info info = new Info( templateName, node.getLine(), node.getColumn() );
            throw  new ParseErrorException( pex.getMessage(), info, rsvc.getLogContext().getStackTrace() );
        }

        /*
         * now we want to init and render.  Chain the context
         * to prevent any changes to the current context.
         */

        if (nodeTree != null)
        {
            context.pushCurrentTemplateName(templateName);

            try
            {
                try
                {
                    nodeTree.init(context, rsvc);
                }
                catch (TemplateInitException pex)
                {
                    Info info = new Info( templateName, node.getLine(), node.getColumn() );
                    throw  new ParseErrorException( pex.getMessage(), info, rsvc.getLogContext().getStackTrace() );
                }

                try
                {
                    preRender(context);

                    /*
                     *  now render, and let any exceptions fly
                     */
                    nodeTree.render(context, writer);
                }
                catch (StopCommand stop)
                {
                    if (!stop.isFor(this))
                    {
                        throw stop;
                    }
                }
                catch (ParseErrorException pex)
                {
                    // convert any parsing errors to the correct line/col
                    Info info = new Info( templateName, node.getLine(), node.getColumn() );
                    throw  new ParseErrorException( pex.getMessage(), info, rsvc.getLogContext().getStackTrace() );
                }
            }
            finally
            {
                context.popCurrentTemplateName();
                postRender(context);
            }
            return true;
        }

        return false;
    }