Package org.apache.flex.forks.velocity

Examples of org.apache.flex.forks.velocity.VelocityContext


        /*
         *  lets make a Context and add the event cartridge
         */
       
        VelocityContext inner = new VelocityContext();

        /*
         *  Now make an event cartridge, register all the
         *  event handlers (at once) and attach it to the
         *  Context
         */

        EventCartridge ec = new EventCartridge();
        ec.addEventHandler(this);
        ec.attachToContext( inner );
 
        /*
         *  now wrap the event cartridge - we want to make sure that
         *  we can do this w/o harm
         */

        VelocityContext context = new VelocityContext( inner );

        context.put("name", "Velocity");

        try
        {
            /*
             *  First, the reference insertion handler
             */

            String s = "$name";
           
            StringWriter w = new StringWriter();
            Velocity.evaluate( context, w, "mystring", s );
           
            if ( !w.toString().equals( REFERENCE_VALUE ))
            {
                fail( "Reference insertion test 1");
            }

            /*
             *  using the same handler, we can deal with
             *  null references as well
             */

            s = "$floobie";

            w = new StringWriter();
            Velocity.evaluate( context, w, "mystring", s );

            if ( !w.toString().equals( NO_REFERENCE_VALUE ))
            {
                fail( "Reference insertion test 2");
            }

            /*
             *  now lets test setting a null value - this test
             *  should result in *no* log output.
             */
                
            s = "#set($settest = $NotAReference)";
            w = new StringWriter();
            logString = null;
            Velocity.evaluate( context, w, "mystring", s );
           
            if( logString != null)
            {
                fail( "NullSetEventHandler test 1");
            }
           
            /*
             *  now lets test setting a null value - this test
             *  should result in log output.
             */

            s = "#set($logthis = $NotAReference)";
            w = new StringWriter();
            logString = null;          
            Velocity.evaluate( context, w, "mystring", s );
          
            if( logString == null)
            {
                fail( "NullSetEventHandler test 1");
            }

            /*
             *  finally, we test a method exception event - we do this
             *  by putting this class in the context, and calling
             *  a method that does nothing but throw an exception.
             *  we use a little switch to turn the event handling
             *  on and off
             *
             *  Note also how the reference insertion process
             *  happens as well
             */
           
            exceptionSwitch = true;

            context.put("this", this );

            s = " $this.throwException()";
            w = new StringWriter();
           
            try
View Full Code Here


    /**
     * Runs the test.
     */
    public void runTest ()
    {
        VelocityContext context = new VelocityContext();

        try
        {
            StringWriter writer = new StringWriter();
            Velocity.evaluate(context, writer, "vm_chain1", template1);
View Full Code Here

            /*
             * now, make a Context object and populate it.
             */

            VelocityContext context = new VelocityContext();

            context.put("provider", provider);
            context.put("name", "jason");
            context.put("providers", provider.getCustomers2());
            context.put("list", al);
            context.put("hashtable", h);
            context.put("search", provider.getSearch());
            context.put("relatedSearches", provider.getRelSearches());
            context.put("searchResults", provider.getRelSearches());
            context.put("menu", provider.getMenu());
            context.put("stringarray", provider.getArray());
            context.put("vector", v);
            context.put("mystring", new String());
            context.put("hashmap", new HashMap() );
            context.put("runtime", new FieldMethodizer( "org.apache.flex.forks.velocity.runtime.RuntimeSingleton" ));
            context.put("fmprov", new FieldMethodizer( provider ));
            context.put("Floog", "floogie woogie");
            context.put("geirstring", str );
            context.put("mylong", new Long(5) );
           
            /*
             *  we want to make sure we test all types of iterative objects
             *  in #foreach()
             */
            
            int intarr[] = { 10, 20, 30, 40, 50 };

            Object[] oarr = { "a","b","c","d" } ;
           
            context.put( "collection", v );
            context.put("iterator", v.iterator());
            context.put("map", h );
            context.put("obarr", oarr );
            context.put("intarr", intarr );
           
            String stest = " My name is $name -> $Floog";
            StringWriter w = new StringWriter();
            //            Velocity.evaluate( context, w, "evaltest",stest );
            //            System.out.println("Eval = " + w );

            w = new StringWriter();
            //Velocity.mergeTemplate( "mergethis.vm",  context, w );
            //System.out.println("Merge = " + w );

            w = new StringWriter();
            //Velocity.invokeVelocimacro( "floog", "test", new String[2],  context,  w );
            //System.out.println("Invoke = " + w );


            /*
             *  event cartridge stuff
             */

            EventCartridge ec = new EventCartridge();
            ec.addEventHandler(this);
            ec.attachToContext( context );

            /*
             *  make a writer, and merge the template 'against' the context
             */

            VelocityContext vc = new VelocityContext( context );

            if( template != null)
            {
                writer = new BufferedWriter(new OutputStreamWriter(System.out, encoding));
                template.merge( vc , writer);
View Full Code Here

        SourceCodeBuffer out = new SourceCodeBuffer();

        try
        {
            VelocityUtil util = new VelocityUtil(TEMPLATE_PATH, false, out, null);
            VelocityContext velocityContext = VelocityManager.getCodeGenContext(util);
            velocityContext.put(DATA_BINDING_INFO_KEY, dataBindingInfo);
            template.merge(velocityContext, out);
        }
        catch (Exception e)
        {
            ThreadLocalToolkit.log(new VelocityException.GenerateException(compilationUnit.getSource().getRelativePath(),
View Full Code Here

TOP

Related Classes of org.apache.flex.forks.velocity.VelocityContext

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.