Uploaded image for project: 'Velocity'
  1. Velocity
  2. VELOCITY-747

Macros with same name in different templates creates issue when VelocityEngine initialized with init(Properties) method

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.6.x
    • 2.0
    • Engine
    • None

    Description

      I have two different templates with same macro names performing different functions. Works fine when VelocityEngine is initialized with init(propsFileName).

      When VelocityEngine is initialized with init(Properties), macro defined in template1 will be used when macro defined in template2 is called.

      Ex:

      one.vm:
      #macro ( myMacro )
      This is from myMacro macro of one.vm
      #end
      #myMacro

      two.vm
      #macro ( myMacro )
      This is from myMacro macro of two.vm
      #end
      #myMacro

      settings in my velocity.properties:
      directive.foreach.counter.initial.value = 1
      file.resource.loader.path = E:/Programs
      file.resource.loader.cache = true
      file.resource.loader.modificationCheckInterval = -1

      velocimacro.permissions.allow.inline.local.scope = true
      directive.set.null.allowed = true
      velocimacro.max.depth = -1

      code in java file:

      VelocityEngine engine = new VelocityEngine();
      Properties props = new Properties();
      props.load( new FileInputStream("velocity.properties") );
      engine.init(props);
      //engine.init("velocity.properties");

      StringWriter writer = new StringWriter();
      VelocityContext ctx = new VelocityContext();

      engine.mergeTemplate("one.vm","UTF-8", ctx,writer);
      System.out.println("Template 1 output:" + writer.toString());

      StringWriter writerTwo = new StringWriter();
      engine.mergeTemplate("two.vm","UTF-8", ctx,writerTwo);
      System.out.println("Template 2 output:" + writerTwo.toString());

      Expected output :
      Template 1 output:This is from Test1 macro of one.vm

      Template 2 output:This is from Test1 macro of two.vm

      Actual output:
      Template 1 output:This is from Test1 macro of one.vm

      Template 2 output:This is from Test1 macro of one.vm

      But with the same code will work properly when initialized with the commented line i.e. engine.init("velocity.properties");

      Attachments

        Activity

          People

            cbrisson Claude Brisson
            ravikanth_lolur Ravikanth L
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: