Package org.apache.flex.forks.velocity

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


      String path = source.getName();

      StandardDefs standardDefs = info.getStandardDefs();
      String templateName = TemplatePath + standardDefs.getInterfaceDefTemplate();

    Template template = VelocityManager.getTemplate(templateName);
    if (template != null)
    {
      try
      {
        // create a velocity context
        VelocityContext velocityContext = VelocityManager.getCodeGenContext();

        //  SourceCodeBuffer tracks line number change during codegen
        SourceCodeBuffer out = new SourceCodeBuffer((int) source.size());

        //  create SourceCode wrappers for scripts
        Set<SourceCode> scriptSet = new LinkedHashSet<SourceCode>();
        for (Iterator iter = info.getScripts().iterator(); iter.hasNext(); )
        {
          Script script = (Script) iter.next();
          if (!script.isEmbedded())
          {
            scriptSet.add(new SourceCode(script.getText(), script.getXmlLineNumber(), out, map));
          }
          else
          {
            // use Source.getName() to construct the new VirtualFile name
            String n = source.getName().replace('\\', '/') + ":" + script.getXmlLineNumber() + "," + script.getEndXmlLineNumber();
            VirtualFile f = new TextFile(script.getText(), n, source.getParent(), MimeMappings.AS, source.getLastModified());

                        // line number map is for error reporting, so the names must come from error reporting...
                        LineNumberMap m = new LineNumberMap(source.getNameForReporting(), n);

                        m.put(script.getXmlLineNumber(), 1, (script.getEndXmlLineNumber() - script.getXmlLineNumber()));
                        // C: add this so that when unexpected EOF occurs, (last line + 1) maps to the last line
                        //    in the original XML Script block.
                        m.put(script.getEndXmlLineNumber(), script.getEndXmlLineNumber() - script.getXmlLineNumber() + 1, 1);

                        // 'n' must match 'n' in the include directive...
                        source.addSourceFragment(n, f, m);

                        // 'n' must match 'n' in the addSourceFragment call.
                        scriptSet.add(new SourceCode("include \"" + n + "\";", script.getXmlLineNumber(), out, map));
                    }
                }

                //  create SourceCode wrappers for metadata entries
                Set<SourceCode> metadataSet = new LinkedHashSet<SourceCode>();
                for (Iterator iter = info.getMetadata().iterator(); iter.hasNext(); )
                {
                    Script script = (Script)iter.next();
                    metadataSet.add(new SourceCode(script.getText(), script.getXmlLineNumber(), out, map));
                }

                //  create SourceCode wrappers for variable declarations
                Map<String, SourceCode> varDeclMap = new LinkedHashMap<String, SourceCode>();
                for (Iterator iter = info.getVarDecls().values().iterator(); iter.hasNext(); )
                {
                    DocumentInfo.VarDecl varDecl = (DocumentInfo.VarDecl)iter.next();
                    varDeclMap.put(varDecl.name, new SourceCode(varDecl.className, varDecl.line, out, map));
                }

                int superClassLineNumber = 1;

                Set<SourceCode> importNameSet = new LinkedHashSet<SourceCode>();
                for (Iterator i = info.getImportNames().iterator(); i.hasNext();)
                {
                    DocumentInfo.NameInfo importName = (DocumentInfo.NameInfo) i.next();
                    importNameSet.add(new SourceCode(importName.getName(), importName.getLine(), out, map));

                    if (importName.getName().equals(info.getQualifiedSuperClassName()))
                    {
                        superClassLineNumber = importName.getLine();
                    }
                }
                for (Iterator<String> i = bogusImports.iterator(); i.hasNext();)
                {
                    String importName = i.next();
                    importNameSet.add(new SourceCode(importName, 1, out, map));
                }

                Set<SourceCode> interfaceNameSet = new LinkedHashSet<SourceCode>();
                for (Iterator i = info.getInterfaceNames().iterator(); i.hasNext();)
                {
                    DocumentInfo.NameInfo interfaceName = (DocumentInfo.NameInfo) i.next();
                    interfaceNameSet.add(new SourceCode(interfaceName.getName(), interfaceName.getLine(), out, map));
                }

                // register values
                velocityContext.put("imports", importNameSet);
                velocityContext.put("variables", varDeclMap.entrySet());
                velocityContext.put("scripts", scriptSet);
                velocityContext.put("classMetaData", metadataSet);
                velocityContext.put("bindingManagementVariables", FrameworkDefs.bindingManagementVars);

                // C: should really give line number mappings to superclass name and interface names.
                velocityContext.put("superClassName", new SourceCode(info.getQualifiedSuperClassName(), superClassLineNumber, out, map));
                velocityContext.put("interfaceNames", interfaceNameSet);

                velocityContext.put("className", info.getClassName());
                velocityContext.put("packageName", info.getPackageName());

                // run the template!
                //long s2 = System.currentTimeMillis();
                //VelocityManager.parseTime += s2 - start;
                template.merge(velocityContext, out);
                //VelocityManager.mergeTime += System.currentTimeMillis() - s2;

                // Normalize line endings as a temporary work around for bug 149821
                String generated = out.toString().replaceAll("\r\n", "\n");
                String filename = writeGenerated(info, generated);
View Full Code Here


     */
    public boolean mergeTemplate( String templateName, String encoding,
                                      Context context, Writer writer )
        throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, Exception
    {
        Template template = ri.getTemplate(templateName, encoding);
       
        if ( template == null )
        {
            ri.error("Velocity.parseTemplate() failed loading template '"
                          + templateName + "'" );
            return false;
        }
        else
        {
            template.merge(context, writer);
            return true;
         }
    }
View Full Code Here

     */
    public static boolean mergeTemplate( String templateName, String encoding,
                                      Context context, Writer writer )
        throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, Exception
    {
        Template template = RuntimeSingleton.getTemplate(templateName, encoding);

        if ( template == null )
        {
            RuntimeSingleton.error("Velocity.parseTemplate() failed loading template '"
                          + templateName + "'" );
            return false;
        }
        else
        {
            template.merge(context, writer);
            return true;
         }
    }
View Full Code Here

            /*
             *  Chinese and spanish
             */

            Template template = Velocity.getTemplate(
                getFileName(null, "encodingtest", TMPL_FILE_EXT), "UTF-8");

            FileOutputStream fos =
                new FileOutputStream (
                    getFileName(RESULT_DIR, "encodingtest", RESULT_FILE_EXT));

            Writer writer = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8"));
          
            template.merge(context, writer);
            writer.flush();
            writer.close();
           
            if (!isMatch(RESULT_DIR,COMPARE_DIR,"encodingtest",
                    RESULT_FILE_EXT,CMP_FILE_EXT) )
            {
                fail("Output 1 incorrect.");
            }

            /*
             *  a 'high-byte' chinese example from Michael Zhou
             */

            template = Velocity.getTemplate(
                  getFileName( null, "encodingtest2", TMPL_FILE_EXT), "UTF-8");

            fos =
                new FileOutputStream (
                    getFileName(RESULT_DIR, "encodingtest2", RESULT_FILE_EXT));

            writer = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8"));
          
            template.merge(context, writer);
            writer.flush();
            writer.close();
           
            if (!isMatch(RESULT_DIR,COMPARE_DIR,"encodingtest2",
                    RESULT_FILE_EXT,CMP_FILE_EXT) )
            {
                fail("Output 2 incorrect.");
            }

            /*
             *  a 'high-byte' chinese from Ilkka
             */

            template = Velocity.getTemplate(
                  getFileName( null, "encodingtest3", TMPL_FILE_EXT), "GBK");

            fos =
                new FileOutputStream (
                    getFileName(RESULT_DIR, "encodingtest3", RESULT_FILE_EXT));

            writer = new BufferedWriter(new OutputStreamWriter(fos, "GBK"));
          
            template.merge(context, writer);
            writer.flush();
            writer.close();
           
            if (!isMatch(RESULT_DIR,COMPARE_DIR,"encodingtest3",
                    RESULT_FILE_EXT,CMP_FILE_EXT) )
            {
                fail("Output 3 incorrect.");
            }

            /*
             *  Russian example from Vitaly Repetenko
             */

            template = Velocity.getTemplate(
                  getFileName( null, "encodingtest_KOI8-R", TMPL_FILE_EXT), "KOI8-R");

            fos =
                new FileOutputStream (
                    getFileName(RESULT_DIR, "encodingtest_KOI8-R", RESULT_FILE_EXT));

            writer = new BufferedWriter(new OutputStreamWriter(fos, "KOI8-R"));
          
            template.merge(context, writer);
            writer.flush();
            writer.close();
           
            if (!isMatch(RESULT_DIR,COMPARE_DIR,"encodingtest_KOI8-R",
                    RESULT_FILE_EXT,CMP_FILE_EXT) )
View Full Code Here

            /*
             *  let someone handle the request
             */

            Template template = handleRequest( request, response, context );       
            /*
             *  bail if we can't find the template
             */

            if ( template == null )
View Full Code Here

    {
        /*
         * invoke handleRequest
         */

        Template t =  handleRequest( ctx );

        /*
         *  if it returns null, this is the 'old' deprecated
         *  way, and we want to mimic the behavior for a little
         *  while anyway
View Full Code Here

            /*
             *  lets ensure the results directory exists
             */
            assureResultsDirectoryExists(RESULTS_DIR);

            Template template1 = RuntimeSingleton.getTemplate(
                getFileName(null, "template/test1", TMPL_FILE_EXT));
           
            Template template2 = RuntimeSingleton.getTemplate(
                getFileName(null, "template/test2", TMPL_FILE_EXT));
          
            FileOutputStream fos1 =
                new FileOutputStream (
                    getFileName(RESULTS_DIR, "test1", RESULT_FILE_EXT));

            FileOutputStream fos2 =
                new FileOutputStream (
                    getFileName(RESULTS_DIR, "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();
            writer2.close();

            if (!isMatch(RESULTS_DIR,COMPARE_DIR,"test1",RESULT_FILE_EXT,CMP_FILE_EXT) ||
                !isMatch(RESULTS_DIR,COMPARE_DIR,"test2",RESULT_FILE_EXT,CMP_FILE_EXT))
View Full Code Here

           
            /*
             *  get the template and the output
             */

            Template template = RuntimeSingleton.getTemplate(
                getFileName(null, "context_safety", TMPL_FILE_EXT));

            FileOutputStream fos1 =
                new FileOutputStream (
                    getFileName(RESULT_DIR, "context_safety1", RESULT_FILE_EXT));

            FileOutputStream fos2 =
                new FileOutputStream (
                    getFileName(RESULT_DIR, "context_safety2", 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
             */

            context.put("vector", v)
            template.merge(context, writer1);
            writer1.flush();
            writer1.close();
           
            /*
             *  now put the string array into the context, and merge
             */

            context.put("vector", strArray)
            template.merge(context, writer2);
            writer2.flush();
            writer2.close();

            if (!isMatch(RESULT_DIR,COMPARE_DIR,"context_safety1",
                    RESULT_FILE_EXT,CMP_FILE_EXT) ||
View Full Code Here

     */
    public void runTest ()
    {
        try
        {
            Template template1 = RuntimeSingleton.getTemplate(
                getFileName(null, "path1", TMPL_FILE_EXT));
           
            Template template2 = RuntimeSingleton.getTemplate(
                getFileName(null, "path2", TMPL_FILE_EXT));
          
            FileOutputStream fos1 =
                new FileOutputStream (
                    getFileName(RESULTS_DIR, "path1", RESULT_FILE_EXT));

            FileOutputStream fos2 =
                new FileOutputStream (
                    getFileName(RESULTS_DIR, "path2", 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();
            writer2.close();

            if (!isMatch(RESULTS_DIR, COMPARE_DIR, "path1",
                    RESULT_FILE_EXT, CMP_FILE_EXT) ||
View Full Code Here

            assureResultsDirectoryExists(RESULTS_DIR);

            /*
             * Template to find with the file loader.
             */
            Template template1 = Velocity.getTemplate(
                getFileName(null, "path1", TMPL_FILE_EXT));
           
            /*
             * Template to find with the classpath loader.
             */
            Template template2 = Velocity.getTemplate(
                getFileName(null, "template/test1", TMPL_FILE_EXT));
          
            /*
             * Template to find with the jar loader
             */
            Template template3 = Velocity.getTemplate(
               getFileName(null, "template/test2", TMPL_FILE_EXT));

            /*
             * and the results files
             */

            FileOutputStream fos1 =
                new FileOutputStream (
                    getFileName(RESULTS_DIR, "path1", RESULT_FILE_EXT));

            FileOutputStream fos2 =
                new FileOutputStream (
                    getFileName(RESULTS_DIR, "test2", RESULT_FILE_EXT));

            FileOutputStream fos3 =
                new FileOutputStream (
                    getFileName(RESULTS_DIR, "test3", RESULT_FILE_EXT));

            Writer writer1 = new BufferedWriter(new OutputStreamWriter(fos1));
            Writer writer2 = new BufferedWriter(new OutputStreamWriter(fos2));
            Writer writer3 = new BufferedWriter(new OutputStreamWriter(fos3));
           
            /*
             *  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();
            writer2.close();

            template3.merge(context, writer3);
            writer3.flush();
            writer3.close();

            if (!isMatch(RESULTS_DIR,COMPARE_DIR,"path1",RESULT_FILE_EXT,CMP_FILE_EXT))
            {
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.