Package org.apache.flex.forks.velocity

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


    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);
View Full Code Here


            else
            {
                writer = (Writer) writers.get(outputFile);
            }               
           
            VelocityContext vc = new VelocityContext( controlContext );
            template.merge (vc,writer);

            // commented because it is closed in shutdown();
            //fw.close();
           
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);
View Full Code Here

            else
            {
                writer = (Writer) writers.get(outputFile);
            }               
           
            VelocityContext vc = new VelocityContext( controlContext );
            template.merge (vc,writer);

            // commented because it is closed in shutdown();
            //fw.close();
           
View Full Code Here

    {
      try
      {
        StringWriter stringWriter = new StringWriter();

        VelocityContext velocityContext = new VelocityContext();

        for (Iterator iter = templateVars.entrySet().iterator(); iter.hasNext(); )
        {
          Map.Entry entry = (Map.Entry)iter.next();
          velocityContext.put((String)entry.getKey(), entry.getValue());
        }

        template.merge(velocityContext, stringWriter);

        String sourceName = unit.getSource().getName();
View Full Code Here

   * no reason to create a generic instance for every context, but we may want
   * to add state - benchmarking stuff etc.
   */
  public static VelocityContext getCodeGenContext(Util util)
  {
    VelocityContext cx = new VelocityContext();
    if (util == null)
    {
      util = new Util();
    }

    if (util instanceof EventHandler)
    {
      EventCartridge ec = new EventCartridge();
      ec.addEventHandler(util);
      ec.attachToContext(cx);
    }
    cx.put(UTIL_KEY, util);
    return cx;
  }
View Full Code Here

    SourceCodeBuffer out = new SourceCodeBuffer();

    try
    {
      VelocityUtil util = new VelocityUtil(TEMPLATE_PATH, mxmlConfiguration.debug(), out, null);
      VelocityContext vc = VelocityManager.getCodeGenContext(util);
            vc.put(ATEMBEDS_KEY, atEmbeds);
      template.merge(vc, out);
    }
    catch (Exception e)
    {
      ThreadLocalToolkit.log(new VelocityException.GenerateException(compilationUnit.getSource().getRelativePath(),
View Full Code Here

    SourceCodeBuffer out = new SourceCodeBuffer();

    try
    {
      VelocityUtil util = new VelocityUtil(TEMPLATE_PATH, mxmlConfiguration.debug(), out, null);
      VelocityContext vc = VelocityManager.getCodeGenContext(util);
      vc.put(STYLEDEFLIST_KEY, styleDefList);
            // vc.put(PACKAGENAME_KEY, packageName); TODO: get packagename working
      vc.put(CLASSNAME_KEY, className);
      template.merge(vc, out);
    }
    catch (Exception e)
    {
      ThreadLocalToolkit.log(new VelocityException.GenerateException(compilationUnit.getSource().getRelativePath(),
View Full Code Here

            if (template == null)
            {
                throw new TemplateException( templateName );
            }

            VelocityContext velocityContext = VelocityManager.getCodeGenContext();
            velocityContext.put( "packageName", packageName );
            velocityContext.put( "baseClass", baseClassName );
            if (embedProps.size() != 0)
            {
              velocityContext.put("assetType", ASSET_TYPE );
            }
            velocityContext.put( "embedClass", className );
            velocityContext.put( "embedMap", embedMap );
          velocityContext.put( "embedProps", embedProps );

            StringWriter stringWriter = new StringWriter();

            template.merge(velocityContext, stringWriter);
            // once we figure out a non-AS2 way to call stop, add this and put the generated code in EmbedClass.vm
View Full Code Here

        try
        {
            VelocityUtil velocityUtil = new VelocityUtil(TEMPLATE_PATH, configuration.debug(),
                                                         sourceCodeBuffer, lineNumberMap);
            VelocityContext velocityContext = VelocityManager.getCodeGenContext(velocityUtil);
            velocityContext.put(STYLE_MODULE_KEY, styleModule);
            template.merge(velocityContext, sourceCodeBuffer);
        }
        catch (Exception e)
        {
            ThreadLocalToolkit.log(new GenerateException(styleModule.getName(), e.getLocalizedMessage()));
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.