Re: syntax change in velocity 1.7
No ideas... On Wed, Jun 1, 2011 at 9:26 AM, Will Glass-Husain wglasshus...@gmail.com wrote: Hi, I just did a test upgrade of a site from Velocity 1.6.2 to Velocity 1.7. A number of my templates started to fail because they included square brackets. (Ironically, we discovered this soon after I finished describing to my coworkers the project's obsessive stance on backwards compatibility). My pages often reference mathematical values, and the bracket is a common part of the text. This used to work #for($var in $varList) $abc[sub1] #end which would print something like Sales[sub1] Revenue[sub1] Cost[sub1] etc Now it gives a parse error. I see that ${abc}[sub1] keeps the old behavior. However, searching our site there have 40+ pages with many of these now illegal references. (Many by other authors). Any suggestions as to how I can keep the backwards compatible parsing behavior? I'll dig into the Velocity code, see if I can think of anything helpful. But just wanted to check if others had ideas. WILL - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: syntax change in velocity 1.7
Unfortunately, there is no introspection in Velocity. One complicated idea would be to meta parse your template. The idea would be to use a kind of Velocity introspection on all your templates. Each time this introspection encounter a variable, like ${a} or a, you replace it with a meta template that would content ${variableName} and would produce ${a}. So, finally, it would do the job for you. The only thing you need is that Velocity introspection but as far as I remember it doesn't exist. On 1 juin 2011, at 07:26, Will Glass-Husain wrote: Hi, I just did a test upgrade of a site from Velocity 1.6.2 to Velocity 1.7. A number of my templates started to fail because they included square brackets. (Ironically, we discovered this soon after I finished describing to my coworkers the project's obsessive stance on backwards compatibility). My pages often reference mathematical values, and the bracket is a common part of the text. This used to work #for($var in $varList) $abc[sub1] #end which would print something like Sales[sub1] Revenue[sub1] Cost[sub1] etc Now it gives a parse error. I see that ${abc}[sub1] keeps the old behavior. However, searching our site there have 40+ pages with many of these now illegal references. (Many by other authors). Any suggestions as to how I can keep the backwards compatible parsing behavior? I'll dig into the Velocity code, see if I can think of anything helpful. But just wanted to check if others had ideas. WILL - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: syntax change in velocity 1.7
You can alter your templates to match the new syntax, something like: find . -name *.vtl | xargs sed -ri -e s/\\\$([a-z.\(\)]+)(\[[^\]+])/$\{\1\}\2/g so that every reference which is followed by square brackets will be enclosed in curly brackets. Claude On 2011-06-01 09:44, Sergey Maslov wrote: No ideas... On Wed, Jun 1, 2011 at 9:26 AM, Will Glass-Husain wglasshus...@gmail.com wrote: Hi, I just did a test upgrade of a site from Velocity 1.6.2 to Velocity 1.7. A number of my templates started to fail because they included square brackets. (Ironically, we discovered this soon after I finished describing to my coworkers the project's obsessive stance on backwards compatibility). My pages often reference mathematical values, and the bracket is a common part of the text. This used to work #for($var in $varList) $abc[sub1] #end which would print something like Sales[sub1] Revenue[sub1] Cost[sub1] etc Now it gives a parse error. I see that ${abc}[sub1] keeps the old behavior. However, searching our site there have 40+ pages with many of these now illegal references. (Many by other authors). Any suggestions as to how I can keep the backwards compatible parsing behavior? I'll dig into the Velocity code, see if I can think of anything helpful. But just wanted to check if others had ideas. WILL - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: syntax change in velocity 1.7
Thanks, Claude, That's probably what I'll end up doing. Either one time or possibly do it dynamically in a custom resource loader. (The problem is these files are all spread out in different accounts with different authors and versioning). WILL On Wed, Jun 1, 2011 at 1:11 AM, Claude Brisson cla...@renegat.net wrote: You can alter your templates to match the new syntax, something like: find . -name *.vtl | xargs sed -ri -e s/\\\$([a-z.\(\)]+)(\[[^\]+])/$\{\1\}\2/g so that every reference which is followed by square brackets will be enclosed in curly brackets. Claude On 2011-06-01 09:44, Sergey Maslov wrote: No ideas... On Wed, Jun 1, 2011 at 9:26 AM, Will Glass-Husain wglasshus...@gmail.com wrote: Hi, I just did a test upgrade of a site from Velocity 1.6.2 to Velocity 1.7. A number of my templates started to fail because they included square brackets. (Ironically, we discovered this soon after I finished describing to my coworkers the project's obsessive stance on backwards compatibility). My pages often reference mathematical values, and the bracket is a common part of the text. This used to work #for($var in $varList) $abc[sub1] #end which would print something like Sales[sub1] Revenue[sub1] Cost[sub1] etc Now it gives a parse error. I see that ${abc}[sub1] keeps the old behavior. However, searching our site there have 40+ pages with many of these now illegal references. (Many by other authors). Any suggestions as to how I can keep the backwards compatible parsing behavior? I'll dig into the Velocity code, see if I can think of anything helpful. But just wanted to check if others had ideas. WILL - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Does velocity provide these features?
Hi there, i'm evaluating Velocity to find out whether it meets my requirements to generate text by using custom templates. I looked at the user guide and wrote a little hello world application but there are requirements for which I don't know if I have to write my own methods or if there are velocity tools that would do the job for me: Is there a way to automatically add line breaks when you merge the template with the context (without cutting words after e.g. 80 characters)? Is there a way to use text shifting (indentation) in combination with line breaks without cutting words after e.g. 80 characters)? Long text: $magic.doMagic( $text ) -- Long text: Some very Very long text, more text … Is there a way to automatically add line breaks (without cutting words after e.g. 80 characters) and add a certain String (e.g. 100. ) at the beginning of each line: Funny Velocity user request: $magic.doMagic2( $text ) -- Funny Velocity user request: this 100. is just a test, a test, a test, a 100. test, a test … Is there a way to cut the string of a variable after 9 characters and add a * to the string, if the string has more than 10 characters? #set( $test = textwithmorethan10char ) Test: $magic.doMagic3( $test) -- Test: textwithm* Thanx in advance! -- View this message in context: http://old.nabble.com/Does-velocity-provide-these-features--tp31748723p31748723.html Sent from the Velocity - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: Does velocity provide these features?
On 06/01/2011 03:40 PM, Moe221 wrote: Hi there, i'm evaluating Velocity to find out whether it meets my requirements to generate text by using custom templates. I looked at the user guide and wrote a little hello world application but there are requirements for which I don't know if I have to write my own methods or if there are velocity tools that would do the job for me: Is there a way to automatically add line breaks when you merge the template with the context (without cutting words after e.g. 80 characters)? Is there a way to use text shifting (indentation) in combination with line breaks without cutting words after e.g. 80 characters)? Long text: $magic.doMagic( $text ) -- Long text: Some very Very long text, more text … Is there a way to automatically add line breaks (without cutting words after e.g. 80 characters) and add a certain String (e.g. 100. ) at the beginning of each line: Funny Velocity user request: $magic.doMagic2( $text ) -- Funny Velocity user request: this 100. is just a test, a test, a test, a 100. test, a test … Is there a way to cut the string of a variable after 9 characters and add a * to the string, if the string has more than 10 characters? #set( $test = textwithmorethan10char ) Test: $magic.doMagic3( $test) -- Test: textwithm* Thanx in advance! Natively, no, this is not the job of the velocity core. But it would be fairly simple to write a velocity tool that does that for you, similar to http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/DisplayTool.html DisplayTool does have a method for your last request, see http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/DisplayTool.html#truncate%28java.lang.Object,%20int,%20java.lang.String,%20boolean%29 You will have to enable the tools, then you would have to write: $displaytool.truncate($test, 10, '*', false) Alternatively, you can do that as well directly in the template, but it would be a bit harder since you don't have all the power of Java. For example, line numbering has been done in: https://github.com/xwiki/xwiki-platform/raw/master/xwiki-platform-core/xwiki-platform-web/src/main/webapp/templates/code.vm -- Sergiu Dumitriu http://purl.org/net/sergiu/ - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: Does velocity provide these features?
As Sergiu said, this is a job for tools and the DisplayTool that is part of the VelocityTools project supports only one of the listed features. However, if you have code or write code for the other features, those would be welcome as patches to the DisplayTool, as those are just the kind of thing that it does. On Wed, Jun 1, 2011 at 6:40 AM, Moe221 mailtest...@gmx.de wrote: Hi there, i'm evaluating Velocity to find out whether it meets my requirements to generate text by using custom templates. I looked at the user guide and wrote a little hello world application but there are requirements for which I don't know if I have to write my own methods or if there are velocity tools that would do the job for me: Is there a way to automatically add line breaks when you merge the template with the context (without cutting words after e.g. 80 characters)? Is there a way to use text shifting (indentation) in combination with line breaks without cutting words after e.g. 80 characters)? Long text: $magic.doMagic( $text ) -- Long text: Some very Very long text, more text … Is there a way to automatically add line breaks (without cutting words after e.g. 80 characters) and add a certain String (e.g. 100. ) at the beginning of each line: Funny Velocity user request: $magic.doMagic2( $text ) -- Funny Velocity user request: this 100. is just a test, a test, a test, a 100. test, a test … Is there a way to cut the string of a variable after 9 characters and add a * to the string, if the string has more than 10 characters? #set( $test = textwithmorethan10char ) Test: $magic.doMagic3( $test) -- Test: textwithm* Thanx in advance! -- View this message in context: http://old.nabble.com/Does-velocity-provide-these-features--tp31748723p31748723.html Sent from the Velocity - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: Custom Java Object stored in Velocity Context
The class of the object and the method itself must be declared public. On Wed, Jun 1, 2011 at 1:38 PM, Logan Stinger lstin...@bluelid.com wrote: I have the following code: … ListICODocument history = repository.getDocumentHistoryForId(8B2F2F53-7DEA-45B6-84BA-60F2FA11F07D); context.put(documentHistory, history); Then in my notes.vm file I have the following: #foreach($doc in $response.response.get(documentHistory)) $doc #end The rendered output is what I would expect. However, I don’t want to see the toString() representation of my object. I want to see the value of a particular method call on my object. So I changed my notes.vm to be this: #foreach($doc in $response.response.get(documentHistory)) $doc.isMax() #end In this case my rendered output is simply: $doc.isMax() $doc.isMax() I was under the impression that I could add any java object to the velocity context and call any method on that object in my velocity template. Am I misunderstanding? *Logan Stinger* *[image: Description: bluelid_logo_small]* * * (515) 281-6702 (515) 822-8212 lstin...@bluelid.com
Re: Custom Java Object stored in Velocity Context
Well, i've got no problems getting Velocity to call public methods on instances of publicly declared classes. Got any more info you can share? Like the class in question? Velocity version? Log messages? Anything? On Wed, Jun 1, 2011 at 7:53 PM, Logan Stinger lstin...@bluelid.com wrote: The class is very simple right now, public class with 5 public getters and setters. Nothing else to it. I've tried sticking a few other classes in the context to test them. I have been unable to get anything but the toString representation of any of them. On Jun 1, 2011, at 5:15 PM, Nathan Bubna wrote: The class of the object and the method itself must be declared public. On Wed, Jun 1, 2011 at 1:38 PM, Logan Stinger lstin...@bluelid.com wrote: I have the following code: … ListICODocument history = repository.getDocumentHistoryForId(8B2F2F53-7DEA-45B6-84BA-60F2FA11F07D); context.put(documentHistory, history); Then in my notes.vm file I have the following: #foreach($doc in $response.response.get(documentHistory)) $doc #end The rendered output is what I would expect. However, I don’t want to see the toString() representation of my object. I want to see the value of a particular method call on my object. So I changed my notes.vm to be this: #foreach($doc in $response.response.get(documentHistory)) $doc.isMax() #end In this case my rendered output is simply: $doc.isMax() $doc.isMax() I was under the impression that I could add any java object to the velocity context and call any method on that object in my velocity template. Am I misunderstanding? *Logan Stinger* *[image: Description: bluelid_logo_small]* * * (515) 281-6702 (515) 822-8212 lstin...@bluelid.com - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org