Package org.apache.flex.forks.velocity

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


                        Twonk tw = (Twonk) libModMap.get( lib );
                       
                        if ( tw != null)
                        {
                            Template template = tw.template;
                           
                            /*
                             *  now, compare the last modified time of the resource
                             *  with the last modified time of the template
                             *  if the file has changed, then reload. Otherwise, we should
                             *  be ok.
                             */

                            long tt = tw.modificationTime;
                            long ft = template.getResourceLoader().getLastModified( template );

                            if ( ft > tt )
                            {
                                logVMMessageInfo("Velocimacro : autoload reload for VMs from " +
                                                 "VM library template : " + lib  );
            
                                /*
                                 *  when there are VMs in a library that invoke each other,
                                 *  there are calls into getVelocimacro() from the init()
                                 *  process of the VM directive.  To stop the infinite loop
                                 *  we save the current time reported by the resource loader
                                 *  and then be honest when the reload is complete
                                 */
                                
                                tw.modificationTime = ft;
                                                                      
                                template = rsvc.getTemplate( lib );
                                /*
                                 * and now we be honest
                                 */

                                tw.template = template;
                                tw.modificationTime = template.getLastModified();

                                /*
                                 *  note that we don't need to put this twonk back
                                 *  into the map, as we can just use the same reference
                                 *  and this block is synchronized
View Full Code Here


    String templateName = getTemplateName();
    Map templateVars = getTemplateVars();
    String suffix = getGeneratedSuffix();

    Template template = null;
    try
    {
      template = VelocityManager.getTemplate(getTemplatePath() + templateName);
    }
    catch(Exception e) {}


    if (template != null)
    {
      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();
        String prefix = sourceName.substring(0, sourceName.lastIndexOf(File.separatorChar) + 1);
        String generatedName = prefix + className + suffix;
View Full Code Here

    String templateKey = path + (lib == null ? "" : lib);

    // from what I can tell templates and there parser tree are static (unchanging)
    // data so that this should be thread safe, I think all the transient data comes
    // from the context.
    Template t = templates.get(templateKey);
    if (t == null)
    {
      t = getTemplate(path, ve);
      templates.put(templateKey, t);
    }
View Full Code Here

  private static Template getTemplate(String path, VelocityEngine ve)
  {
    try
    {
      Template t = SerializedTemplateFactory.load(path + "s");
      t.setRuntimeServices(ve.getRuntimeServices());
      t.setName(path);
      t.initDocument();
      return t;
    }
    catch (Exception e)
    {
      // any problems here are catastrophic failures
View Full Code Here

            }
      }

      StandardDefs standardDefs = ThreadLocalToolkit.getStandardDefs();
      String fontFaceRulesTemplate = TEMPLATE_PATH + standardDefs.getFontFaceRulesTemplate();
    Template template;

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

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

    private Source generateStyleSource(StyleDefList styleDefList, ResourceContainer resources,
                                       String packageName, String className, String genFileName)
    {
      //  load template

      Template template;
        StandardDefs standardDefs = ThreadLocalToolkit.getStandardDefs();
        String styleDefTemplate = TEMPLATE_PATH + standardDefs.getStyleDefTemplate();

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

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

        try
        {
            StandardDefs standardDefs = ThreadLocalToolkit.getStandardDefs();

            String templateName = standardDefs.getEmbedClassTemplate();
            Template template = VelocityManager.getTemplate(CODEGEN_TEMPLATE_PATH + templateName);
            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
            //velocityContext.put("needsStop", "" + (data.defineTag instanceof DefineSprite && ((DefineSprite)data.defineTag).needsStop));

            //long t2 = System.currentTimeMillis();
            //VelocityManager.parseTime += t2 - start;
View Full Code Here

            benchmarkHelper.endPhase(CompilerBenchmarkHelper.POSTPROCESS);
    }

    private VirtualFile generateSourceCodeFile(CompilationUnit compilationUnit, StyleModule styleModule)
    {
        Template template;
        StandardDefs standardDefs = compilationUnit.getStandardDefs();
        String templateName = TEMPLATE_PATH + (!configuration.archiveClassesAndAssets() ? standardDefs.getStyleModuleTemplate() : standardDefs.getStyleLibraryTemplate());

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

        SourceCodeBuffer sourceCodeBuffer = new SourceCodeBuffer();

        String genFileName = (configuration.getGeneratedDirectory() +
                              File.separatorChar +
                              styleModule.getName() +
                              "-generated.as");

        Source source = compilationUnit.getSource();

        DualModeLineNumberMap lineNumberMap = new DualModeLineNumberMap(source.getNameForReporting(), genFileName);
        styleModule.setLineNumberMap(lineNumberMap);

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

      StandardDefs standardDefs = doc.getStandardDefs();
      String classDefTemplate = CLASSDEF_TEMPLATE_PATH + standardDefs.getClassDefTemplate();
      String classDefLibTemplate = CLASSDEF_TEMPLATE_PATH + standardDefs.getClassDefLibTemplate();

    //  load template
    Template template = VelocityManager.getTemplate(classDefTemplate, classDefLibTemplate);
    if (template == null)
    {
      ThreadLocalToolkit.log(new UnableToLoadTemplate(classDefTemplate));
      return null;
    }

    //  evaluate template against document
    String genFileName = MxmlCompiler.getGeneratedName(mxmlConfiguration, doc.getPackageName(), doc.getClassName(),
                                                            "-generated.as");

    Source source = doc.getCompilationUnit().getSource();

    // C: I would like to guesstimate this number based on MXML component size...
    SourceCodeBuffer out = new SourceCodeBuffer((int) (source.size() * 4));
    try
    {
            DualModeLineNumberMap lineMap = new DualModeLineNumberMap(source.getNameForReporting(), genFileName);
            doc.setLineNumberMap(lineMap);

            VelocityUtil util = new VelocityUtil(CLASSDEF_TEMPLATE_PATH, mxmlConfiguration.debug(), out, lineMap);
      VelocityContext vc = VelocityManager.getCodeGenContext(util);
      vc.put(DOC_KEY, doc);
      // pass whether to care for comments or not
      vc.put(COMMENTS_KEY, processComments);
   
            template.merge(vc, out);
    }
    catch (Exception e)
    {
      ThreadLocalToolkit.log(new CodeGenerationException(doc.getSourcePath(), e.getLocalizedMessage()));
      return null;
View Full Code Here

        StandardDefs standardDefs = ThreadLocalToolkit.getStandardDefs();

        try
        {
            String templateName = CODEGEN_TEMPLATE_PATH + standardDefs.getSkinClassTemplate();
            Template template = VelocityManager.getTemplate(templateName);

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

            int dot = fullClassName.lastIndexOf( '.' );
            String packageName;
            String className;

            if (dot != -1)
            {
                packageName = fullClassName.substring(0, dot);
                className = fullClassName.substring(dot + 1);
            }
            else
            {
                packageName = "";
                className = fullClassName;
            }

            VelocityContext velocityContext = VelocityManager.getCodeGenContext();
            velocityContext.put("packageName", packageName);
            velocityContext.put("baseClassName", baseClassName);
            velocityContext.put("className", className);
            velocityContext.put("needsIBorder", new Boolean(needsIBorder));
            velocityContext.put("needsBorderMetrics", new Boolean(needsBorderMetrics));
            velocityContext.put("needsIFlexDisplayObject", new Boolean(needsIFlexDisplayObject));
            velocityContext.put("needsMeasuredHeight", new Boolean(needsMeasuredHeight));
            velocityContext.put("needsMeasuredWidth", new Boolean(needsMeasuredWidth));
            velocityContext.put("needsMove", new Boolean(needsMove));
            velocityContext.put("needsSetActualSize", new Boolean(needsSetActualSize));
            velocityContext.put("needsName", new Boolean(!flexMovieClipOrSprite));
            velocityContext.put("needsToString", new Boolean(!flexMovieClipOrSprite));

            StringWriter stringWriter = new StringWriter();
            template.merge(velocityContext, stringWriter);
            result = stringWriter.toString();
        }
        catch (Exception e)
        {
            if (Trace.error)
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.