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

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


    public boolean evaluate(Context context, Writer writer,
                                    String logTag, Reader reader)
        throws ParseErrorException, MethodInvocationException,
            ResourceNotFoundException,IOException
    {
        SimpleNode nodeTree = null;

        try
        {
            nodeTree = ri.parse(reader, logTag);
        }
        catch (ParseException pex)
        {
            throw  new ParseErrorException( pex );
        }
        catch (TemplateInitException pex)
        {
            throw  new ParseErrorException( pex );
        }

        /*
         * now we want to init and render
         */

        if (nodeTree != null)
        {
            InternalContextAdapterImpl ica =
                new InternalContextAdapterImpl( context );

            ica.pushCurrentTemplateName( logTag );

            try
            {
                try
                {
                    nodeTree.init( ica, ri );
                }
                catch (TemplateInitException pex)
                {
                    throw  new ParseErrorException( pex );
                }
                /**
                 * pass through application level runtime exceptions
                 */
                catch( RuntimeException e )
                {
                    throw e;
                }
                catch(Exception e)
                {
                    getLog().error("Velocity.evaluate() : init exception for tag = "
                                   + logTag, e);
                }

                /*
                 *  now render, and let any exceptions fly
                 */

                nodeTree.render( ica, writer );
            }
            finally
            {
                ica.popCurrentTemplateName();
            }
View Full Code Here


    public static boolean evaluate( Context context, Writer writer,
                                    String logTag, Reader reader )
        throws ParseErrorException, MethodInvocationException,
            ResourceNotFoundException,IOException
    {
        SimpleNode nodeTree = null;

        try
        {
            nodeTree = RuntimeSingleton.parse( reader, logTag );
        }
        catch ( ParseException pex )
        {
            throw  new ParseErrorException( pex );
        }
        catch (TemplateInitException pex)
        {
            throw  new ParseErrorException( pex );
        }

        /*
         * now we want to init and render
         */

        if (nodeTree != null)
        {
            InternalContextAdapterImpl ica =
                new InternalContextAdapterImpl( context );

            ica.pushCurrentTemplateName( logTag );

            try
            {
                try
                {
                    nodeTree.init( ica, RuntimeSingleton.getRuntimeServices() );
                }
                catch (TemplateInitException pex)
                {
                    throw  new ParseErrorException( pex );
                }
                /**
                 * pass through application level runtime exceptions
                 */
                catch( RuntimeException e )
                {
                    throw e;
                }
                catch( Exception e )
                {
                    getLog().error("Velocity.evaluate() : init exception for tag = "+logTag, e);
                }

                /*
                 *  now render, and let any exceptions fly
                 */

                nodeTree.render( ica, writer );
            }
            finally
            {
                ica.popCurrentTemplateName();
            }
View Full Code Here

                getLog().error("Could not auto-initialize Velocity", e);
                throw new IllegalStateException("Velocity could not be initialized!");
            }
        }

        SimpleNode ast = null;
        Parser parser = (Parser) parserPool.get();

        if (parser == null)
        {
            /*
 
View Full Code Here

     * @param String name of the template being parsed
     */
    public static SimpleNode parse(InputStream inputStream, String templateName )
        throws ParseException
    {
        SimpleNode ast = null;
        Parser parser = (Parser) parserPool.get();
       
        if (parser != null)
        {
            try
View Full Code Here

        // Note: this method is a reworked version of
        // org.apache.velocity.app.Velocity.evaluate(..)
        // cleaned up to avoid using any Velocity singletons

        StringWriter out = new StringWriter(template.length());
        SimpleNode nodeTree = null;

        try {
            nodeTree = velocityRuntime.parse(new StringReader(template), template);
        }
        catch (ParseException pex) {
            throw new CayenneRuntimeException("Error parsing template '"
                    + template
                    + "' : "
                    + pex.getMessage());
        }

        if (nodeTree == null) {
            throw new CayenneRuntimeException("Error parsing template " + template);
        }

        // ... not sure what InternalContextAdapter is for...
        InternalContextAdapterImpl ica = new InternalContextAdapterImpl(context);
        ica.pushCurrentTemplateName(template);

        try {
            nodeTree.init(ica, velocityRuntime);
            nodeTree.render(ica, out);
            return out.toString();
        }
        finally {
            ica.popCurrentTemplateName();
        }
View Full Code Here

        // Note: this method is a reworked version of
        // org.apache.velocity.app.Velocity.evaluate(..)
        // cleaned up to avoid using any Velocity singletons

        StringWriter out = new StringWriter(template.length());
        SimpleNode nodeTree = null;

        try {
            nodeTree = velocityRuntime.parse(new StringReader(template), template);
        }
        catch (ParseException pex) {
            throw new CayenneRuntimeException("Error parsing template '"
                    + template
                    + "' : "
                    + pex.getMessage());
        }

        if (nodeTree == null) {
            throw new CayenneRuntimeException("Error parsing template " + template);
        }

        // ... not sure what InternalContextAdapter is for...
        InternalContextAdapterImpl ica = new InternalContextAdapterImpl(context);
        ica.pushCurrentTemplateName(template);

        try {
            nodeTree.init(ica, velocityRuntime);
            nodeTree.render(ica, out);
            return out.toString();
        }
        finally {
            ica.popCurrentTemplateName();
        }
View Full Code Here

               
        /*
         *  this is really the only thing we can do here as everything
         *  else is context sensitive
         */
        SimpleNode sn = (SimpleNode) node.jjtGetChild(0);

        if (sn instanceof ASTReference)
        {
            elementKey = ((ASTReference) sn).getRootString();
        }
        else
        {
            /*
             * the default, error-prone way which we'll remove
             *  TODO : remove if all goes well
             */
            elementKey = sn.getFirstToken().image.substring(1);
        }

        /*
         * make an uberinfo - saves new's later on
         */
 
View Full Code Here

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

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

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

        if (nodeTree != null)
        {
            InternalContextAdapter ica = new EvaluateContext(context, rsvc);

            ica.pushCurrentTemplateName( templateName );

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

                try
                {
                    preRender(ica);

                    /*
                     *  now render, and let any exceptions fly
                     */
                    nodeTree.render( ica, writer );
                }
                catch (StopCommand stop)
                {
                    if (!stop.isFor(this))
                    {
View Full Code Here

        if (logTag == null)
        {
            throw new NullPointerException("logTag (i.e. template name) cannot be null, you must provide an identifier for the content being evaluated");
        }

        SimpleNode nodeTree = null;
        try
        {
            nodeTree = parse(reader, logTag);
        }
        catch (ParseException pex)
View Full Code Here

        // Note: this method is a reworked version of
        // org.apache.velocity.app.Velocity.evaluate(..)
        // cleaned up to avoid using any Velocity singletons

        StringWriter out = new StringWriter(template.length());
        SimpleNode nodeTree = null;

        try {
            nodeTree = velocityRuntime.parse(new StringReader(template), template);
        }
        catch (ParseException pex) {
            throw new ParseErrorException(pex.getMessage());
        }

        if (nodeTree == null) {
            throw new CayenneRuntimeException("Error parsing template " + template);
        }

        // ... not sure what InternalContextAdapter is for...
        InternalContextAdapterImpl ica = new InternalContextAdapterImpl(context);
        ica.pushCurrentTemplateName(template);

        try {
            nodeTree.init(ica, velocityRuntime);
            nodeTree.render(ica, out);
            return out.toString();
        }
        finally {
            ica.popCurrentTemplateName();
        }
View Full Code Here

TOP

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

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.