Package org.apache.flex.forks.velocity.app

Examples of org.apache.flex.forks.velocity.app.VelocityEngine


  /**
   * Create a VelocityEngine instance configured with the given libs string
   */
  private static final VelocityEngine createEngine(String lib)
  {
    VelocityEngine ve = new VelocityEngine();
    // use our logger, and customize log settings
    ve.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, LOGSYSTEM_CLASS);
    ve.setProperty(Velocity.RUNTIME_LOG_ERROR_STACKTRACE, "false");
    ve.setProperty(Velocity.RUNTIME_LOG_REFERENCE_LOG_INVALID, "true");
    // use our strict introspection
    ve.setProperty(Velocity.UBERSPECT_CLASSNAME, STRICT_UBERSPECT_IMPL_CLASS);
    // load from classpath and file system
    ve.setProperty(Velocity.RESOURCE_LOADER, "file,class");
    // configure class resource loader
    ve.setProperty("class." + Velocity.RESOURCE_LOADER + ".class", CLASSPATH_RESOURCE_LOADER_CLASS);

    // libs are precompiled in later in this function
    ve.setProperty(Velocity.VM_LIBRARY, "");
    // initialize

    try
    {
      ve.init();
    }
    catch (Exception e)
    {
      ThreadLocalToolkit.log(new InitializationError(e.getLocalizedMessage()));
    }
View Full Code Here


   * Look up the VelocityEngine instance configured with the given libs string
   */
  private static final VelocityEngine getEngine(String lib)
  {
    String libKey = lib == null ? "" : lib;
    VelocityEngine ve = engines.get(libKey);
    if (ve == null)
      ve = createEngine(lib);
    if (ve != null)
      engines.put(libKey, ve);
    return ve;
View Full Code Here

    return getTemplate(path, (String) null);
  }

  public static Template getTemplate(String path, String lib)
  {
    VelocityEngine ve = getEngine(lib);
    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.
View Full Code Here

        {
            /*
             *  use an alternative logger.  Set it up here and pass it in.
             */
           
            ve = new VelocityEngine();
            ve.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, this );
            ve.init();
        }
        catch (Exception e)
        {
View Full Code Here

     *  Test to make sure that using '=' in #if() throws a PEE
     */
    public void testEquals()
        throws Exception
    {
        VelocityEngine ve = new VelocityEngine();

        ve.init();

        /*
         *  this should parse fine -> uses ==
         */

        String template = "#if($a == $b) foo #end";

        ve.evaluate(new VelocityContext(), new StringWriter(), "foo", template);

        /*
         *  this should throw an exception
         */

        template = "#if($a = $b) foo #end";

        try
        {
            ve.evaluate(new VelocityContext(), new StringWriter(), "foo", template);
            assertTrue(false);
        }
        catch(ParseErrorException pe)
        {
        }
View Full Code Here

     *  Test to see if we force the first arg to #macro() to be a word
     */
    public void testMacro()
        throws Exception
    {
        VelocityEngine ve = new VelocityEngine();

        ve.init();

        /*
         * this should work
         */

        String template = "#macro(foo) foo #end";

        ve.evaluate(new VelocityContext(), new StringWriter(), "foo", template);

         /*
         *  this should throw an exception
         */

        template = "#macro($x) foo #end";

        try
        {
            ve.evaluate(new VelocityContext(), new StringWriter(), "foo", template);
            assertTrue(false);
        }
        catch(ParseErrorException pe)
        {
        }
View Full Code Here

     0th arg to #macro() and the 1th arg to foreach()
     */
    public void testArgs()
        throws Exception
    {
        VelocityEngine ve = new VelocityEngine();

        ve.init();

        /*
         * this should work
         */

        String template = "#macro(foo) foo #end";

        ve.evaluate(new VelocityContext(), new StringWriter(), "foo", template);

         /*
         *  this should work - spaces intentional
         */

        template = "#foreach(  $i     in  $woogie   ) end #end";

        ve.evaluate(new VelocityContext(), new StringWriter(), "foo", template);

        /*
        *  this should bomb
        */

       template = "#macro(   foo $a) $a #end #foo(woogie)";

        try
        {
            ve.evaluate(new VelocityContext(), new StringWriter(), "foo", template);
            assertTrue(false);
        }
        catch(ParseErrorException pe)
        {
            System.out.println("Caught pee!");
View Full Code Here

        if (outputFile == null)
        {
            throw new BuildException("The output file needs to be defined!");
        }           
       
        VelocityEngine ve = new VelocityEngine();
       
        try
        {
            // Setup the Velocity Runtime.
            if (templatePath != null)
            {
              log("Using templatePath: " + templatePath, project.MSG_VERBOSE);
                ve.setProperty(
                    ve.FILE_RESOURCE_LOADER_PATH, templatePath);
            }
           
            if (useClasspath)
            {
              log("Using classpath");
                ve.addProperty(
                    VelocityEngine.RESOURCE_LOADER, "classpath");
           
                ve.setProperty(
                    "classpath." + VelocityEngine.RESOURCE_LOADER + ".class",
                        "org.apache.flex.forks.velocity.runtime.resource.loader.ClasspathResourceLoader");

                ve.setProperty(
                    "classpath." + VelocityEngine.RESOURCE_LOADER +
                        ".cache", "false");

                ve.setProperty(
                    "classpath." + VelocityEngine.RESOURCE_LOADER +
                        ".modificationCheckInterval", "2");
            }
           
            ve.init();

            // Create the text generator.
            Generator generator = Generator.getInstance();
            generator.setVelocityEngine(ve);
            generator.setOutputPath(outputDirectory);
View Full Code Here

        {
            /*
             *  use an alternative logger.  Set it up here and pass it in.
             */
           
            ve = new VelocityEngine();
            ve.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, this );
            ve.init();
        }
        catch (Exception e)
        {
View Full Code Here

TOP

Related Classes of org.apache.flex.forks.velocity.app.VelocityEngine

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.