Package org.apache.flex.forks.velocity

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


     */
    public void runTest ()
    {
        try
        {
            Template template = RuntimeSingleton.getTemplate
                (getFileName(null, baseFileName, TMPL_FILE_EXT));
           
            assureResultsDirectoryExists(RESULT_DIR);

            /* get the file to write to */
            FileOutputStream fos =
                new FileOutputStream (getFileName(
                    RESULT_DIR, baseFileName, RESULT_FILE_EXT));

            Writer writer = new BufferedWriter(new OutputStreamWriter(fos));

            /* process the template */
            template.merge( context, writer);

            /* close the file */
            writer.flush();
            writer.close();
           
View Full Code Here


                // the result as the outFile.
                writer = new BufferedWriter(new OutputStreamWriter(
                                            new FileOutputStream(outFile),
                                                encoding));
                // get the template to process
                Template template = ve.getTemplate(style);
                template.merge(context, writer);

                log("Output: " + outFile, Project.MSG_INFO );
            }
        }
        catch (JDOMException e)
View Full Code Here

            /*
             * Get the template and the output. Do them backwards.
             * vm_test2 uses a local VM and vm_test1 doesn't
             */

            Template template2 = RuntimeSingleton.getTemplate(
                getFileName(null, "vm_test2", TMPL_FILE_EXT));
           
            Template template1 = RuntimeSingleton.getTemplate(
                getFileName(null, "vm_test1", TMPL_FILE_EXT));
          
            FileOutputStream fos1 =
                new FileOutputStream (
                    getFileName(RESULT_DIR, "vm_test1", RESULT_FILE_EXT));

            FileOutputStream fos2 =
                new FileOutputStream (
                    getFileName(RESULT_DIR, "vm_test2", RESULT_FILE_EXT));

            Writer writer1 = new BufferedWriter(new OutputStreamWriter(fos1));
            Writer writer2 = new BufferedWriter(new OutputStreamWriter(fos2));
           
            /*
             *  put the Vector into the context, and merge both
             */

            VelocityContext context = new VelocityContext();

            template1.merge(context, writer1);
            writer1.flush();
            writer1.close();
           
            template2.merge(context, writer2);
            writer2.flush();
View Full Code Here

            {
                templateFile = "examples/example.vm";
            }               
        

            Template template = null;

            try
            {
                template = RuntimeSingleton.getTemplate(templateFile, encoding);
            }
            catch( ResourceNotFoundException rnfe )
            {
                System.out.println("Test : RNFE : Cannot find template " + templateFile );
            }
            catch( ParseErrorException pee )
            {
                System.out.println("Test : Syntax error in template " + templateFile + ":" + pee );
            }

            /*
             * 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);
                writer.flush();
                writer.close();
            }
        }
View Full Code Here

    /**
     *
     */
    private Source generateWatcherSetupUtil(CompilationUnit compilationUnit, DataBindingInfo dataBindingInfo)
    {
        Template template;

        StandardDefs standardDefs = compilationUnit.getStandardDefs();
        String templatePath = TEMPLATE_PATH + standardDefs.getWatcherSetupUtilTemplate();

        try
        {
            template = VelocityManager.getTemplate(templatePath);
        }
        catch (Exception exception)
        {
            ThreadLocalToolkit.log(new VelocityException.TemplateNotFound(templatePath));
            return null;
        }

        String className = dataBindingInfo.getWatcherSetupUtilClassName();
        String shortName = className.substring(className.lastIndexOf(DOT) + 1);

        String generatedName = className.replace('.', File.separatorChar) + DOT_AS;

        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(),
                                                                           e.getLocalizedMessage()));
View Full Code Here

  {
    // assumption, this class and templates are found from same classloader, should be cool for now
    InputStream is = SerializedTemplateFactory.class.getClassLoader().getResourceAsStream(resourcePath);
    Object data = new ObjectInputStream(new BufferedInputStream(is)).readObject();   
    is.close();
    Template t = new Template();
    t.setData(data);
    return t;
  }
View Full Code Here

    Velocity.init();
   
    for(int i=0,j=args.length; i<j; i++)
    {
      String serName = args[i] + "s";
          Template template = Velocity.getTemplate(args[i]);
 
          try {
            FileOutputStream fos = new FileOutputStream(serName);
            ObjectOutputStream ooo = new ObjectOutputStream(fos);
            Object data = template.getData();
            ooo.writeObject(data);
            ooo.close();
            fos.close();
          } catch(NotSerializableException nse) {
            System.err.println("Make sure you are using the special velocity in flex/sdk/lib.");
View Full Code Here

TOP

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

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.