You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Claude Brisson (JIRA)" <ji...@apache.org> on 2016/07/18 19:18:20 UTC

[jira] [Resolved] (VELOCITY-747) Macros with same name in different templates creates issue when VelocityEngine initialized with init(Properties) method

     [ https://issues.apache.org/jira/browse/VELOCITY-747?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claude Brisson resolved VELOCITY-747.
-------------------------------------
       Resolution: Fixed
         Assignee: Claude Brisson
    Fix Version/s: 2.x

The problem comes from the fact that there are trailing spaces in your velocity.properties file, at the end of the line:

    velocimacro.permissions.allow.inline.local.scope = true

There's now the appropriate trimming to workaround such typos.


> Macros with same name in different templates creates issue when VelocityEngine initialized with init(Properties) method
> -----------------------------------------------------------------------------------------------------------------------
>
>                 Key: VELOCITY-747
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-747
>             Project: Velocity
>          Issue Type: Bug
>          Components: Engine
>    Affects Versions: 1.6.x
>            Reporter: Ravikanth L
>            Assignee: Claude Brisson
>             Fix For: 2.x
>
>         Attachments: VelocityInitializationExample.ZIP
>
>
> 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");



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org