Package org.apache.velocity.context

Examples of org.apache.velocity.context.InternalContextAdapterImpl


        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


                    /*
                     *  init.  be a good citizen and give it an ICA
                     */

                    InternalContextAdapter ica
                            = new InternalContextAdapterImpl(new VelocityContext());

                    ica.pushCurrentTemplateName("VMProxyArg : "
                            + ParserTreeConstants.jjtNodeName[type]);

                    nodeTree.init(ica, rsvc);
                }
                catch ( Exception e )
View Full Code Here

                          String logTag, SimpleNode nodeTree)
    {
        /*
         * we want to init then render
         */
        InternalContextAdapterImpl ica =
            new InternalContextAdapterImpl(context);

        ica.pushCurrentTemplateName(logTag);

        try
        {
            try
            {
                nodeTree.init(ica, this);
            }
            catch (TemplateInitException pex)
            {
                throw new ParseErrorException(pex, null);
            }
            /**
             * pass through application level runtime exceptions
             */
            catch(RuntimeException e)
            {
                throw e;
            }
            catch(Exception e)
            {
                String msg = "RuntimeInstance.render(): init exception for tag = "+logTag;
                getLog().error(msg, e);
                throw new VelocityException(msg, e);
            }

            try
            {
                if (provideEvaluateScope)
                {
                    Object previous = ica.get(evaluateScopeName);
                    context.put(evaluateScopeName, new Scope(this, previous));
                }
                nodeTree.render(ica, writer);
            }
            catch (StopCommand stop)
            {
                if (!stop.isFor(this))
                {
                    throw stop;
                }
                else if (getLog().isDebugEnabled())
                {
                    getLog().debug(stop.getMessage());
                }
            }
            catch (IOException e)
            {
                throw new VelocityException("IO Error in writer: " + e.getMessage(), e);
            }
        }
        finally
        {
            ica.popCurrentTemplateName();
            if (provideEvaluateScope)
            {
                Object obj = ica.get(evaluateScopeName);
                if (obj instanceof Scope)
                {
                    Scope scope = (Scope)obj;
                    if (scope.getParent() != null)
                    {
                        ica.put(evaluateScopeName, scope.getParent());
                    }
                    else if (scope.getReplaced() != null)
                    {
                        ica.put(evaluateScopeName, scope.getReplaced());
                    }
                    else
                    {
                        ica.remove(evaluateScopeName);
                    }
                }
            }
        }

View Full Code Here

        VelocityContext base = new VelocityContext();
        base.put("outsideVar", "value1");

        ProxyVMContext vm =
            new ProxyVMContext(new InternalContextAdapterImpl(base), instance, true);
        vm.put("newLocalVar", "value2");

        // New variable put doesn't leak
        assertNull(base.get("newLocalVar"));
        assertEquals("value2", vm.get("newLocalVar"));
View Full Code Here

        instance.init();

        VelocityContext base = new VelocityContext();
        base.put("outsideVar", "value1");

        EvaluateContext evc = new EvaluateContext(new InternalContextAdapterImpl(base), instance);
        evc.put("newLocalVar", "value2");

        // New variable put doesn't leak
        assertNull(base.get("newLocalVar"));
        assertEquals("value2", evc.get("newLocalVar"));
View Full Code Here

        instance.setProperty(RuntimeConstants.EVALUATE_CONTEXT_CLASS, TestContext.class.getName());
        instance.init();

        VelocityContext base = new VelocityContext();
        base.put("outsideVar", "value1");
        EvaluateContext evc = new EvaluateContext(new InternalContextAdapterImpl(base), instance);

        // original entry
        assertEquals(1,evc.getKeys().length);
       
        // original plus local entry
View Full Code Here

        {
            // initialize with bad class name
            RuntimeInstance instance = new RuntimeInstance();
            instance.setProperty(RuntimeConstants.EVALUATE_CONTEXT_CLASS, "org.apache");
            instance.init();
            EvaluateContext evc = new EvaluateContext(new InternalContextAdapterImpl(base), instance);
            fail ("Expected an exception");
        }
        catch (Exception e) {}
       
        try
        {
            // initialize with class not implementing Context
            RuntimeInstance instance = new RuntimeInstance();
            instance.setProperty(RuntimeConstants.EVALUATE_CONTEXT_CLASS, org.apache.velocity.test.EvaluateContextTestCase.class.getName());
            instance.init();
            EvaluateContext evc = new EvaluateContext(new InternalContextAdapterImpl(base), instance);
            fail ("Expected an exception");
        }
        catch (Exception e) {}
    }      
View Full Code Here

        instance.init();

        VelocityContext base = new VelocityContext();
        base.put("outsideVar", "value1");

        EvaluateContext evc = new EvaluateContext(new InternalContextAdapterImpl(base), instance);
        evc.put("newLocalVar", "value2");

        // New variable put doesn't leak
        assertNull(base.get("newLocalVar"));
        assertEquals("value2", evc.get("newLocalVar"));
View Full Code Here

        instance.setProperty(RuntimeConstants.EVALUATE_CONTEXT_CLASS, TestContext.class.getName());
        instance.init();

        VelocityContext base = new VelocityContext();
        base.put("outsideVar", "value1");
        EvaluateContext evc = new EvaluateContext(new InternalContextAdapterImpl(base), instance);

        // original entry
        assertEquals(1,evc.getKeys().length);
       
        // original plus local entry
View Full Code Here

        {
            // initialize with bad class name
            RuntimeInstance instance = new RuntimeInstance();
            instance.setProperty(RuntimeConstants.EVALUATE_CONTEXT_CLASS, "org.apache");
            instance.init();
            EvaluateContext evc = new EvaluateContext(new InternalContextAdapterImpl(base), instance);
            fail ("Expected an exception");
        }
        catch (Exception e) {}
       
        try
        {
            // initialize with class not implementing Context
            RuntimeInstance instance = new RuntimeInstance();
            instance.setProperty(RuntimeConstants.EVALUATE_CONTEXT_CLASS, org.apache.velocity.test.EvaluateContextTestCase.class.getName());
            instance.init();
            EvaluateContext evc = new EvaluateContext(new InternalContextAdapterImpl(base), instance);
            fail ("Expected an exception");
        }
        catch (Exception e) {}
    }      
View Full Code Here

TOP

Related Classes of org.apache.velocity.context.InternalContextAdapterImpl

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.