[jira] [Commented] (VELOCITY-881) Even handler didn't work when the reference appear in #if statement
[ https://issues.apache.org/jira/browse/VELOCITY-881?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16091033#comment-16091033 ] pixiang.lq commented on VELOCITY-881: - At first, thank you for your answers Claude Brisson. I have try to force a rendering with code like: #if( "$some.reference" == 'some value') but it still doesn't work, and the output was: -- ${provider.version} -- I know "${deploy.domain} will always be null, since Velocity will first search the context for a deploy property". But in our team property naming conventions is "property.name", like "provider.version", rather than "property_name". So "reference insertion handler" mechanism is a good way for us to replace the value when velocity got value null. "$foo.bar.baz would call the handler three times, which is not at all desirable." In fact $foo.bar.baz would call the handler only one times and i have debug to verify that. --- public Object execute(Object o, InternalContextAdapter context) throws MethodInvocationException { if(this.referenceType == 4) { return null; } else { {color:red}Object result = this.getVariableValue(context, this.rootString);{color} this.log.error(String.format("rootString:%s, result:%s", this.rootString, result)); if(result == null && !this.strictRef) { return EventHandlerUtil.invalidGetMethod(this.rsvc, context, this.getDollarBang() + this.rootString, (Object)null, (String)null, this.uberInfo); } else { At last, may be my suggestion is not good for performance in other scenes and my be have another way to solute this. I fill it very strange that "reference insertion handler" mechanism has give a way to replace the inserted value in the template, but it not support to replace the reference in if statement. > Even handler didn't work when the reference appear in #if statement > --- > > Key: VELOCITY-881 > URL: https://issues.apache.org/jira/browse/VELOCITY-881 > Project: Velocity > Issue Type: Bug > Components: Engine >Affects Versions: 1.7 > Environment: it a common case. It nothing to do with a specified > environment >Reporter: pixiang.lq >Assignee: Claude Brisson > Labels: easyfix > Original Estimate: 2h > Remaining Estimate: 2h > > My code like: > > public static void main(String[] args) { > VelocityEngine ve = new VelocityEngine(); > ve.setProperty(Velocity.RESOURCE_LOADER, "class"); > ve.setProperty("class.resource.loader.class", > > "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); > try { > ve.init(); > Template tp = ve.getTemplate("my-template.xml"); > Context context = new VelocityContext(); > // add my event handler > Map map = new HashMap<>(); > map.put("deploy.domain", "offline"); > map.put("deploy_domain", "offline"); > map.put("provider.version", "1.0.0"); > map.put("provider_version", "1.0.0"); > EventCartridge eventCartridge = new EventCartridge(); > eventCartridge.addEventHandler(new > MyReferenceInsertionHandler(map)); > eventCartridge.attachToContext(context); > StringWriter writer = new StringWriter(); > tp.merge(context, writer); > System.out.println(writer.toString()); > } catch (Exception e) { > e.printStackTrace(); > } > } > > My template file to be converted by velocity like: > > #if(${deploy.domain}=='testString') > > > aaa > > > #end > > > ${provider.version} > > > -- > My got the output in fact: > -- > > > 1.0.0 > > > -- > My expected output: > -- > > > aaa > > > > > 1.0.0 > > > -- > My suggestion to fix this bug: > ASTReference.java > -- > The method before change: > public Object value(InternalContextAdapter context) > throws MethodInvocationException > { > return (computableReference ? execute(null, context) :
Re: [ANNOUNCE] Velocity Engine 2.0 RC9 test build available
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 Claude, On 7/17/17 7:09 AM, Claude Brisson wrote: > A new test build of Velocity Engine 2.0 is available (RC9). > > No determination as to the quality ('alpha,' 'beta,' or 'GA') of > Velocity Engine 2.0 has been made, and at this time it is simply a > "test build". We welcome any comments you may have, and will take > all feedback into account if a quality vote is called for this > build. > > Release notes: > > * > https://dist.apache.org/repos/dist/dev/velocity/velocity-engine/2.0/re lease-notes.html > > > > Distribution: > > * > https://dist.apache.org/repos/dist/dev/velocity/velocity-engine/2.0/ > > Maven 2 staging repository: > > * > https://repository.apache.org/content/repositories/orgapachevelocity-1 020/ > > A vote regarding the quality of this test build will be initiated > within the next couple of days. > > Release Candidates changelog: > > RC1: initial candidate RC2: bugfixes RC3: review SLF4J Logger names > (instead of a single logger named "Velocity", have a hierarchy of > loggers with a base of 'org.apache.velocity') RC4: minor fixes > RC5: * the default encoding is now UTF-8 (and not the platform > default) * commons-collections is not any more a compilation > dependency * commons-lang3 dependency is not any more shaded * the > configuration API doesn't reference ExtProperties * the events API > has been optimized and reviewed: all events do receive the current > Context * there has been a few optimizations in ASTStringLiteral > rendering RC6: mostly code cleaning and build process optimization > ; assembly module has been dropped RC7: still a lot of core > cleanups and reviews, plus: * new strategy for reference boolean > evaluation * allow expressions inside [ ] : $foo[$bar + 1] RC8: > vararg methods bugfix RC9: reenginering of the > DataSourceResourceLoader I should really know the answer to this question already, but I don't, ant it's not covered in the Release Notes: Is Velocity 2.0 backward-compatible with templates written for 1.x? Should I be able to simply replace e.g. Velocity 1.7 with 2.0 and expect it to work with very few changes? The changelog seems to indicate that "most things" ought to work right away, but I thought I'd ask. If that's the expectation, then I'll throw 2.0 into my testing environment immediately and see what happens. Thanks, - -chris -BEGIN PGP SIGNATURE- Comment: GPGTools - http://gpgtools.org Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBCAAGBQJZbRWbAAoJEBzwKT+lPKRYKtMQAJs7hVnk1KfYoQaoxbr2sJEv RP8MsYlOjF6cpFusMDipUeC/x1LGqDLLDwDDe2yNTtu6Tsc34ds09ZY7c0pPVPwr bPt2kj26BJI/6AGKs6X4ntJJ5dYhqppFk0VkjBl0ArB5LK6or4VTWWUyQaHrDXJB jCv73Zisoqtkq78cC9R7iWJdcqJUbwVQSZv+Gxc2AFugnRsX+emVAHiBWOk56wS5 d5+cq8yOd/35OToQyhHebilIFYKZdPlkBkimv3YI33oMAAILsKqyl7Xo2LYj+ilT NSgRt7bBen6mq/SmTgGC6J0hgCoORIGlJgf4gv+bLL6eNV9Jlugu/TLLqPxKzX+Z LmJwjlCpeF/p6uKCTmrou02WzgdqcmIH0DAFuStR5rl0yPymtNjbBu5E6tz6LMb2 FoCR3aUnKVBdTPCwt0CPdV1AZ7SmlEWH/R7q0CJs7A2A7rsX0NV2hzbN8Rg/tCDd EqHCus6ob53qZOntp7PjOGEvB4nor7DeVp/cAKNqDJ6fENp1uDue7InX4GAgyOkn t+pRm6hrTK1aP8XY5u3g7Fe413GEDbWIXYrxFOtQK6GQmlyLbnvy7K5JAmJQ1lfH kYYHxiw7gjzSrpPhgCHAHdmhr6d9Gty2gpWtb27h8OUIwHCQnvCWmgauqlo7Yi/A i+COIZjnc359z4Jaiou1 =r1/H -END PGP SIGNATURE- - To unsubscribe, e-mail: dev-unsubscr...@velocity.apache.org For additional commands, e-mail: dev-h...@velocity.apache.org
Re: [ANNOUNCE] Velocity Engine 2.0 RC9 test build available
Thanks. Just tried it locally without any issues. Cheers Dennis - To unsubscribe, e-mail: dev-unsubscr...@velocity.apache.org For additional commands, e-mail: dev-h...@velocity.apache.org
[jira] [Resolved] (VELOCITY-881) Even handler didn't work when the reference appear in #if statement
[ https://issues.apache.org/jira/browse/VELOCITY-881?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Claude Brisson resolved VELOCITY-881. - Resolution: Won't Fix Assignee: Claude Brisson Fix Version/s: (was: 2.0) A "reference insertion handler" does what its name states it does: it allows to alter what is to be inserted in the template, at the time of insertion. Your proposed change is to allow the handler to change the value after each and every *evaluation*, which means that $foo.bar.baz would call the handler three times, which is not at all desirable. You can sometimes _force_ a rendering with code like: #if( "$some.reference" == 'some value') but the example you give is also invalid because you use dots in property names, which is forbidden ; $\{deploy.domain} will always be null, since Velocity will first search the context for a _deploy_ property. > Even handler didn't work when the reference appear in #if statement > --- > > Key: VELOCITY-881 > URL: https://issues.apache.org/jira/browse/VELOCITY-881 > Project: Velocity > Issue Type: Bug > Components: Engine >Affects Versions: 1.7 > Environment: it a common case. It nothing to do with a specified > environment >Reporter: pixiang.lq >Assignee: Claude Brisson > Labels: easyfix > Original Estimate: 2h > Remaining Estimate: 2h > > My code like: > > public static void main(String[] args) { > VelocityEngine ve = new VelocityEngine(); > ve.setProperty(Velocity.RESOURCE_LOADER, "class"); > ve.setProperty("class.resource.loader.class", > > "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); > try { > ve.init(); > Template tp = ve.getTemplate("my-template.xml"); > Context context = new VelocityContext(); > // add my event handler > Map map = new HashMap<>(); > map.put("deploy.domain", "offline"); > map.put("deploy_domain", "offline"); > map.put("provider.version", "1.0.0"); > map.put("provider_version", "1.0.0"); > EventCartridge eventCartridge = new EventCartridge(); > eventCartridge.addEventHandler(new > MyReferenceInsertionHandler(map)); > eventCartridge.attachToContext(context); > StringWriter writer = new StringWriter(); > tp.merge(context, writer); > System.out.println(writer.toString()); > } catch (Exception e) { > e.printStackTrace(); > } > } > > My template file to be converted by velocity like: > > #if(${deploy.domain}=='testString') > > > aaa > > > #end > > > ${provider.version} > > > -- > My got the output in fact: > -- > > > 1.0.0 > > > -- > My expected output: > -- > > > aaa > > > > > 1.0.0 > > > -- > My suggestion to fix this bug: > ASTReference.java > -- > The method before change: > public Object value(InternalContextAdapter context) > throws MethodInvocationException > { > return (computableReference ? execute(null, context) : null); > } > After change: > public Object value(InternalContextAdapter context) > throws MethodInvocationException > { > Object value = this.computableReference?this.execute((Object)null, > context):null; > if(value == null && !this.escaped) { > // process the value by EventHandlerUtil > value = EventHandlerUtil.referenceInsert(this.rsvc, context, > this.literal, value); > } > return value; > } > -- -- This message was sent by Atlassian JIRA (v6.4.14#64029) - To unsubscribe, e-mail: dev-unsubscr...@velocity.apache.org For additional commands, e-mail: dev-h...@velocity.apache.org
[jira] [Created] (VELOCITY-881) Even handler didn't work when the reference appear in #if statement
pixiang.lq created VELOCITY-881: --- Summary: Even handler didn't work when the reference appear in #if statement Key: VELOCITY-881 URL: https://issues.apache.org/jira/browse/VELOCITY-881 Project: Velocity Issue Type: Bug Components: Engine Affects Versions: 1.7 Environment: it a common case. It nothing to do with a specified environment Reporter: pixiang.lq Fix For: 2.0 My code like: public static void main(String[] args) { VelocityEngine ve = new VelocityEngine(); ve.setProperty(Velocity.RESOURCE_LOADER, "class"); ve.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); try { ve.init(); Template tp = ve.getTemplate("my-template.xml"); Context context = new VelocityContext(); // add my event handler Map map = new HashMap<>(); map.put("deploy.domain", "offline"); map.put("deploy_domain", "offline"); map.put("provider.version", "1.0.0"); map.put("provider_version", "1.0.0"); EventCartridge eventCartridge = new EventCartridge(); eventCartridge.addEventHandler(new MyReferenceInsertionHandler(map)); eventCartridge.attachToContext(context); StringWriter writer = new StringWriter(); tp.merge(context, writer); System.out.println(writer.toString()); } catch (Exception e) { e.printStackTrace(); } } My template file to be converted by velocity like: #if(${deploy.domain}=='testString') aaa #end ${provider.version} -- My got the output in fact: -- 1.0.0 -- My expected output: -- aaa 1.0.0 -- My suggestion to fix this bug: ASTReference.java -- The method before change: public Object value(InternalContextAdapter context) throws MethodInvocationException { return (computableReference ? execute(null, context) : null); } After change: public Object value(InternalContextAdapter context) throws MethodInvocationException { Object value = this.computableReference?this.execute((Object)null, context):null; if(value == null && !this.escaped) { // process the value by EventHandlerUtil value = EventHandlerUtil.referenceInsert(this.rsvc, context, this.literal, value); } return value; } -- -- This message was sent by Atlassian JIRA (v6.4.14#64029) - To unsubscribe, e-mail: dev-unsubscr...@velocity.apache.org For additional commands, e-mail: dev-h...@velocity.apache.org
[ANNOUNCE] Velocity Engine 2.0 RC9 test build available
A new test build of Velocity Engine 2.0 is available (RC9). No determination as to the quality ('alpha,' 'beta,' or 'GA') of Velocity Engine 2.0 has been made, and at this time it is simply a "test build". We welcome any comments you may have, and will take all feedback into account if a quality vote is called for this build. Release notes: * https://dist.apache.org/repos/dist/dev/velocity/velocity-engine/2.0/release-notes.html Distribution: * https://dist.apache.org/repos/dist/dev/velocity/velocity-engine/2.0/ Maven 2 staging repository: * https://repository.apache.org/content/repositories/orgapachevelocity-1020/ A vote regarding the quality of this test build will be initiated within the next couple of days. Release Candidates changelog: RC1: initial candidate RC2: bugfixes RC3: review SLF4J Logger names (instead of a single logger named "Velocity", have a hierarchy of loggers with a base of 'org.apache.velocity') RC4: minor fixes RC5: * the default encoding is now UTF-8 (and not the platform default) * commons-collections is not any more a compilation dependency * commons-lang3 dependency is not any more shaded * the configuration API doesn't reference ExtProperties * the events API has been optimized and reviewed: all events do receive the current Context * there has been a few optimizations in ASTStringLiteral rendering RC6: mostly code cleaning and build process optimization ; assembly module has been dropped RC7: still a lot of core cleanups and reviews, plus: * new strategy for reference boolean evaluation * allow expressions inside [ ] : $foo[$bar + 1] RC8: vararg methods bugfix RC9: reenginering of the DataSourceResourceLoader Regards, Claude - To unsubscribe, e-mail: dev-unsubscr...@velocity.apache.org For additional commands, e-mail: dev-h...@velocity.apache.org