Re: Macros in macros
Expensive in cycles or memory? And in what version? Much optimization has been done, and i've yet to notice trouble in 1.6+ (at least compared to previous). On Thu, Dec 17, 2009 at 1:31 PM, Jude Robinson dotcode+veloc...@gmail.com wrote: Hi all - a concise question about VTL performance: referencing macros from within macros seems to be very expensive - do you know why this is? - 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: Macros in macros
Yeah, macros actually got a lot more expensive (especially in memory) in 1.5. 1.6.2 resolved most of those issues. :) On Thu, Dec 17, 2009 at 5:27 PM, Jude Robinson dotcode+veloc...@gmail.com wrote: Expensive in cycles or memory? And in what version? Much optimization has been done, and i've yet to notice trouble in 1.6+ (at least compared to previous). Sorry, should have stated the version: 1.6.2 pokes around a bit / sigh / Scratch that: 1.5 Sorry. Ignore. No problems here. trots off to upgrade / - 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: Include output from another servlet
With Spring MVC? Yeah, i have that running in an app somewhere, not sure offhand. Did you have particular questions? On Tue, Dec 15, 2009 at 6:44 AM, Ben Short b...@benshort.co.uk wrote: Thanks for this information. Has anyone had any luck getting velocity tools 2 working with spring? 2009/11/12 Antonio Petrelli antonio.petre...@gmail.com: 2009/11/12 Ben Short b...@benshort.co.uk: Using jsp I can include the output of another servlet using the following jsp:include page=/another/servlet/ Can the same thing be done with velocity? Try with the import tool: http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/view/ImportTool.html Ciao Antonio - 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 - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: Include output from another servlet
With Spring MVC? Yeah, i have that running in an app somewhere, not sure offhand. Did you have particular questions? On Tue, Dec 15, 2009 at 6:44 AM, Ben Short b...@benshort.co.uk wrote: Thanks for this information. Has anyone had any luck getting velocity tools 2 working with spring? 2009/11/12 Antonio Petrelli antonio.petre...@gmail.com: 2009/11/12 Ben Short b...@benshort.co.uk: Using jsp I can include the output of another servlet using the following jsp:include page=/another/servlet/ Can the same thing be done with velocity? Try with the import tool: http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/view/ImportTool.html Ciao Antonio - 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 - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: Inhrited public methods not visible to Velocity
On Thu, Oct 15, 2009 at 2:34 AM, Steve O'Hara soh...@pivotal-solutions.co.uk wrote: Of course, it turned out to be an error on my part sorry about that However as an aside, I changed the velocity code to call getMethods and removed the recursion in ClassMap.java and that worked fine. I know it's only a small thing and it's not exactly a fix because the code isn't broken, but maybe it's worth making the change for the small amount of possible performance gain. I'll leave it up to you. Did all tests pass too? Historical reasons are all i can think of right now. It is how it was done. I think, too, it was a way to keep out public methods inherited from protected classes. I kinda doubt the current dev community (myself included) would care about that anymore. I'm not sure whether there's much performance gain to be had by the swap, but certainly it seems like it would simplify the code and perhaps obviate such strange bugs as VELOCITY-736. If you would be so kind as to open a JIRA issue on this, i think it is something we should consider. Cheers, Steve -Original Message- From: Steve O'Hara Sent: 15 October 2009 09:22 To: Velocity Users List Subject: RE: Inhrited public methods not visible to Velocity Hi Nathan, Thanks for your reply - I'm using v6.2 Yes, the abstract class is public and the methods in the abstract class are also public. I've taken another look at ClassMap.java and can see how you're recursing up the super classes to get all the public methods. Forgive my naivety, but why is this necessary? Wouldn't a simple call to getMethods() do this for you which would also save having to check if the method is public? I'll see if I can debug why the introspector is not working in my case and come back to the list. Steve -Original Message- From: user-return-20992-sohara=pivotal-solutions.co...@velocity.apache.org [mailto:user-return-20992-sohara=pivotal-solutions.co...@velocity.apache.org] On Behalf Of Nathan Bubna Sent: 14 October 2009 20:38 To: Velocity Users List Subject: Re: Inhrited public methods not visible to Velocity On Wed, Oct 14, 2009 at 8:44 AM, Steve O'Hara soh...@pivotal-solutions.co.uk wrote: I have a class that extends an abstract class which is placed into a Velocity context. However, the public methods of the abstract class are not visible to Velocity. is the abstract class public? VelocityTools itself does this successfully. I looked at the source code and can see that getDeclaredMethods() is being used rather than getMethods() Is there a reason for that? Yes, the intention is to support public methods declared in public classes. So we navigate the class heirarchy looking for those. It's also always helpful with such questions to mention the version of Velocity being used. Thanks, Steve - 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 - 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: Testing for nulls with #if
When the innards of the $val block ($item.get(1)) resolve to null, they are output as they were. So $val should render as the literal string $item.get(1). That string is definitely not null. If you want, you can use quiet notation ($!item.get(1)), but even that will render as an empty string , which is also not null. So, no matter what, your $val reference will not be null. It is a defined block object which never renders as null. It is not a workable shortcut for null testing. You can do #if( $val == ) if you switch to quiet notation or #if( $val == $item.get(1) ) to test properly as things are. On Wed, Oct 14, 2009 at 3:35 AM, Margus Kliimask margus.kliim...@mindworks.ee wrote: Hi, I've run into a problem with testing for a null in #defined block with an #if directive. The manual states: The variable $foo is evaluated to determine whether it is true, which will happen under one of two circumstances: .. or (ii) the value is not null. I feed an array of lists ... String[] [] Items = {{A, 100}, {B, null}}; context.put(Items, Items); ... to this Velocity script: ... #define( $key )$item.get(0)#end #define( $val )$item.get(1)#end #foreach ( $item in $Items ) (1)#if( $item.get(1) )$key:$val #end (2)#if( $val )$key:$val #end #end ... I get back: (1)A:100 (2)A:100 (1)(2)B:$item.get(1) So, #if could detect null (missing value) in #if( $item.get(1) ), but could not in #defined block #if( $val ). What am I missing? I definitely don't want to mention the b-word here :) and appreciate any help, guidance or comments. Thanks, Margus - 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: Inhrited public methods not visible to Velocity
On Wed, Oct 14, 2009 at 8:44 AM, Steve O'Hara soh...@pivotal-solutions.co.uk wrote: I have a class that extends an abstract class which is placed into a Velocity context. However, the public methods of the abstract class are not visible to Velocity. is the abstract class public? VelocityTools itself does this successfully. I looked at the source code and can see that getDeclaredMethods() is being used rather than getMethods() Is there a reason for that? Yes, the intention is to support public methods declared in public classes. So we navigate the class heirarchy looking for those. It's also always helpful with such questions to mention the version of Velocity being used. Thanks, Steve - 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: Correct License citation
You aren't actually required to put reference of this in the About screen of the app. If you are distributing the application, my understanding is that you should put attribution in a NOTICE file, but if not distributing (and just running on your own server), you don't *need* to do anything license-wise. If you wish to give credit, however, typically the phrase Powered by Apache Velocity with Apache Velocity being a link to http://velocity.apache.org would be appreciated. On Fri, Sep 18, 2009 at 4:49 AM, Hazam ha...@email.it wrote: Hi all, I used velocity in a product, and since the License is Apache 2.0 I want to include correct reference in the About screen of the application. The library served for templating XML over HTTP requests, and was used as is in his 1.6.2 version. How should I report correctly in this About screen of the application? What is your preferred wording? Thanks a lot -Frank - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: Velocity Tools Error Question with Struts2
Personally, i'm really not sure. I haven't used Struts 2, and last i looked (which was easily a year ago) their VelocityTools support was rather outdated. Have you tried asking on the Struts list already? Have you tried putting your object into the request attributes? On Thu, Sep 17, 2009 at 1:58 PM, White, Tim tim.wh...@qwest.com wrote: While my colleague is waiting to get added to this list, he asked me to post this question on his behalf. He is trying to access the error info from a Struts2 controller, and is having the issues below: Thanks, Tim I'm having trouble accessing the validationAware errors that are generated in an Action class. GenericAction.java declaration: GenericLogin extends ActionSupport implements ServletRequestAware, ServletResponseAware, ServletContextAware, ValidationAware Code: addFieldError(ERROR_MSG_HEADER, /qCmsRepository/Global/Messages/Errors/error.errorMessageHeader.vm); addFieldError(FIELD_TEST, /qCmsRepository/Global/Messages/Errors/error.systemFailure.vm); Velocity Tool TestErrorTool.java declaration: TestErrorToolextends ActionSupport implements ValidationAware if (hasFieldErrors()) { Map errorMap = getFieldErrors(); String cmsErrorMessagePath = ; List fieldErrorList = (List)errorMap.get(errorKey); Iterator errorIterator = fieldErrorList.iterator(); while (errorIterator.hasNext()) { cmsErrorMessagePath = (String)errorIterator.next(); System.out.println(ErrorKey: + errorKey); System.out.println(ErrorMessagePath: + cmsErrorMessagePath); } } I cannot access the validationAware object when I get to the Velocity Tool. When you examie hasFieldErrors() it returns false. When I look at the objects in debug mode, the validationAware error, message fieldErrors are NULL. In the next step, the Interceptor, the validationAware objects are available again. How do I get access to the ValidationAware objects that I set in the action class in the Velocity Tool? Any help is appreciated. - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: Correct License citation
Then just follow the terms of the license. http://www.apache.org/foundation/licence-FAQ.html It's really not complicated. On Fri, Sep 18, 2009 at 12:58 PM, Emanuele Di Saverio emanuele.disave...@gmail.com wrote: Thanks for you answer Nathan!The problem is that I'm using it in a commercially distributed mobile application, and it gets distributed in an application package that cannot be inspected by the user. So how can I do? I want to be absolutely sure that I don't get sued by ASF :) On Fri, Sep 18, 2009 at 9:25 PM, Nathan Bubna nbu...@gmail.com wrote: You aren't actually required to put reference of this in the About screen of the app. If you are distributing the application, my understanding is that you should put attribution in a NOTICE file, but if not distributing (and just running on your own server), you don't *need* to do anything license-wise. If you wish to give credit, however, typically the phrase Powered by Apache Velocity with Apache Velocity being a link to http://velocity.apache.org would be appreciated. On Fri, Sep 18, 2009 at 4:49 AM, Hazam ha...@email.it wrote: Hi all, I used velocity in a product, and since the License is Apache 2.0 I want to include correct reference in the About screen of the application. The library served for templating XML over HTTP requests, and was used as is in his 1.6.2 version. How should I report correctly in this About screen of the application? What is your preferred wording? Thanks a lot -Frank - 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: Problems using logging in Velocity 1.6.2
On Mon, Aug 24, 2009 at 4:12 PM, Dr. Matthias Lauxmatthias.l...@web.de wrote: Hi Nathan, thanks a lot! So indeed most messages are at the FINE level, just as suspected. The problem I'm trying to solve is to identify actual template problems such as FINE: Null reference [template 'release_main.vm', line 18, column 9] : $yyy cannot be resolved. (taken from a JDK log output based on JdkLogChute). This originates in ASTReference line 404-406, where log.debug() is called - as expected a FINE log message. One problem I see is that this message is hidden between zillions of other messages offering status information - but no indication of real problems. The message above shows a real problem I need to fix. If this came at a WARNING or SEVERE level, I could find it. This is a debated issue and more involved than you might think. Velocity's original creators designed it to ignore schmoo (defined as anything not intended to be replaced by Velocity). I believe the idea was to have Velocity be very unobtrusive and only replace things it clearly understood and had values for. The imagined workflow was that people would take content and insert VTL into it. In such a view, syntax errors and missing values are minor things to be expected and easy to ignore. Other template engines reverse that and assume that anything that looks like their particular syntax are intended to be so. Thus, any missing values or syntax errors are treated severely and must be made impossible to ignore. The imagined workflow here is that the template language is primary and the content inserted into it, rather than vice versa. The Velocity community has never been at one mind (to my knowledge) about which approach was better, leading to a variety of inconsistent escaping patterns and configuration options to bend it one way or the other. There was enough other work and debates going on that this one never gained clear consensus or careful control, but the ignore schmoo view has largely prevailed as the default, leaving stricter controls as config options. My early contributions to the Velocity Engine project were largely about enhancing and cleaning up the log system and output. At the time, consensus was that it was much too noisy for a library. So i lowered the levels on many things, including this one you are concerned with. I stand by that choice as fitting the default pattern of Velocity. If you wish to treat missing references more harshly, you are free to configure ReferenceInsertionEventHandlers to do so, or turn on the strict mode that Byron Foster added in 1.6 (see the Strict Reference section of http://velocity.apache.org/engine/releases/velocity-1.6.2/developer-guide.html ) . These features allow you to push Velocity into more of a content inserted into template syntax paradigm. But unfortunately there is no option that will only raise the log level of that message. Different LogChute implementations may map the level differently, but all should map it to something that indicates debug level, not error or warn. In my previous approach messages like this were preceeded by [warn] or [error] and could be easily found in the velocity.log file. This was based on using the Velocity class directly rather that VelocityEngine. Is there some way to reproduce this behaviour in the new approach? Sounds like I should try to use the SystemLogChute or the AvalonLogChute since both use LogChute.WARN_PREFIX, which is what I had seen before in the output. Thanks again, Matthias Nathan Bubna wrote: Hi Matthias, Believe your eyes. The cues you need are in the source of the JdkLogChute.java file, lines 81-96. debug-FINE, trace-FINEST, warn-WARNING, error-SEVERE, info-INFO. And yeah, the overwhelming majority of Velocity log output happens at the debug/FINE level. You would only get a SEVERE if there were an error and only in very unlikely circumstances will you get a WARNING message. There are certainly a few trace/FINEST messages out there, but not many. Most messages are debug/FINE because they're there for debugging. INFO is not really a relevant level for Velocity. The presence of a myriad of log levels doesn't necessitate the use of them all. Velocity is a utility library, not a framework and certainly not an application. Logging is pretty much just for debugging or error reporting. There is little other data that needs logging in Velocity, and not much that users really need to ever see. It's my hope/plan to change things in the 2.x branch such that level is not the primary categorization for log messages. For Velocity, it's more important to know what function a message relates to. I'm envisioning developers using it like getLog().resources(message) and getLog().reflection(message, level) or maybe even getLog().users(message) to output things users need to see. Of course, i've been swamped with other work and haven't gotten to work on this yet
Re: continue processing templates after resource not found?
On Fri, Aug 28, 2009 at 2:46 PM, ChadDavischadmichaelda...@gmail.com wrote: I'm now using the org.apache.velocity.app.event.implement.IncludeNotFound event handler. This works great. But . . . I now would like to be able to have access to the name of the missing resource so i can inline it into the notfound.vm template that takes over when the resource is not found. Is this information in the context ? Okay. I looked at the code and it seems that this feature is not there. I wrote my own version that puts the not found resource in the context so you can have amore meaningful message in the notfound.vm. It's a very simple enhancement. Seems like it might be worth adding to the real class, let me know if you're interested. Yeah, that sounds like a good addition. Can you open a JIRA issue and attach it as a patch? https://issues.apache.org/jira/browse/VELOCITY - 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: Resorce not found -- again! :(
I'm not set up to easily test Tomcat 5 or 5.5 right now (this machine only has 6.0 at the moment). Here's some standard questions: Are you sure that your properties are being loaded? What version of VelocityTools are you using? And a non-standard one: Perhaps Tomcat 5.5 isn't fond of '.' in paths. Have you tried: webapp.resource.loader.path = /, /email On Wed, Aug 26, 2009 at 3:54 AM, Manishprol...@gmx.net wrote: I had a very strange experience and few stressful hours after shifting to Tomcat 5.5 recently. I still haven't understood the reasons, though I resolved the problem myself. Here is an attempt to understand reasons behind this dreaded ResourceNotFoundException when almost everything you have configured seems to be fine, moreover it was working for good 5 years! :) This is what I have in velocity.proeprties file kept under WEB-INF - # $Id: velocity.properties 649 2005-02-18 07:32:03Z manishh $ velocimacro.library.autoreload=true velocimacro.library=/VM_global_library.vm velocimacro.permissions.allow.inline=true file.resource.loader.cache=false # Filepath for error template, # relative to web application root directory tools.view.servlet.error.template = default/error.vm # Directory for layout templates, # relative to web application root directory tools.view.servlet.layout.directory = layout/ # Filepath of the default layout template # relative to the layout directory # NOT relative to the root directory of the webapp! tools.view.servlet.layout.default.template = Default.vm # set some path properties now webapp.resource.loader.path = ., ./email The servlet is configured correctly - servlet servlet-namevelocity/servlet-name servlet-class org.apache.velocity.tools.view.servlet.VelocityLayoutServlet /servlet-class init-param param-nameorg.apache.velocity.toolbox/param-name param-value/WEB-INF/toolbox.xml/param-value /init-param init-param param-nameorg.apache.velocity.properties/param-name param-value/WEB-INF/velocity.properties/param-value /init-param load-on-startup1/load-on-startup /servlet All this was working fine under Tomcat 5.0.28 but when I switched to Tomcat 5.5.28, it suddenly started showing ResourceNotFoundException for the VTL files. when I switched back to Tomcat 5.0.28, it worked fine What exactly is happening here? I am running Win XP and Velocity tools 1.1. I am really surprised to see this behaviou r - clearly the issue is with velocity.proeprties file, but I can't underatand **what** exactly is the problem and what should be done to make it work under Tomcat 5.5??? Any pointers, help would be highly appreciated. TIA, - Manish - 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: Problems using logging in Velocity 1.6.2
Hi Matthias, Believe your eyes. The cues you need are in the source of the JdkLogChute.java file, lines 81-96. debug-FINE, trace-FINEST, warn-WARNING, error-SEVERE, info-INFO. And yeah, the overwhelming majority of Velocity log output happens at the debug/FINE level. You would only get a SEVERE if there were an error and only in very unlikely circumstances will you get a WARNING message. There are certainly a few trace/FINEST messages out there, but not many. Most messages are debug/FINE because they're there for debugging. INFO is not really a relevant level for Velocity. The presence of a myriad of log levels doesn't necessitate the use of them all. Velocity is a utility library, not a framework and certainly not an application. Logging is pretty much just for debugging or error reporting. There is little other data that needs logging in Velocity, and not much that users really need to ever see. It's my hope/plan to change things in the 2.x branch such that level is not the primary categorization for log messages. For Velocity, it's more important to know what function a message relates to. I'm envisioning developers using it like getLog().resources(message) and getLog().reflection(message, level) or maybe even getLog().users(message) to output things users need to see. Of course, i've been swamped with other work and haven't gotten to work on this yet, though it's one of the things i'm more excited about doing. On Sun, Aug 23, 2009 at 1:07 AM, Dr. Matthias Lauxmatthias.l...@web.de wrote: (aopolgies if this should appear twice - I don't see my first email on the mailing list archive so I gather the mail may not have made it) Hi, I'm lost getting Velocity logging to work the way I need it. In the past I used the Velocity directly such as Velocity.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templateDir); Velocity.init(); and got the expected output in the velocity.log file. Now I moved to using VelocityEngine instead because I had some issues with the output in a long running server app which performed the same tasks over and over again (the velocity.log file would grow and I did not know how to get Velocity to start a new file for every processing run). Anyway. Now the new code started to look like this: engine = new VelocityEngine(); engine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templateDir); engine.init(); and nothing happens other than an empty file velocity.log being created. Well. So I added a LogChute: engine = new VelocityEngine(); engine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templateDir); engine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, org.apache.velocity.runtime.log.JdkLogChute); engine.init(); because I'm using JDK logging in my app anyway. My own logging is based on a console handler with level INFO and a file handler with level FINE (at least right now). What happened now was that there was nothing related to Velocity on the console, and truckloads of FINE log entries in the file handler. That's not quite all of the expected results, but it's the best I got so far. As it seems, Velocity seems to pick up the settings of the JDK logging subsystem. It gets weird tho when I set the logging level for the file handler to INFO as well: all log entries to the file handler for the JdkLogChute are gone. The only way for me to understand these observations is that only log messages of level FINE are actually recorded. Even if I go to level FINEST and check out the log files afterwards, there's zillions of Velocity log entries, but all with level FINE. This works also for the java.util.logging.ConsoleHandler, i. e. setting the level to FINE there also gives me the log messages, but all of level FINE. In my original velocity.log there were - for the same set of data - [error] and [debug] entries which I would like to see again as corresponding log entries. Having only messages of level FINE can't be correct tho. When, for testing purposes, I add a manual log entry like this engine.getLog().info(Hello); right after the init(), it works on both console and file. So the loggers used inside Velocity also work correctly, but it seems that Velocity itself only creates log messages with level FINE - which I refuse to believe. I also tried the AvalonLogChute instead since that seems to be the default used in my previous implementation (velocity.log created by interacting with Velocity instead of VelocityEngine). Same result - an empty velocity.log file. Well, this is not too surprising since I presume that the AvalonLogChute is still the default - and I had not specified a LogChute in the first attempts. I'm kinda lost right now. I would like to be able to use JDK logging (since then I don't have to deal with different output files in analysis afterwards) and I would like to propagate the (configurable) log levels of my application to the
Re: Calling overridden superclass methods in VTL
No, there was never such a feature. I think the statement should be something like: $reference.badMethodDefinedInSuperClass() The point seems to be that Velocity supports calling any public method of an object defined in a public class/interface, not merely those defined in the subclass. Which is quite true. On Tue, Aug 11, 2009 at 7:25 AM, Christopher Schultzch...@christopherschultz.net wrote: All, I was reading http://wiki.apache.org/jakarta-velocity/BuildingSecureWebApplications and I noticed that, about halfway down the page, there is this warning about creating subclass wrappers around objects: Subclassing is not helpful as the template designer can call a method from a superclass with the VTL $reference.super().badmethod(). I no documentation of the super method neither in the Developer Guide nor in the VTL Reference. As far as I know, calling around a virtual method is not possible even using regular Java. Is this statement apocryphal, or was/is this possible at some point? Thanks, -chris - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: From Viewtool get the VTL being parsed
a tool can really only get access to whatever is in the context or what is manually given to it. since the HttpServletRequest is available automatically, they can get the request path and derive the file from that. just know that even that isn't perfect; if the request path points to foo.vm and foo.vm does #parse('bar.vm') which is the one with your tool being used in it, there's no way for the tool to know that without being told, since #parse doesn't really inject info about itself into the context. On Sat, Aug 8, 2009 at 6:01 AM, Jason Tesserjasontes...@gmail.com wrote: From a viewtool I need to get the name of the file being parsed. Is that possible? Thanks, Jason Tesser dotCMS Lead Development Manager 1-305-858-1422 - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: arguments to macro
there's a velocimacro.strict.arguments property that would make that true, but it's false by default. it's been that way for some time. i'm not sure why the user guide says that. On Thu, Aug 6, 2009 at 9:14 AM, ChadDavischadmichaelda...@gmail.com wrote: In the user guide, it says when the Velocimacro is invoked, it must be called with the same number of arguments with which it was defined I find that this isn't the case. I can define several params and only pass in the ones I need. I'm using 1.7 beta, perhaps this behaviour is different. The docs are for 1.6 - 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: Velocity File Resource Path Loading Problem
): at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:539) W/System.err( 710): at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212) W/System.err( 710): at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) W/System.err( 710): at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409) W/System.err( 710): at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520) Nathan Bubna wrote: Have you tried using the WebappResourceLoader from the VelocityTools project? The FileResourceLoader is difficult to use and not very portable in webapp environments. It also won't work at all in unexploded WAR deployments. On Mon, Jul 20, 2009 at 9:48 PM, Jim Cortezj...@jimcortez.com wrote: Hello all, I am working on a small MVC framework that runs on top of iJetty (a Jetty port fot the Android platform). I am having trouble during initialization of Velocity. Take a peek at the following code: Log.info(Setting Template Directory: +Configuration.VIEWS_LOC); File viewsFolder = new File(Configuration.VIEWS_LOC); if(!viewsFolder.exists() || !viewsFolder.canRead()){ success=false; Log.warn(Folder +Configuration.VIEWS_LOC+ does not exist, or unreachable!); } else { Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, Configuration.VIEWS_LOC); Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, ConciergeVelocityLogger); try { Velocity.init(); } catch (Exception e) { Log.warn(Error initializing Velocity: +e.getMessage()); e.printStackTrace(); success = false; } } That code should show that the templates directory both exists and is readable. Here is the output of the error log: I/Jetty ( 709): Setting Template Directory: /sdcard/jetty/webapps/concierge/WEB-INF/views W/Jetty ( 709): Error initializing Velocity: null W/System.err( 709): java.lang.NullPointerException W/System.err( 709): at java.io.Reader.init(Reader.java:72) W/System.err( 709): at java.io.InputStreamReader.init(InputStreamReader.java:96) W/System.err( 709): at org.apache.commons.collections.ExtendedProperties.load(ExtendedProperties.java:543) W/System.err( 709): at org.apache.commons.collections.ExtendedProperties.load(ExtendedProperties.java:519) W/System.err( 709): at org.apache.velocity.runtime.RuntimeInstance.setDefaultProperties(RuntimeInstance.java:397) W/System.err( 709): at org.apache.velocity.runtime.RuntimeInstance.initializeProperties(RuntimeInstance.java:570) W/System.err( 709): at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:249) W/System.err( 709): at org.apache.velocity.runtime.RuntimeSingleton.init(RuntimeSingleton.java:114) W/System.err( 709): at org.apache.velocity.app.Velocity.init(Velocity.java:79) W/System.err( 709): at org.concierge.lib.Configurator.initialize(Configurator.java:34) W/System.err( 709): at org.concierge.lib.DispatchServlet.doGet(DispatchServlet.java:25) W/System.err( 709): at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) W/System.err( 709): at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) W/System.err( 709): at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502) W/System.err( 709): at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:389) W/System.err( 709): at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) W/System.err( 709): at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) W/System.err( 709): at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) W/System.err( 709): at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:417) W/System.err( 709): at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230) W/System.err( 709): at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) W/System.err( 709): at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) W/System.err( 709): at org.mortbay.jetty.Server.handle(Server.java:320) W/System.err( 709): at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:535) W/System.err( 709): at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:865) W/System.err( 709): at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:539) W/System.err( 709): at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212) W/System.err( 709): at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) W/System.err( 709): at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228) W/System.err( 709): at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520) I can only
Re: simple problem
On Mon, Jul 20, 2009 at 12:49 AM, lanxiazhilanxia...@gmail.com wrote: thanks Rupali, I got this problem when I started to think that, can I simply output an expression like #{1+2+20*3+$a} without a varible? The macro is fine. Alternately, you could add an instance of the MathTool (from VelocityTools) to your context and use that. ## this will have a newline char in it... #set($newline=hello ) and $velocityCount can be configured to start at any number: directive.foreach.counter.initial.value = 0 2009/7/20 Rupali Gupta r.gup...@mpstechnologies.com Hi, Use $velocityCount in place where you need incremental value of some variable Eg: instead of, #set($a = 0) #foreach($mapping in $mappings) Do something.. #set($a = $a+1) label for=journal-$aType something/label Do it like: #foreach($mapping in $mappings) Do something.. label for=journal- $velocityCount Type something /label $velocityCount increase the value of variable incrementally, without having to use ($a= $a+1) I hope this helps! Thanks, Rupali _ From: lanxiazhi [mailto:lanxia...@gmail.com] Sent: Monday, July 20, 2009 12:52 PM To: Velocity Users List Subject: Re: simple problem we know this #set($a = $a + 1) will change $a which in some cases may not be preferable...but thanks anyway. 2009/7/20 Alexander the.malk...@gmail.com Hi, Use #set($a = $a + 1) Correct me if Im wrong but if u use variable like this it would write hello on a single line, where is the problem? #set($newline=hello) $newline - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: simple problem
On Mon, Jul 20, 2009 at 7:02 AM, Alexander the.malk...@gmail.com wrote: Oh, didnt know that it can be configured, really thanks! Anyway default behaviour not obvious for javadev. The rational was that it wasn't just meant for javadevs and javadevs would be able to figure it out. I'm willing to reconsider this in version 2. 2009/7/20 Nathan Bubna nbu...@gmail.com On Mon, Jul 20, 2009 at 12:49 AM, lanxiazhilanxia...@gmail.com wrote: thanks Rupali, I got this problem when I started to think that, can I simply output an expression like #{1+2+20*3+$a} without a varible? The macro is fine. Alternately, you could add an instance of the MathTool (from VelocityTools) to your context and use that. ## this will have a newline char in it... #set($newline=hello ) and $velocityCount can be configured to start at any number: directive.foreach.counter.initial.value = 0 2009/7/20 Rupali Gupta r.gup...@mpstechnologies.com Hi, Use $velocityCount in place where you need incremental value of some variable Eg: instead of, #set($a = 0) #foreach($mapping in $mappings) Do something.. #set($a = $a+1) label for=journal-$aType something/label Do it like: #foreach($mapping in $mappings) Do something.. label for=journal- $velocityCount Type something /label $velocityCount increase the value of variable incrementally, without having to use ($a= $a+1) I hope this helps! Thanks, Rupali _ From: lanxiazhi [mailto:lanxia...@gmail.com] Sent: Monday, July 20, 2009 12:52 PM To: Velocity Users List Subject: Re: simple problem we know this #set($a = $a + 1) will change $a which in some cases may not be preferable...but thanks anyway. 2009/7/20 Alexander the.malk...@gmail.com Hi, Use #set($a = $a + 1) Correct me if Im wrong but if u use variable like this it would write hello on a single line, where is the problem? #set($newline=hello) $newline - 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: Escaping question
#set( $hashes = '' ) $hashes single-quoted strings are not interpolated. On Mon, Jul 20, 2009 at 12:07 PM, Steve Cohensco...@javactivity.org wrote: Using Velocity 1.6.2 I wish to output the string #. In my template, I code it \#\#\#\#\# It renders as \#\#\#\#\#. What am I doing wrong? Or how can I make it do what I want? Steve Cohen - 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: Escaping question
On Mon, Jul 20, 2009 at 5:51 PM, Nathan Bubnanbu...@gmail.com wrote: In VelocityTools 1.4, there is little support for auto-loading GenericTools, i wouldn't bother. Just create a context, add tool instances that you want and then use the already available context-chaining support in VelocityContext to use that tool context as a base context for other ones. just to clarify, since i just noticed you are creating a webapp. you could use the ServletToolboxManager in 1.4 to manage your tools without using the VelocityViewServlet at all. ask if you want more info on that. In VelocityTools 2.0, you can just create a ToolManager and ask it for a ToolContext (which you can use like a standard VelocityContext) via the createContext() method. Auto-loading definitely requires a special context. oh, and in 2.0, you would not need to do any configuration. just get a ToolContext and go, tools are lazy-loaded when used, so all are configured to be available by default. On Mon, Jul 20, 2009 at 1:53 PM, Steve Cohensco...@javactivity.org wrote: Steve Cohen wrote: ... (never mind any of what I wrote before, I have now boiled it down to one hopefully intelligent question): I am NOT using VelocityView but instantiating, configuring and initializing a VelocityEngine in java code. I don't use Velocity View. Since I don't use VelocityView, and the documentation for Velocity Tools assumes I do (http://velocity.apache.org/tools/releases/1.4/generic/EscapeTool.html) telling me this: *Toolbox Configuration Example* tool keyesc/key scopeapplication/scope classorg.apache.velocity.tools.generic.EscapeTool/class /tool how do I perform this same step in java code (i.e. what applicationAttributes or runtime Properties must I set, in order for my VelocityEngine to see the Tools generally or the EscapeTool in particular (which is all I need)? - 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: macros parameter type checking
#if( $foo.class.name == java.lang.Integer ) or just don't give your macro to an untrusted user. or if you can at least trust the user to pass a number, then $foo.intValue() is all you need. On Fri, Jun 26, 2009 at 10:52 AM, ChadDavischadmichaelda...@gmail.com wrote: I have a macro that takes an integer parameter. AFAIK, there's no support for typing in the Velocity language. How can I verify that the parameter is an integer value before doing my velocity macro logic? - 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: Resource from a jar file
Can you put your jar in the classpath and use the ClasspathResourceLoader instead of going through the file system? I've never used the JarResourceLoader, and i haven't really got time to dig in and see why it isn't working for you right now... On Sun, Jun 14, 2009 at 11:21 AM, Mark Fenbersmark.fenb...@noaa.gov wrote: Nathan Bubna wrote: You can configure multiple resource loaders in a lookup order. resource.loader=jar,file,whatever jar.resource.loader.class = ... file.resource.loader.class = ... whatever.resource.loader.class = ... if Velocity can't find it via the jar one, it'll ask the file one, then the whatever one, and so on until it runs out of loaders to ask. Only then will it throw a ResourceNotFoundException. Good to know this. My velocity.properties file now looks like this: resource.loader = jar,file jar.resource.loader.class = org.apache.velocity.runtime.resource.loader.JarResourceLoader jar.resource.loader.path = jar:file:templates.jar file.resource.path = / So now I am able to get past the Velocity.init() method without any thrown exceptions regardless how I'm running my app (jar, JVM, Eclipse, etc.). But when my app reaches the mergeTemplate() method, I get a ResourceNotFoundException: org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'file:/home/oper/workspace/GIFTS/templates.jar!/SHEF.6hr.template' when I run from the Jar file, but do not get it if running from JVM or Eclipse. My /home/oper/workspace/GIFTS/templates.jar file looks like this: 7332 Mon May 04 08:14:20 EDT 2009 SHEF.6hr.template (among other entries). So despite the error, the jar file it complains about exists at the location given, and it also contains the template file that it squawks about. So I'm not sure what I'm doing wrong and why the resource cannot be found when it exists right where is says it is looking. Any ideas? I'm using v1.6.2. Mark - 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: Best way to handle optional attributes in 1.6.2
Your original VTL amounted to #if ( null != ) when there was no attribute value. The fact that this evaluated as false was a bug, since null doesn't equal the empty string. Several little, obscure comparison bugs like this were fixed prior to 1.6.2. I don't recall, though, under which commit/JIRA Issue this fix was registered in the changelog. On Mon, Jun 15, 2009 at 3:19 PM, sebbseb...@gmail.com wrote: Thanks for the suggestions which work fine. There seems to have been a change in behaviour since version 1.5.1, but I could not find it in the release notes. Can anyone confirm this? On 14/06/2009, Nathan Bubna nbu...@gmail.com wrote: That should be: #if( $!items.getAttributeValue('required') != ) Or just $!items.getAttributeValue('required') if you don't mind showing empty strings. Or if you really want to clean up the look: public class AltTool { public Object empty(Object val, Object alt) { return (val == null || val.toString().length() == 0) ? alt : val; } } context.put(alt, new AltTool()); $alt.empty($item.getAttributeValue('required'), 'No') On Sat, Jun 13, 2009 at 5:39 AM, Jude Robinsondotcode+veloc...@gmail.com wrote: Is there a better way to handle optional attributes? !$items.getAttributeValue('required') != - 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 - 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: Resource from a jar file
Yes, but at some point, many Velocity users will ship an app with finished templates that the customer won't modify. At that time, it can make a lot of sense to just keep your templates in the classpath or a non-classpath jar. Guessing from user examples and questions, the ClasspathResourceLoader is one of the more frequently used loaders. The JarResourceLoader is probably the least-used one. Personally, i use the WebappResourceLoader from VelocityTools most. On Mon, Jun 15, 2009 at 6:54 PM, Mark Fenbersmark.fenb...@noaa.gov wrote: Amidst this dialog, the thought occurred to me that templates are made to be customized (or what would be the point of Velocity?), and so I realized that these template really don't belong in a Jar file anyway. If they were, people who know little about Java would have to un-jar the templates, modify them, and re-jar them before my app would read them. So it now makes sense to just read these from the file system, rather than from a jar file... Thanks, anyway, as I learned some important things in the process. Mark Nathan Bubna wrote: Can you put your jar in the classpath and use the ClasspathResourceLoader instead of going through the file system? I've never used the JarResourceLoader, and i haven't really got time to dig in and see why it isn't working for you right now... - 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: Best way to handle optional attributes in 1.6.2
That should be: #if( $!items.getAttributeValue('required') != ) Or just $!items.getAttributeValue('required') if you don't mind showing empty strings. Or if you really want to clean up the look: public class AltTool { public Object empty(Object val, Object alt) { return (val == null || val.toString().length() == 0) ? alt : val; } } context.put(alt, new AltTool()); $alt.empty($item.getAttributeValue('required'), 'No') On Sat, Jun 13, 2009 at 5:39 AM, Jude Robinsondotcode+veloc...@gmail.com wrote: Is there a better way to handle optional attributes? !$items.getAttributeValue('required') != - 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: Resource from a jar file
I think org.apache.velocity.runtime.resource.loader.JarResourceLoader was created to help with such situations. On Sat, Jun 13, 2009 at 4:56 PM, Mark Fenbersmark.fenb...@noaa.gov wrote: I'm having some trouble with mergeTemplate() in that it seems to be unable to open a template file if it is packaged in a jar file. In my Java code, I use getResource(resources/velocity.template).getFile() [from the Class object] to expand the relative location to a full URL. This is for flexibility/portability... This approach works fine when *not* running my app from a Jar file because the file name expands to a simple path, something like: /home/mark/resources/velocity.template whereas when run from a Jar file, it expands to something like: file:/home/mark/MyApp.jar!/resources/velocity.template, and thus mergeTemplate doesn't like this format... probably the file: or the ! throw it off. I'm not sure how to get past this hurdle. Any ideas? Mark - 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: Resource from a jar file
On Sat, Jun 13, 2009 at 6:48 PM, Mark Fenbersmark.fenb...@noaa.gov wrote: Nathan Bubna wrote: I think org.apache.velocity.runtime.resource.loader.JarResourceLoader was created to help with such situations. OK, I read up on JarResourceLoader() and put the appropriate resource loader entries into the velocity.properties file, but now I have a new problem in that if I am not using a Jar file, it dumps a stack trace. My program can run from Eclipse, from a JVM, or from a jar file. I want to avoid having a separate velocity.properties file for each way the program can be run. Is there a way the velocity.properties file can be configured so that it doesn't matter if the program is run from a jar or from a JVM? You can configure multiple resource loaders in a lookup order. resource.loader=jar,file,whatever jar.resource.loader.class = ... file.resource.loader.class = ... whatever.resource.loader.class = ... if Velocity can't find it via the jar one, it'll ask the file one, then the whatever one, and so on until it runs out of loaders to ask. Only then will it throw a ResourceNotFoundException. Mark - 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: Problem with #include file in index.apt.vm
How are you using Velocity? Are you using the singleton? A VelocityEngine? Are you using a servlet or a framework that handles Velocity for you? Is this a webapp? On Fri, May 29, 2009 at 11:26 AM, Nathan Sowatskey nsowa...@cisco.com wrote: Hi all I am trying to use this feature: http://velocity.apache.org/engine/devel/user-guide.html#Include I have this directive in an index.apt.vm file that is in src/site/apt: #include(user_stories_table.txt) I also have the user_stories_table.txt file in the same directory. The #include does not find the file. I have tried moving the file to various other locations, still won't find it. I have tried renaming the file to .vm in the apt dir, won't find it, I have tried I have also tried creating a velocity.properties file with various loader properties in it. But I don't know where to put the velocity.properties file so it is picked up, nor am I sure what the root of the relative paths will be, so I can't be sure what the property value should be. The error is below. Any help will be greatly appreciated! Many thanks Nathan When I run mvn site, I get: [ERROR] Cannot process content resource [ERROR] java.lang.NullPointerException at java.io.Reader.init(Reader.java:61) at java.io.InputStreamReader.init(InputStreamReader.java:80) at org.apache.velocity.runtime.resource.ContentResource.process(ContentResource .java:62) at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(Resour ceManagerImpl.java:415) at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(Resourc eManagerImpl.java:335) at org.apache.velocity.runtime.RuntimeInstance.getContent(RuntimeInstance.java: 1152) at org.apache.velocity.runtime.directive.Include.renderOutput(Include.java:225) -- Nathan Sowatskey (nsowa...@cisco.com) - Technical Leader, NMTG XMP - +34-638-083-675 - 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: Macros occasionally not parsing
I haven't seen this with 1.6.2, but none of my current projects are under any load (yet). Just to clarify, is the macro defined and used in the template or just used in the template? And for completeness, what are your macro settings? On Mon, May 18, 2009 at 12:58 PM, Will Glass-Husain wglasshus...@gmail.com wrote: Hi, I'm having problems with templates that are occasionally not parsing macros. The macro appears literally in the body of the result: #somemacro($argument) The error occurs under load in a webapp (e.g. when the same template is being retrieved simultaneously). I know it's not a template error since the same template will work fine in one call and then not run the macro in the next. I seem to remember this was an issue with early versions of Velocity, but I just upgraded to 1.6.2 and still see the problem. Anyone else see this issue? 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: Macros occasionally not parsing
Sorry, thought of a few more things to clarify... When the problem appears, you are actually seeing this in the output: #Dataset($decision, $decision, $GraphColorList.get(5), 2) Right? And this happens when the same template is being retrieved in multiple threads at the same time? And has/is the template been/being cached? I'm guessing no on the last one, but want to be sure. On Mon, May 18, 2009 at 1:25 PM, Will Glass-Husain wglasshus...@gmail.com wrote: Thanks, The macro is defined in the template. It looks like: #set($rounds = $currRound - 1) #macro(Dataset $decn $label $color $width) dataset seriesName=$label color=$color thickness=$width anchorBorderColor=$color #foreach($step in [0..$rounds]) set value='$Values.get($decn).getResult($step)'/ #end /dataset #end and the call like this: #Dataset($decision, $decision, $GraphColorList.get(5), 2) My macro option are: p.setProperty(velocimacro.library, macro_library.fml); p.setProperty(velocimacro.permissions.allow.inline.local.scope, true); p.setProperty(velocimacro.context.localscope, true); Let me know if you see anything useful. We originally had this problem under Velocity 1.5 so I upgraded to 1.6.2. I'll set up a test case under load, see if I can replicate it. WILL On Mon, May 18, 2009 at 1:06 PM, Nathan Bubna nbu...@gmail.com wrote: I haven't seen this with 1.6.2, but none of my current projects are under any load (yet). Just to clarify, is the macro defined and used in the template or just used in the template? And for completeness, what are your macro settings? On Mon, May 18, 2009 at 12:58 PM, Will Glass-Husain wglasshus...@gmail.com wrote: Hi, I'm having problems with templates that are occasionally not parsing macros. The macro appears literally in the body of the result: #somemacro($argument) The error occurs under load in a webapp (e.g. when the same template is being retrieved simultaneously). I know it's not a template error since the same template will work fine in one call and then not run the macro in the next. I seem to remember this was an issue with early versions of Velocity, but I just upgraded to 1.6.2 and still see the problem. Anyone else see this issue? 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 - 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: Problem with VM and caching
Would you mind opening a JIRA issue for this? It shouldn't throw an NPE if the IncludeEventHandler returns null. https://issues.apache.org/jira/browse/VELOCITY On Fri, May 15, 2009 at 9:53 AM, johann.we...@eventim.de wrote: I'm using the last one, 1.6.2. The problem is not the macro, I was wrong. The thing is, the file default.config is not available. In this case my IncludeEventHandler returns null (public String includeEvent(..) method) to keep the parsing process going. When I use the merge method with a list of macro libs, it throws a npe if the file doesn't exist and the IncludeEventHandler returns null. -Ursprüngliche Nachricht- Von: Nathan Bubna [mailto:nbu...@gmail.com] Gesendet: Fr 15.05.2009 18:17 An: Velocity Users List Betreff: Re: Problem with VM and caching What version of Velocity are you using? On Fri, May 15, 2009 at 4:04 AM, johann.we...@eventim.de wrote: It's a little bit strange... I have a #parse directive in my global lib.vm which causes an exception #macro(setGlobalConstants) #set($TEST = this is a constant var!) #parse(setup/default.config) #end If I set velocimacro.permissions.allow.inline.local.scope = true, I'll see this exception. If it's set to false, everything is fine. java.lang.NullPointerException at java.util.Hashtable.get(Hashtable.java:333) at org.apache.velocity.runtime.VelocimacroManager.getNamespace(VelocimacroManager.java:318) at org.apache.velocity.runtime.VelocimacroManager.get(VelocimacroManager.java:215) at org.apache.velocity.runtime.VelocimacroFactory.getVelocimacro(VelocimacroFactory.java:563) at org.apache.velocity.runtime.RuntimeInstance.getVelocimacro(RuntimeInstance.java:1563) at org.apache.velocity.runtime.directive.RuntimeMacro.render(RuntimeMacro.java:218) at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:175) at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336) at org.apache.velocity.runtime.directive.Parse.render(Parse.java:260) at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:175) at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336) at org.apache.velocity.Template.merge(Template.java:328) -Ursprüngliche Nachricht- Von: Nathan Bubna [mailto:nbu...@gmail.com] Gesendet: Freitag, 24. April 2009 15:37 An: Velocity Users List Betreff: Re: Problem with VM and caching Yes, you should still have access to global macros. By seems to be that i don't, do you mean that you tried it, and it didn't work? Or just that the docs are unclear? On Fri, Apr 24, 2009 at 6:31 AM, johann.we...@eventim.de wrote: If I set this property to true, do I have access to the global macros which were defined in VM_global_library.vm? It seems to be that I don't. Is there a way to access the global macros? -Ursprüngliche Nachricht- Von: Nathan Bubna [mailto:nbu...@gmail.com] Gesendet: Donnerstag, 23. April 2009 20:19 An: Velocity Users List Betreff: Re: Problem with VM and caching Keep your inline macros local: velocimacro.permissions.allow.inline.local.scope = true and in general, i'd recommend rereading the Velocimacro section of this: http://velocity.apache.org/engine/devel/developer-guide.html#Velocity_Configuration_Keys_and_Values On Thu, Apr 23, 2009 at 9:26 AM, johann.we...@eventim.de wrote: Hi all, I'm using 2 vm files : The first one, located in /example1/local.vm with #macro(Hello) Hello from example 1 #end And the second one in /example2/local.vm with #macro(Hello) Hello from example 2 #end One index.htm in both directories with #Hello Now, if I try to parse the /example1/index.htm via template.merge(context, velocityWriter, /example1/local.vm ) the output is Hello from example 1. The second call for /example2/index.htm template.merge(context, velocityWriter, /example2/local.vm ) returns Hello from example 2. But if I'm parsing the /example1/index.htm template.merge(context, velocityWriter, /example1/local.vm ) again, I'm getting Hello from example 2. It works correct if I turn off the loader cache. Any suggestions? Regards, Johann - 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 - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: Multi line text strings
#set ($rec = { 'Control' : Control1, 'CM' : 1. Do this 2. Do that 3. Do the other}) Or, using the EscapeTool, you could do: #set ($rec = { 'Control' : Control1, 'CM' : 1. Do this${esc.n}2. Do that${esc.n}3. Do the other}) On Thu, May 14, 2009 at 5:39 PM, Gary M. Catlin gcatli...@gmail.com wrote: Hello, I am looking to implement new lines within a text string to simulate separate paragraphs. In the code below, I am defining a local table structure with two columns; Control and CM. #set ($RecCMs = []) #set ($rec = { 'Control' : Control1, 'CM' : MyText1}) #set ($n = $RecCMs.add($rec)) #set ($rec = { 'Control' : Control2, 'CM' : Mytext2}) #set ($n = $RecCMs.add($rec)) I would like to replace the value of MyText1 with a multi line string, such as the following: 1. Do this 2. Do that 3. Do the other Eventually, I would like the entire content of $RecCMs.CM to be displayed in a table. ... td$RecCMs.CM/td ... How do I go about defining the text string so that new lines are observed? - 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: Escaping EL in JSTL
In the upcoming 1.7, you'll be able to do #[[c:if test=${ foo != null }]]# but for now, you have to use what we call poor man's escaping: #set( $D = '$' ) c:if test=$D{ foo != null} Of course, it's best if you can just set the $D reference globally in your context instead of every template. :) On Wed, May 13, 2009 at 10:41 AM, M. Tinnemeyer marc-...@gmx.net wrote: Ups the code was: c:if test=${ foo != null } ... /c:if On May 13, 2009, at 7:31 PM, M. Tinnemeyer wrote: Good evening, I use Velocity to generate several Jsp pages. This works quite well as long as I do not use EL expressions like: c:forEach items=${foo != null} var=bar ... /c:forEach I tried to escape the $ sign by using a backslash or but then Velocity stumbles upon !=. #set( $D = '$' ) like stated in the user-guide did not improve the situation. Does anybody have a clue on this ? Maybe there is a way to exclude a whole line from being parsed by Velocity ? Kind regards Marc Tinnemeyer - 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 - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: a problem to load a template in the same jar
If you are keeping your template in a jar, then you should use the ClasspathResourceLoader or the JarResourceLoader. On Thu, May 7, 2009 at 8:37 AM, liumin HU l...@sigems.fr wrote: hi, I have a problem to load a template.my situations is: I have a jar used in a wep app. In one method, It use velocity to generate a file with a template. this template is used only by this method. I need a absolute path for file_resource_loader_path, i dont know how to get it. i tried the template file in the root of jar or same level of my class file. velocity cant load it. and i think the other source loader is not for this situation. Am i wrong some where. please help me thanks in advance liu - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: resource.manager.defaultcache.size of 89 - any reason why?
I wasn't around for that, but i always imagined it was arbitrary. It's really the kind of thing that you should tune yourself, but some value was needed as the default. On Mon, May 11, 2009 at 12:50 PM, Matt Brown matt.br...@citrixonline.com wrote: When resource caching is enabled in Velocity, and the default cache (ResourceCacheImpl) is used, the default size of the LRU cache used (if not otherwise set) is 89. Just curious - anyone know how/why the value of 89 was chosen? Thanks - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: Download page refers to MD6 files - edit replace bug?
heh. that's amusing. thanks, for letting us know! i'll get it fixed. On Fri, May 8, 2009 at 9:57 AM, sebb seb...@gmail.com wrote: http://velocity.apache.org/download.cgi has a link to http://www.apache.org/dist/velocity/engine/1.6.2/velocity-1.6.2.zip.md6 likewise for tgz Looks like someone replaced 5 = 6 a bit too enthusiastically ... - 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: How to resolve error : Left side ($menuCurrentPage) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible.
On Thu, Apr 30, 2009 at 11:32 PM, RUPALI r.gup...@mpstechnologies.com wrote: Thanks, I noticed that we are using velocity-1.5 but velocity-tools-1.4 Can this make a difference too? Shall I change both the jars to the same version? no. the versions are not synchronized. i recommend Velocity 1.6.2 with either VelocityTools 1.4 or 2.0-beta3. -Rupali -Original Message- From: Nathan Bubna [mailto:nbu...@gmail.com] Sent: Thursday, April 30, 2009 7:19 PM To: Velocity Users List Subject: Re: How to resolve error : Left side ($menuCurrentPage) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible. On Wed, Apr 29, 2009 at 10:21 PM, RUPALI r.gup...@mpstechnologies.com wrote: I am using: Velocity: 1.5 I very much recommend upgrading to Velocity 1.6.2, as there were mountains of bugs fixed (including some race conditions) and major performance improvements. I would like to be sure that none of the fixed bugs are behind this. And what VelocityTools version are you using? Jetty: 6.1 JDK: 1.6 DB: SQL Server 2000 Struts 1.2.9 I get following kind of errors in log file: 2009-02-05 00:13:12,602 ERROR [btpool0-2] log.SimpleLog4JLogSystem (SimpleLog4JLogSystem.java:154) - Left side ($request.getParameter(test)) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible. /common/includes/ads/doubleclick.fhtml [line 86, column 38] 2009-02-05 00:13:36,100 ERROR [btpool0-2] log.SimpleLog4JLogSystem (SimpleLog4JLogSystem.java:154) - Left side ($request.getParameter(test)) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible. /common/includes/ads/doubleclick.fhtml [line 86, column 38] 2009-02-05 00:13:42,259 ERROR [btpool0-5] log.SimpleLog4JLogSystem (SimpleLog4JLogSystem.java:154) - ResourceManager : unable to find resource '/super/includes/super.before-doctype.fhtml' in any resource loader. 2009-02-05 00:13:42,260 ERROR [btpool0-5] log.SimpleLog4JLogSystem (SimpleLog4JLogSystem.java:154) - #parse(): cannot find template '/super/includes/super.before-doctype.fhtml', called from template /index.html at (2, 26) I've attached one of the files where the error occurs.. you can also review that. Thanks so much! Rupali -Original Message- From: Nathan Bubna [mailto:nbu...@gmail.com] Sent: Wednesday, April 29, 2009 7:29 PM To: Velocity Users List Subject: Re: How to resolve error : Left side ($menuCurrentPage) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible. Ok, it helps to know that you are using Struts 1 and VelocityTools. This means it is likely that you are not creating/managing your own Context object. Right? So how *are* you making data available to your templates? Where is the $currentMenuPage reference supposed to come from? Is it from a custom tool? If so, what scope is that tool? Are you putting values into the request attributes? Into the session attributes? Into the servlet context attributes? Or are you somehow grabbing the context and putting them in there. Your templates should all be thread safe insofar as they don't go around doing things like $application.setAttribute('foo','bar') (or similar things with $session or tools put in either of those scopes). Also, what version of Velocity are you using? On Wed, Apr 29, 2009 at 12:22 AM, RUPALI r.gup...@mpstechnologies.com wrote: Yes I am using Struts framework. (Struts 1.2.9) I am using velocity tools also. About thread safety, I am not sure how can I check this. But as this is an existing and big application, it must be working in thread safe manner.. Could you suggest me how to look for the thread safety for velocity files? -Original Message- From: Nathan Bubna [mailto:nbu...@gmail.com] Sent: Tuesday, April 28, 2009 7:21 PM To: Velocity Users List Subject: Re: How to resolve error : Left side ($menuCurrentPage) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible. Without knowing a lot more about how you populate and use your context, i'm really not sure. Are you using a framework? If so, which one? Are you using VelocityTools at all? Are you sure your context is being handled in a threadsafe manner? Velocity looks for references in the context it is given. It's mostly up to you to make sure that context is properly filled and used. On Mon, Apr 27, 2009 at 8:35 PM, RUPALI r.gup...@mpstechnologies.com wrote: Thanks Nathan, But how is this possible that the error goes on page refresh? And its not just for variable $menuCurrentPage, randomly the message generates for any variable and resolves on page refresh..?? -Original Message- From: Nathan Bubna [mailto:nbu...@gmail.com] Sent: Monday, April 27, 2009 7:17 PM To: Velocity Users List Subject: Re: How
Re: How to resolve error : Left side ($menuCurrentPage) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible.
On Wed, Apr 29, 2009 at 10:21 PM, RUPALI r.gup...@mpstechnologies.com wrote: I am using: Velocity: 1.5 I very much recommend upgrading to Velocity 1.6.2, as there were mountains of bugs fixed (including some race conditions) and major performance improvements. I would like to be sure that none of the fixed bugs are behind this. And what VelocityTools version are you using? Jetty: 6.1 JDK: 1.6 DB: SQL Server 2000 Struts 1.2.9 I get following kind of errors in log file: 2009-02-05 00:13:12,602 ERROR [btpool0-2] log.SimpleLog4JLogSystem (SimpleLog4JLogSystem.java:154) - Left side ($request.getParameter(test)) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible. /common/includes/ads/doubleclick.fhtml [line 86, column 38] 2009-02-05 00:13:36,100 ERROR [btpool0-2] log.SimpleLog4JLogSystem (SimpleLog4JLogSystem.java:154) - Left side ($request.getParameter(test)) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible. /common/includes/ads/doubleclick.fhtml [line 86, column 38] 2009-02-05 00:13:42,259 ERROR [btpool0-5] log.SimpleLog4JLogSystem (SimpleLog4JLogSystem.java:154) - ResourceManager : unable to find resource '/super/includes/super.before-doctype.fhtml' in any resource loader. 2009-02-05 00:13:42,260 ERROR [btpool0-5] log.SimpleLog4JLogSystem (SimpleLog4JLogSystem.java:154) - #parse(): cannot find template '/super/includes/super.before-doctype.fhtml', called from template /index.html at (2, 26) I've attached one of the files where the error occurs.. you can also review that. Thanks so much! Rupali -Original Message- From: Nathan Bubna [mailto:nbu...@gmail.com] Sent: Wednesday, April 29, 2009 7:29 PM To: Velocity Users List Subject: Re: How to resolve error : Left side ($menuCurrentPage) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible. Ok, it helps to know that you are using Struts 1 and VelocityTools. This means it is likely that you are not creating/managing your own Context object. Right? So how *are* you making data available to your templates? Where is the $currentMenuPage reference supposed to come from? Is it from a custom tool? If so, what scope is that tool? Are you putting values into the request attributes? Into the session attributes? Into the servlet context attributes? Or are you somehow grabbing the context and putting them in there. Your templates should all be thread safe insofar as they don't go around doing things like $application.setAttribute('foo','bar') (or similar things with $session or tools put in either of those scopes). Also, what version of Velocity are you using? On Wed, Apr 29, 2009 at 12:22 AM, RUPALI r.gup...@mpstechnologies.com wrote: Yes I am using Struts framework. (Struts 1.2.9) I am using velocity tools also. About thread safety, I am not sure how can I check this. But as this is an existing and big application, it must be working in thread safe manner.. Could you suggest me how to look for the thread safety for velocity files? -Original Message- From: Nathan Bubna [mailto:nbu...@gmail.com] Sent: Tuesday, April 28, 2009 7:21 PM To: Velocity Users List Subject: Re: How to resolve error : Left side ($menuCurrentPage) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible. Without knowing a lot more about how you populate and use your context, i'm really not sure. Are you using a framework? If so, which one? Are you using VelocityTools at all? Are you sure your context is being handled in a threadsafe manner? Velocity looks for references in the context it is given. It's mostly up to you to make sure that context is properly filled and used. On Mon, Apr 27, 2009 at 8:35 PM, RUPALI r.gup...@mpstechnologies.com wrote: Thanks Nathan, But how is this possible that the error goes on page refresh? And its not just for variable $menuCurrentPage, randomly the message generates for any variable and resolves on page refresh..?? -Original Message- From: Nathan Bubna [mailto:nbu...@gmail.com] Sent: Monday, April 27, 2009 7:17 PM To: Velocity Users List Subject: Re: How to resolve error : Left side ($menuCurrentPage) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible. Yes, it is a Velocity message. it means that in the template being processed at that time, there is no value for th $menuCurrentPage variable when it is being used in an #if( $menuCurrentPage == 'something' ) comparison (or an #elseif). On Sun, Apr 26, 2009 at 11:33 PM, RUPALI r.gup...@mpstechnologies.com wrote: Hi, The problem I am facing is that occasionally Resourcenotfound/unable to parse file error comes on the velocity pages which go on page refresh. The following error is shown in the server logs before
Re: A strange problem of ResourceNotFound
Since you are just passing a Reader directly to the evaluate() method, your VelocityEngine knows absolutely nothing about the path from which it came. So, how are you configuring the VelocityEngine instance you are using here (ve)? I don't see that code here. On Thu, Apr 30, 2009 at 5:45 AM, Manish prol...@gmx.net wrote: We are facing this strage problem in our code that uses standalone velocity engine. So far it did send the emails correctly from this standalone program running (this particular code doesn't reside under struts application) on our server. This is the part of teh code we use - String result = null; Reader r = null; StringWriter writer = null; try { writer = new StringWriter(); r = new BufferedReader(new FileReader(new File(RESOURCE_PATH, MAIL_TEMPLATE_FILE))); boolean status = ve.evaluate(context, writer, someEmail, r); if (!status) throw new RuntimeException(Error in evaluation: ); writer.close(); result = writer.toString(); } catch (ResourceNotFoundException e) { throw new RuntimeException(e); } catch (ParseErrorException e) { throw new RuntimeException(e); } catch (Exception e) { throw new RuntimeException(e); } finally { if (r!= null) try {r.close();} catch (IOException ioe) {}; if (writer != null) try {writer.close();} catch (IOException ioe) {}; } return result; Now this resource path is not changed in last 3 yeas and it's working fine and sending mails proeprly. Now the mail template (say someMail.vm) refers to 2 VTL files within itself to parse header and footer for this mail (say header.vm and footer.vm). So I have these two new lines added to the the VTL template - someMail.vm - #parse(header.vm) ... ... ... #parse(footer.vm) bother these header and footer reside in the same directory to which this RESOURCE_PATH points, the engine is able to parse the mail template correctly, but it is not able to parse gheader and footer and it fails with ResourceNotFoundException . I am wondering why and how can I fix this One obvious way is to add it to the mail template itself but I don't want to do that because header footer will be referred by other pages on site as well. Why this ResourceNotFoundException exception is thrown though both files reside in the same RESOURCE_PATH directory? How can I fix this? TIA, - Manish - 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: How to resolve error : Left side ($menuCurrentPage) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible.
Ok, it helps to know that you are using Struts 1 and VelocityTools. This means it is likely that you are not creating/managing your own Context object. Right? So how *are* you making data available to your templates? Where is the $currentMenuPage reference supposed to come from? Is it from a custom tool? If so, what scope is that tool? Are you putting values into the request attributes? Into the session attributes? Into the servlet context attributes? Or are you somehow grabbing the context and putting them in there. Your templates should all be thread safe insofar as they don't go around doing things like $application.setAttribute('foo','bar') (or similar things with $session or tools put in either of those scopes). Also, what version of Velocity are you using? On Wed, Apr 29, 2009 at 12:22 AM, RUPALI r.gup...@mpstechnologies.com wrote: Yes I am using Struts framework. (Struts 1.2.9) I am using velocity tools also. About thread safety, I am not sure how can I check this. But as this is an existing and big application, it must be working in thread safe manner.. Could you suggest me how to look for the thread safety for velocity files? -Original Message- From: Nathan Bubna [mailto:nbu...@gmail.com] Sent: Tuesday, April 28, 2009 7:21 PM To: Velocity Users List Subject: Re: How to resolve error : Left side ($menuCurrentPage) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible. Without knowing a lot more about how you populate and use your context, i'm really not sure. Are you using a framework? If so, which one? Are you using VelocityTools at all? Are you sure your context is being handled in a threadsafe manner? Velocity looks for references in the context it is given. It's mostly up to you to make sure that context is properly filled and used. On Mon, Apr 27, 2009 at 8:35 PM, RUPALI r.gup...@mpstechnologies.com wrote: Thanks Nathan, But how is this possible that the error goes on page refresh? And its not just for variable $menuCurrentPage, randomly the message generates for any variable and resolves on page refresh..?? -Original Message- From: Nathan Bubna [mailto:nbu...@gmail.com] Sent: Monday, April 27, 2009 7:17 PM To: Velocity Users List Subject: Re: How to resolve error : Left side ($menuCurrentPage) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible. Yes, it is a Velocity message. it means that in the template being processed at that time, there is no value for th $menuCurrentPage variable when it is being used in an #if( $menuCurrentPage == 'something' ) comparison (or an #elseif). On Sun, Apr 26, 2009 at 11:33 PM, RUPALI r.gup...@mpstechnologies.com wrote: Hi, The problem I am facing is that occasionally Resourcenotfound/unable to parse file error comes on the velocity pages which go on page refresh. The following error is shown in the server logs before the logging of resourcenotfound exception: Left side ($menuCurrentPage) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible. Is something related to the velocity engine here? The problem is occurring right now only on staging site of my website, and thankfully is not on Live. But it is happening a lot of times on staging and is becoming troublesome Thanks, Rupali - 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 - 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 - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: How to resolve error : Left side ($menuCurrentPage) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible.
Without knowing a lot more about how you populate and use your context, i'm really not sure. Are you using a framework? If so, which one? Are you using VelocityTools at all? Are you sure your context is being handled in a threadsafe manner? Velocity looks for references in the context it is given. It's mostly up to you to make sure that context is properly filled and used. On Mon, Apr 27, 2009 at 8:35 PM, RUPALI r.gup...@mpstechnologies.com wrote: Thanks Nathan, But how is this possible that the error goes on page refresh? And its not just for variable $menuCurrentPage, randomly the message generates for any variable and resolves on page refresh..?? -Original Message- From: Nathan Bubna [mailto:nbu...@gmail.com] Sent: Monday, April 27, 2009 7:17 PM To: Velocity Users List Subject: Re: How to resolve error : Left side ($menuCurrentPage) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible. Yes, it is a Velocity message. it means that in the template being processed at that time, there is no value for th $menuCurrentPage variable when it is being used in an #if( $menuCurrentPage == 'something' ) comparison (or an #elseif). On Sun, Apr 26, 2009 at 11:33 PM, RUPALI r.gup...@mpstechnologies.com wrote: Hi, The problem I am facing is that occasionally Resourcenotfound/unable to parse file error comes on the velocity pages which go on page refresh. The following error is shown in the server logs before the logging of resourcenotfound exception: Left side ($menuCurrentPage) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible. Is something related to the velocity engine here? The problem is occurring right now only on staging site of my website, and thankfully is not on Live. But it is happening a lot of times on staging and is becoming troublesome Thanks, Rupali - 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 - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: How to resolve error : Left side ($menuCurrentPage) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible.
Yes, it is a Velocity message. it means that in the template being processed at that time, there is no value for th $menuCurrentPage variable when it is being used in an #if( $menuCurrentPage == 'something' ) comparison (or an #elseif). On Sun, Apr 26, 2009 at 11:33 PM, RUPALI r.gup...@mpstechnologies.com wrote: Hi, The problem I am facing is that occasionally Resourcenotfound/unable to parse file error comes on the velocity pages which go on page refresh. The following error is shown in the server logs before the logging of resourcenotfound exception: Left side ($menuCurrentPage) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible. Is something related to the velocity engine here? The problem is occurring right now only on staging site of my website, and thankfully is not on Live. But it is happening a lot of times on staging and is becoming troublesome Thanks, Rupali - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: Facing Issues with velocity sortTool to sort Two java.util.Date Type
If there is an exception (like a NullPointerException) during sorting, then SortTool will return null. The null field is apparently causing an exception. I'm not sure why, but i would guess that it is because the java.util.Date class' compareTo method doesn't like it when you pass in null as an argument. SortTool never calls compareTo on a null object, but it will pass null objects in to compareTo (e.g. myNotNullComparable.compareTo(nullComparable) ). That's the best guess i have for you. You might try subclassing SortTool to right your own sort method that can handle this situation. or just making your Note class comparable and doing $sorter.sort(${notes}). On Thu, Apr 23, 2009 at 6:04 AM, Ranjeet ranjeet@ebusinessware.com wrote: Hi, I have a DTO Note.java in which there are some porperty like createdAt and updatedAt of java.util.Date type. I want to sort the order of list by updatedAt and createdAt. When I create the note/entity on that time I set java.util.Date() in createdAt property and not set in updatedAt so updatedAt property is null in db and dto both at very first, when I am going to update the same note/entity on that time I set the java.util.Date in updatedAt property and update the entity then both property becomes not null, means some values in dto and table. Now I want to sort the order of list by updatedAt and createdAt so recent updated record should come on top and want to shwo only recent five records only. If updatedAt and createdAt property is not null then works fine. for example if there is 3 record and 2 note/entity are updated and one is not updated, means in list of 3 dto , 2 dto have values in updatedAt and in one DTO the value in updatedAt is null, in this scenario not sorting and not displaying the records. I mean if any of the updatedAt property is null in dto list then not display the record,. I could not find the solution why this is not displaying while sorting? Thanks Regards, Ranjeet - Original Message - From: Nathan Bubna nbu...@gmail.com To: Velocity Users List user@velocity.apache.org Sent: Wednesday, April 22, 2009 11:56 PM Subject: Re: Facing Issues with velocity sortTool to sort Two java.util.Date Type Could you be more specific about what you mean by not working? What happens? The code sample looks like you are already implementing the search pattern you want. Why not just try: $sorter.sort(${campaign.notes}) On Mon, Apr 20, 2009 at 3:42 AM, Ranjeet ranjeet@ebusinessware.com wrote: Hi All, I am using velocity 1.5 sortTool to sort the properties of list. I am sorting two date, createdAt and updatedAt both property of dto are java.util.Date type. I am trying to sort on updatedAt first and if updatedAt is null then on createdAt. Its working fine if there is some value in updatedAt, but its not working if updatedAt has null value. Please help me out of this problem. code sample is attached with this mail. Thanks Regards, Ranjeet - 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 - 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: Problem with VM and caching
Keep your inline macros local: velocimacro.permissions.allow.inline.local.scope = true and in general, i'd recommend rereading the Velocimacro section of this: http://velocity.apache.org/engine/devel/developer-guide.html#Velocity_Configuration_Keys_and_Values On Thu, Apr 23, 2009 at 9:26 AM, johann.we...@eventim.de wrote: Hi all, I'm using 2 vm files : The first one, located in /example1/local.vm with #macro(Hello) Hello from example 1 #end And the second one in /example2/local.vm with #macro(Hello) Hello from example 2 #end One index.htm in both directories with #Hello Now, if I try to parse the /example1/index.htm via template.merge(context, velocityWriter, /example1/local.vm ) the output is Hello from example 1. The second call for /example2/index.htm template.merge(context, velocityWriter, /example2/local.vm ) returns Hello from example 2. But if I'm parsing the /example1/index.htm template.merge(context, velocityWriter, /example1/local.vm ) again, I'm getting Hello from example 2. It works correct if I turn off the loader cache. Any suggestions? Regards, Johann - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: Velocity page caching problem
On Tue, Apr 21, 2009 at 5:47 AM, Doug Carter dcar...@mercycorps.org wrote: On Mon, Apr 20, 2009 at 07:58:59PM -0700, Nathan Bubna wrote: On Mon, Apr 20, 2009 at 4:38 PM, Doug Carter dcar...@mercycorps.org wrote: On Mon, Apr 20, 2009 at 02:33:50PM -0700, Nathan Bubna wrote: On Mon, Apr 20, 2009 at 1:09 PM, Doug Carter dcar...@mercycorps.org wrote: #snip When I update/write/save a velocity source page, the page will not refresh in my browser, it remains unchanged. If I save out the source file a few times, it works. #snip webapp.resource.loader.cache = false Thanks for the quick response. I tried this and it didn't make any difference. I thought it might be related to ModJK, so I went directly to Tomcat, but had the same problem. #snip I did as you suggested and it is reading the velosurf.properties file. Adding webapp.resource.loader.cache = false, seemed to help a little, but there are still times that it fails. Could this be related to the time settings on server versus the PC (where the browser runs)? velosurf.properties? was that a typo? looks like it's using /WEB-INF/velocity.properties anyway, it's difficult to guess what is happening, in part because your description varies. first, it takes a few save outs to get it to refresh. is that because of the time it takes to do the saves? or the saves themselves? then you first say setting webapp.resource.loader.cache=false doesn't make a difference, then next it seems to help. it would be good to have more precise information. if setting the w.r.l.c=false changes things, *how* does it change things? What are you seeing happen? Below is my catalina.out. #snip INFO: Velocity [info] VelocityViewServlet: Using custom properties at '/WEB-INF/velocity.properties' Apr 21, 2009 5:34:39 AM org.apache.catalina.core.ApplicationContext log INFO: Velocity [info] ** Apr 21, 2009 5:34:39 AM org.apache.catalina.core.ApplicationContext log INFO: Velocity [info] Starting Jakarta Velocity v1.4 #snip INFO: Velocity [info] Resource Loader Instantiated: org.apache.velocity.tools.view.servlet.WebappLoader Apr 21, 2009 5:34:39 AM org.apache.catalina.core.ApplicationContext log INFO: Velocity [debug] WebappLoader : initialization starting. Apr 21, 2009 5:34:39 AM org.apache.catalina.core.ApplicationContext log INFO: Velocity [info] WebappLoader : added template path - '/' Apr 21, 2009 5:34:39 AM org.apache.catalina.core.ApplicationContext log INFO: Velocity [debug] WebappLoader : initialization complete. Apr 21, 2009 5:34:39 AM org.apache.catalina.core.ApplicationContext log INFO: Velocity [info] ResourceCache : initialized. (class org.apache.velocity.runtime.resource.ResourceCacheImpl) Apr 21, 2009 5:34:39 AM org.apache.catalina.core.ApplicationContext log INFO: Velocity [info] Default ResourceManager initialization complete. Apr 21, 2009 5:34:39 AM org.apache.catalina.core.ApplicationContext log #snip INFO: Server startup in 4204 ms this is only log output for startup. can i see logs for what happens when you request a template, change it, then request it again? (or some similar set of actions that shows the problem) - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: Velocity page caching problem
On Wed, Apr 22, 2009 at 11:33 AM, Doug Carter dcar...@mercycorps.org wrote: Nathan, velosurf.properties? was that a typo? looks like it's using /WEB-INF/velocity.properties Typo. anyway, it's difficult to guess what is happening, in part because your description varies. first, it takes a few save outs to get it to refresh. is that because of the time it takes to do the saves? or the saves themselves? then you first say setting webapp.resource.loader.cache=false doesn't make a difference, then next it seems to help. it would be good to have more precise information. if setting the w.r.l.c=false changes things, *how* does it change things? What are you seeing happen? I'm sorry about the lousy feedback and variable responses. I know how difficult it is to problem solve with crappy data. I've got several webapps running together on a dev server, trying to juggle too many problems at one time. This is not the way to fix it. this is only log output for startup. can i see logs for what happens when you request a template, change it, then request it again? (or some similar set of actions that shows the problem) I need to setup a dedicated debug environment for this, turn on some logging, etc. and remove all the unnecessary variables, so I stop wasting your time. This may not even be a Tomcat problem. First, I checked my disk cache in Firefox for a test page: Last modified: 2009-04-22 11:20:14 Expires: 1969-12-31 16:00:00 As a simple test, I modified the test page, setting border=1 on a table, then saved it, and did a stat on the source file: Access: 2009-04-22 11:21:35.0 -0700 Modify: 2009-04-22 11:21:35.0 -0700 Change: 2009-04-22 11:21:35.0 -0700 So, the file is *newer* on server disk than the last modified cache date on the PC disk. I refresh the page, and the table border does not come on, meaning that the file was not read. If I check the Firefox cache, it shows: Last modified: 2009-04-22 11:21:50 Expires: 1969-12-31 16:00:00 So, I have to assume that something is caching this page within the server. But this is still all anecdotal. I'll setup a better test environment, with a standalone Tomcat instance and a single test page. The only thing I'm unsure of, is the level and type of logging. Is there something specific that can show cache info? I'd rather do a controlled experiment that can give you actionable data. In a simplified test environment, it should be manageable to have the log level set to debug. And using log4j should give the most control. The ServletLogger is a bit noisy. Also, if you are going to set up a test for this, as you describe, then once you have reproduced the problem and tried what we've discussed thus far, consider trying it again with Velocity 1.6.2 there have been a variety of fixes and improvements in the resource management code (and in logging, for more useful output). Thanks again for your time, Doug - 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: Velocity page caching problem
On Mon, Apr 20, 2009 at 1:09 PM, Doug Carter dcar...@mercycorps.org wrote: Hi all, I'm running: Tomcat 5.5.23, ModJK 1.2.2, Java 1.6.07, Apache 2.0.52, CentOS 4.7, VelocityToolsView 1.4, VelocityDep 1.4. I've been using Tomcat/Velocity for many years, and have written many applications. I've put up with an annoying behavior for too long. When I update/write/save a velocity source page, the page will not refresh in my browser, it remains unchanged. If I save out the source file a few times, it works. I always use these property settings in velocity.properties: --- resource.loader = webapp webapp.resource.loader.class = org.apache.velocity.tools.view.servlet.WebappLoader webapp.resource.loader.path = / # for development mode...allow macros to be re-loaded when changed. file.resource.loader.cache = false this is pointless, since you aren't using a resource.loader with the key file. try: webapp.resource.loader.cache = false velocimacro.library.autoreload = true velocimacro.permissions.allow.inline.to.replace.global = true --- Anyone else have this problem or know what to do about it? TIA, Doug - 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: Velocity page caching problem
On Mon, Apr 20, 2009 at 4:38 PM, Doug Carter dcar...@mercycorps.org wrote: On Mon, Apr 20, 2009 at 02:33:50PM -0700, Nathan Bubna wrote: On Mon, Apr 20, 2009 at 1:09 PM, Doug Carter dcar...@mercycorps.org wrote: Hi all, I'm running: Tomcat 5.5.23, ModJK 1.2.2, Java 1.6.07, Apache 2.0.52, CentOS 4.7, VelocityToolsView 1.4, VelocityDep 1.4. I've been using Tomcat/Velocity for many years, and have written many applications. I've put up with an annoying behavior for too long. When I update/write/save a velocity source page, the page will not refresh in my browser, it remains unchanged. If I save out the source file a few times, it works. I always use these property settings in velocity.properties: --- resource.loader = webapp webapp.resource.loader.class = org.apache.velocity.tools.view.servlet.WebappLoader webapp.resource.loader.path = / # for development mode...allow macros to be re-loaded when changed. file.resource.loader.cache = false this is pointless, since you aren't using a resource.loader with the key file. try: webapp.resource.loader.cache = false Thanks for the quick response. I tried this and it didn't make any difference. I thought it might be related to ModJK, so I went directly to Tomcat, but had the same problem. I tried different browsers, didn't make a difference. The browser and the server are running on different machine cause this? I'm at a loss. Anything else that I could try? yeah. time to look at the log output first and make sure that your velocity.properties are being loaded. even if at first glance at the logs it looks like they are, try changing something that would break it (like webapp.resource.loader.path=/foo/) and make sure it breaks. If it breaks, then change it back to what you want, fire it up and send the log output this way, so i can take a look. Thanks again, Doug velocimacro.library.autoreload = true velocimacro.permissions.allow.inline.to.replace.global = true --- Anyone else have this problem or know what to do about it? TIA, Doug - 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 - 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: What does vm stand for?
As far as i know, it comes from the fact that Velocity was started as an Apache licensed alternative to WebMacro's templates which always had the suffix wm. I imagine, naming Velocity templates with the vm suffix made more sense then. These days, i think vtl is more sensible, but old conventions die hard. :) On Wed, Apr 15, 2009 at 9:41 AM, Dabir, Kunal kunal_da...@syntelinc.com wrote: Velocity template files usually end with extension .vm (I know its not necessary), just out of curiosity i wanted to know what actually vm stands for? Regards, Kunal Confidential: This electronic message and all contents contain information from Syntel, Inc. which may be privileged, confidential or otherwise protected from disclosure. The information is intended to be for the addressee only. If you are not the addressee, any disclosure, copy, distribution or use of the contents of this message is prohibited. If you have received this electronic message in error, please notify the sender immediately and destroy the original message and all copies. - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: Using Velocity only for scripting purposes
On Tue, Apr 7, 2009 at 11:17 AM, MS79 shapi...@gmail.com wrote: The application I'm working on currently uses Velocity for simple template processing; some forms, extract data, etc. In response to trying to meet a business need of a client, it was proposed that we use Velocity basically as an engine to allow users of the system to write custom logic in the system. This include statement logic and setting values on objects passed it (which would later be persisted to a database). No actual template processing would be done, it is essentially only used to set values on an object. ugh. While it would (and in fact, does) work, it just feels horribly wrong, especially when we have another engine hooked into the system to allow custom rule writing. Am I just being overly sensitive to the use of Velocity here, or are there any other downfalls that this implementation may have that we should be aware of. that would feel quite wrong to me too. Velocity is for templates, not scripting. Using VTL as a scripting language is like trying to pound in a nail with a screwdriver. It might work, but it ain't a good way to get the job done. Volume is supposed to be fairly low (at least as far as I've been told) and the templates would not be very complex. You say that now, but plans change. Shortcuts like this tend to hurt in the long run. You'll still use more memory than you need to, maybe more CPU too. And you'll definitely be working with a crippled scripting language, so your scripts are likely to end up ugly and hard to maintain despite your intentions. Thanks, Mark -- View this message in context: http://www.nabble.com/Using-Velocity-only-for-scripting-purposes-tp22935096p22935096.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: Null Reference I don't understand
Are you sure that getUSFormattedTn() is declared public and that TelephoneNumber is a public class? If so, double check directly that tn is in the context and is the expected class by doing $tn.class right before or after the call to $tn.USFormattedTn. If all above checks out, you might as well try $tn.getUSFormattedTn() just to make sure there isn't some property-method mapping issue. If you still can't figure it out, write back confirming the above and also let us know which version of Velocity you are using. On Mon, Apr 6, 2009 at 7:04 AM, Steve Cohen sco...@javactivity.org wrote: I am making a reference from a template that isn't working and, based on what I see in my logs, it makes no sense to me. Here is the template: Thank you. Your new phone number is $tn.USFormattedTn $tn is an object of class TelephoneNumber. TelephoneNumber has a method String getUSFormattedTn(); The expected output here is Thank you. Your new phone number is 1-555-355- Instead user sees Thank you. Your new phone number is $tn.USFormattedTn TelephoneNumber.toString() in returns the string representation without the preceding 1- country code, in this case, 555-355- In the following log fragments, this is what appears, it is just showing the toString() output, which shows that tn is not null when passed to the template, it does not mean that we are passing the string representation to the template.. 2009-04-01 15:15:59,750 [robo/191312] INFO number.NumberModel - COMPLETE: number 555-355- has been provisioned. 2009-04-01 15:15:59,750 [robo/191312] DEBUG bot.RelayRobot - phone order status: ExitComplete 2009-04-01 15:15:59,750 [robo/191312] TRACE velocity.VelociWrapper - {tn=555-355-, lang=English} 2009-04-01 15:15:59,751 [robo/191312] DEBUG Velocity - ResourceManager : found /resources/en_US/number/ExitComplete.vm with loader org.apache.velocity.tools.view.servlet.WebappLoader 2009-04-01 15:15:59,753 [robo/191312] DEBUG Velocity - Null reference [template '/resources/en_US/number/ExitComplete.vm', line 6, column 56] : $tn.USFormattedTn cannot be resolved. I really don't understand what's going on here. The object is non-null when passed to the template. I don't see where the null reference could be coming from. There are no obvious threading issues that I can see, either. Additionally, I have other templates which use this method reference in the exact same way, with no issues. Can someone suggest a path forward to understanding what is going on here? Thank you. - 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: Null Reference I don't understand
Both should work. We've always allowed $bar.getFoo() to be referenced as $bar.foo or $bar.Foo But you're right. It would be good to confirm whether $tn.uSFormattedTn works, just to make sure something wasn't broken in the release being used. On Mon, Apr 6, 2009 at 10:01 AM, Raymond Auge ra...@liferay.com wrote: Also, wouldn't the naming rules imply that method getUSFormattedTn() be referenced as property uSFormattedTn? Ray On Mon, 2009-04-06 at 07:14 -0700, Nathan Bubna wrote: Are you sure that getUSFormattedTn() is declared public and that TelephoneNumber is a public class? If so, double check directly that tn is in the context and is the expected class by doing $tn.class right before or after the call to $tn.USFormattedTn. If all above checks out, you might as well try $tn.getUSFormattedTn() just to make sure there isn't some property-method mapping issue. If you still can't figure it out, write back confirming the above and also let us know which version of Velocity you are using. On Mon, Apr 6, 2009 at 7:04 AM, Steve Cohen sco...@javactivity.org wrote: I am making a reference from a template that isn't working and, based on what I see in my logs, it makes no sense to me. Here is the template: Thank you. Your new phone number is $tn.USFormattedTn $tn is an object of class TelephoneNumber. TelephoneNumber has a method String getUSFormattedTn(); The expected output here is Thank you. Your new phone number is 1-555-355- Instead user sees Thank you. Your new phone number is $tn.USFormattedTn TelephoneNumber.toString() in returns the string representation without the preceding 1- country code, in this case, 555-355- In the following log fragments, this is what appears, it is just showing the toString() output, which shows that tn is not null when passed to the template, it does not mean that we are passing the string representation to the template.. 2009-04-01 15:15:59,750 [robo/191312] INFO number.NumberModel - COMPLETE: number 555-355- has been provisioned. 2009-04-01 15:15:59,750 [robo/191312] DEBUG bot.RelayRobot - phone order status: ExitComplete 2009-04-01 15:15:59,750 [robo/191312] TRACE velocity.VelociWrapper - {tn=555-355-, lang=English} 2009-04-01 15:15:59,751 [robo/191312] DEBUG Velocity - ResourceManager : found /resources/en_US/number/ExitComplete.vm with loader org.apache.velocity.tools.view.servlet.WebappLoader 2009-04-01 15:15:59,753 [robo/191312] DEBUG Velocity - Null reference [template '/resources/en_US/number/ExitComplete.vm', line 6, column 56] : $tn.USFormattedTn cannot be resolved. I really don't understand what's going on here. The object is non-null when passed to the template. I don't see where the null reference could be coming from. There are no obvious threading issues that I can see, either. Additionally, I have other templates which use this method reference in the exact same way, with no issues. Can someone suggest a path forward to understanding what is going on here? Thank you. - 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 -- Raymond Augé Senior Software Engineer Liferay, Inc. Enterprise. Open Source. For Life. -- Liferay East Coast User Conference 2009 May 21, 2009 Reston, Virginia www.liferay.com/events/ecuc09 - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: Null Reference I don't understand
On Mon, Apr 6, 2009 at 3:49 PM, Steve Cohen sco...@javactivity.org wrote: Nathan Bubna wrote: Are you sure that getUSFormattedTn() is declared public and that TelephoneNumber is a public class? Yes. If so, double check directly that tn is in the context The log file entry below confirms that. and is the expected class by doing $tn.class right before or after the call to $tn.USFormattedTn. Not sure what you meant by doing $tn.class. Were you talking about a temporary test that displays the class? If all above checks out, you might as well try $tn.getUSFormattedTn() just to make sure there isn't some property-method mapping issue. In any case, I revised the template to read as follows for experimental purposes: Thank you. Your phone number is b$tn.USFormattedTn/b Thank you. Your phone number is b$tn.uSFormattedTn/b Thank you. Your phone number is b$tn.getUSFormattedTn()/b $tn.class which produced this output: Thank you. Your phone number is 1-888-888- Thank you. Your phone number is 1-888-888- Thank you. Your phone number is 1-888-888- class com.foo.bar.data.pojos.TelephoneNumber In other words, yes, the object passed to the template was of the expected class and no, I wasn't able to reproduce the problem. If you still can't figure it out, write back confirming the above and also let us know which version of Velocity you are using. Hmm, could that be the issue? The production system where the problem occurred is using 1.6.1. The development version (where I can't reproduce the problem) uses 1.6.2. Since we will be using 1.6.2 in production soon, if that is the case, it might solve the problem. There were reflection related fixes between 1.6.1 and 1.6.2 (VELOCITY-701 VELOCITY-689) On Mon, Apr 6, 2009 at 7:04 AM, Steve Cohen sco...@javactivity.org wrote: I am making a reference from a template that isn't working and, based on what I see in my logs, it makes no sense to me. Here is the template: Thank you. Your new phone number is $tn.USFormattedTn $tn is an object of class TelephoneNumber. TelephoneNumber has a method String getUSFormattedTn(); The expected output here is Thank you. Your new phone number is 1-555-355- Instead user sees Thank you. Your new phone number is $tn.USFormattedTn TelephoneNumber.toString() in returns the string representation without the preceding 1- country code, in this case, 555-355- In the following log fragments, this is what appears, it is just showing the toString() output, which shows that tn is not null when passed to the template, it does not mean that we are passing the string representation to the template.. 2009-04-01 15:15:59,750 [robo/191312] INFO number.NumberModel - COMPLETE: number 555-355- has been provisioned. 2009-04-01 15:15:59,750 [robo/191312] DEBUG bot.RelayRobot - phone order status: ExitComplete 2009-04-01 15:15:59,750 [robo/191312] TRACE velocity.VelociWrapper - {tn=555-355-, lang=English} 2009-04-01 15:15:59,751 [robo/191312] DEBUG Velocity - ResourceManager : found /resources/en_US/number/ExitComplete.vm with loader org.apache.velocity.tools.view.servlet.WebappLoader 2009-04-01 15:15:59,753 [robo/191312] DEBUG Velocity - Null reference [template '/resources/en_US/number/ExitComplete.vm', line 6, column 56] : $tn.USFormattedTn cannot be resolved. I really don't understand what's going on here. The object is non-null when passed to the template. I don't see where the null reference could be coming from. There are no obvious threading issues that I can see, either. Additionally, I have other templates which use this method reference in the exact same way, with no issues. Can someone suggest a path forward to understanding what is going on here? Thank you. - 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 - 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: Inserting large text directly into the output
Pre-1.6 versions of Velocity always use toString() for references, without exception. So in a pre-1.6 situation, you pretty much have to create a custom directive to do something like this. With 1.6, though, we've introduced the Renderable interface: http://velocity.apache.org/engine/releases/velocity-1.6.2/apidocs/index.html If a reference implements this, then the render(Context,Writer) method is used. So, now you can go either way, and creating an object that uses Renderable to get at the writer is probably going to be easier than a custom directive. On Thu, Apr 2, 2009 at 8:40 PM, Daniel Noll dan...@nuix.com wrote: Hi all. I have some amount of text which won't necessarily fit in memory (to be more precise, it normally does, but there is a requirement that it not be truncated, no matter what.) Additionally, our framework for this works more efficiently if we can avoid using a Reader, and write directly to the destination Writer. So: 1. Is there some way that a template can call one of our methods, and our method can somehow get a reference to the Writer and write whatever it wants? 2. Failing that, is there some way to tell Velocity to insert the contents of a Reader directly into the output from the template, using a single template call? Or should I be taking some other approach to this, such as leaving a marker of some sort in the destination file, and then performing a second round of processing to get the text in there? Daniel -- Daniel Noll Forensic and eDiscovery Software Senior Developer The world's most advanced Nuix email data analysis http://nuix.com/ and eDiscovery software - 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: upstream object changes
On Thu, Apr 2, 2009 at 9:16 AM, Raymond Auge ra...@liferay.com wrote: Hey All, I need to push some details up the processing chain. If I inject an object like a Map into the context, and from within VTL call add(Object o) on it, shouldn't this change be visible from outside the context, once execution of the template is done? Yes. The use case is tagging. Our application has several tier of content processing. - servlet - theme - N portlets - CMS content Only the servlet has access to write tags into the meta fields of the page, but N CMS contents and other objects have tags for inclusion. The issue is that for a couple reason we don't pass the real request object all the way through to the CMS processing. BUT, I want to enable CMS template developers to have the ability to submit tags programatically. So, I'd like to provide something like: #set ($VOID = $tags.add(...)) I'm confused; is $tags the HashMapString,String in question? If so, there's no add(String) method, only put(String,String). These would get collected post template into the actual request and at the servlet level verified and added to the meta information of the page. But, my initial tests aren't working, so either I'm doing something wrong (it's just a HashMapString, String that I'm using) or it's not possible. There's always crude debugging right there in the template. Make sure that $tags is present and of the expected type first, then be sure the method call worked. $tags.class $tags.get(...) If all that works in the template, but you still aren't seeing the result upstream, ping back. -- Raymond Augé Senior Software Engineer Liferay, Inc. Enterprise. Open Source. For Life. -- Liferay East Coast User Conference 2009 May 21, 2009 Reston, Virginia www.liferay.com/events/ecuc09 - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: Need help with $velocityHasNext macro
Which version of Velocity? $velocityHasNext doesn't work right in 1.6 and is absent in earlier versions. You should use 1.6.2. On Tue, Mar 31, 2009 at 8:34 AM, Steve Cohen sco...@javactivity.org wrote: Given this macro, which will only be called with lists of size =2 and whose members are Strings representing dates #if ( $list.size() == 2) #foreach( $member in $list )#if( $velocityHasNext )${member}#else and ${member}#end#end #else #foreach( $member in $list )#if( $velocityHasNext )${member}, #else and ${member}#end#end #end I was expecting output of Mar 30, 2009 and Mar 31, 2009 Instead, I am getting Mar 30, 2009Mar 31, 2009 This result makes no sense to me, unless I am misunderstanding the use of $velocityHasNext. Can someone tell me what I am doing wrong? Thanks. - 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: Generic tools
Are you referring to Java generics? Or VelocityTools' GenericTools library? I'm guessing the the former, as that makes more sense of your question. Remember that Java uses generic types at compile time, then erases them: http://java.sun.com/docs/books/tutorial/java/generics/erasure.html Since Velocity runs off of runtime reflection, generic info isn't available. This means methods that take or return generic types work fine, but lack the compile-time type-checking. So, you will be able to call them with wrong generic types too, which may then lead to ClassCastExceptions. So, yeah, it'll work, but Velocity knows nothing of the generic types, so you should be as careful about types and casting as you would if those methods didn't use generics. On Mon, Mar 23, 2009 at 10:22 AM, Raymond Auge ra...@liferay.com wrote: Hey guys, Generic tools are fine right? Vel. Ver. 1.6 i.e. we have an ArrayUtil which has generic methods. Should I anticipate problems? -- Raymond Augé Senior Software Engineer Liferay, Inc. Enterprise. Open Source. For Life. - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: Multiple Velocity starts in log
On Mon, Mar 16, 2009 at 8:36 AM, Steven Weiss swe...@iafrica.com wrote: Hi, I have upgraded to version 1.6.1. I've noticed in the tomcat logs that velocity tries to initialize itself a number of times. Sometimes within seconds of itself, Sometimes hours. Anyone have any ideas? Not with that tiny bit of info. Are you using the Velocity singleton or VelocityEngine? Are you sure it's not just Tomcat restarting your whole app? Is there any library in your app that uses Velocity? What version did you upgrade from? 1.6? 1.5? 1.4? 1.3.1? What are you using Velocity for? Can you tell from your logs if both startups are using the same velocity.properties? Can you tell what your app is doing when it init's itself? (may tell you where the second instance is) Bottom line, a single Velocity runtime cannot be restarted. So, either the classloader is being dumped and the whole app re-started (which i hope you would notice), or else there are multiple runtimes in play. But there's no way for us to guess where just by knowing you upgraded to the latest version from some mysterious version. ;) Rgeards Steven - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: How to call a method without printing its return value?
2009/3/17 bluejoe bluejoe2...@gmail.com: Hi, all. How to call a method without printing its return value? For example, I define a class MyList, which has a method: public MyList add(String e); In my template, when I write: $list.add(a).add(b)... When rendered, the method will be called, but the value returned will be also printed unexpectedly. To hide the output, now I have to write codes as below: #set($___TEMP___ = $list.add(a).add(b)) It solves my problem, but I want to know if there is any better way? i usually take this as a hint that i'm doing something that i probably shouldn't be doing in a template. and when i decide to be lazy and still do it in a template anyway, i use either your workaround or Christoph's. -bluejoe - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: Does velocity engine supports I18N ?
The ResourceTool is a generic tool. It is meant for offline use. Just drop the generic jar in your app, and put an instance of the ResourceTool in your context and it will look for and use a resources.properties in the root of the classpath (unless you call a method that specifies a different bundle). If you want to change the default bundle, call setDefaultBundle. Pretty straightforward. The MultiViewsTool currently has no support for offline use. In its current incarnation, Servlet classes are required. If you'd like to change that, patches are welcome. :) It's a tool whose original contributor has gone away, so it doesn't get much attention. On Sun, Mar 15, 2009 at 7:33 PM, Preetam Palwe preet...@aftek.com wrote: Thanks Nathan I want to use ResourceTool / MultiviewsTool from VelocityTools in offline mode (plan java classes no servlets , struts) Could you please help me to understand how can I use velocity tools in offline mode. -Original Message- From: Nathan Bubna [mailto:nbu...@gmail.com] Sent: Saturday, March 14, 2009 10:19 PM To: Velocity Users List Subject: Re: Does velocity engine supports I18N ? On Sat, Mar 14, 2009 at 7:02 AM, Caleb Jones calebjo...@gmail.com wrote: I've done velocity work with I18n and 33 languages. I've always just passed in my I18n object from Java into the velocity context then called $!{i18n}.tr('Text to translate') in the template. That way there's only one template to maintain. This method can be simplified further using the ResourceTool from VelocityTools. Of course, this assumes that the view has the same layout and information for every locale. On Sat, Mar 14, 2009 at 6:08 AM, Byron Foster by...@base2.cc wrote: Couldn't you always maintain your template files in UTF-8, then always merge in UTF-8 and send out the email in UTF-8. Unless I'm not understanding the problem. I'm not sure what a I18N tool would do for you, unless this is more of an issue of date and number formatting. On Mar 14, 2009, at 0:35 , Preetam Palwe wrote: Precisely I am trying to use Velocity engine as a offline tool to send emails. I have an option or workaround to keep Locale specific velocity templates like body.vm.de , body.vm.en_us etc. But I was wondering whether there is an inbuilt support in velocity for I18N? Jian, If you could please share the your parser code which enables Velocity I18N in offline mode to the mailing list, it would be great! I had read about Multiviews in velocity tools but looks like I can't use it in offline mode. - 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 - 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: Accessing the Toolbox
What framework are you using VelocityTools with? What version of VelocityTools are you using? On Mon, Mar 16, 2009 at 9:45 AM, Andreas Bohnert a...@weberhofer.at wrote: dear velocity forum, I need access to a tool instance which is configured in my toolbox.xml from within java. how can I access these (request-scope) instances from: a.) ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) in *Action.java? b.) another tool? I have implemented public void init( Object context ) and I'm getting the ViewContext, but when I try ChainedContext.getToolBox() it is always null! Can you give me a hint? Thanks, Andreas - 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: StringResourceRepository
Yeah, macros are quite a bit different, but you may be able to rig something where you have your settings such that inline macros are kept inline (not put the global repo), then put your dynamic macros into the repo in a template of their own and use #parse to bring them into the pages you want. I haven't tried that, but it seems feasible now that you can bring macros in via #parse. On Fri, Mar 13, 2009 at 8:22 AM, Thilo Schwarz thilo.schw...@googlemail.com wrote: Hi all! Can someone tell me if I could use StringResourceRepository to process dynamic macros at the same way like templates? Is there any difference between macros and templates internally, or can I use it in the same manner? Kind regards Thilo - 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: [tools-2.0] Exposing a context map entry as a reference
On Thu, Mar 12, 2009 at 4:14 PM, Antonio Petrelli antonio.petre...@gmail.com wrote: 2009/3/5 Nathan Bubna nbu...@gmail.com: I looked through most of the code and don't see the problem, assuming that ImportAttributeModel.getImportedAttributes(...) works as expected. I've got some other things to do at the moment, but i'll try to find some time to install and run it myself today. I've been meaning to get to that anyway. I think I got it. Tiles2Tool is request scoped. Now, through the use of Tiles2Tool, a page is included. In the first page is created a ChainedContext (call it 1), in the included page a new ChainedContext is created (2). The problem is that Tiles2Tool is created and initialized when the request starts, and its velocity context is the one assigned in 1, since it is there that the Tiles2Tool is firstly used. But when used in the included page, it still refers to 1, though it should refer to 2. Ah, of course. I ought to have foreseen this. With Tools 1.x, there was once a complaint about the fact that the tools were being re-created for every include as well as the parent request. So in 2.x, i made a point to have request tools be truly request-scoped, failing to consider that some request tools should probably have stayed page scoped. Is there a way to solve this problem? Yes. :) But i don't know if it can be done internal to Tiles2Tool with the current API you have for it. I have the suspicion that if it had a more Velocity-ish API (rather than the tag-like one it has), this might not be an issue. But i'm not sure i want to impose that constraint, as i'm not sure that would solve this without trying it. So, i am considering adding a page/context scope to the Tools infrastructure. Or maybe try to have just one context per request? Not sure that's wise. Anyway, i need to think about this more and play with some things. And i still haven't yet made time to get the velocity-tiles app running. Thanks for figuring out the problem. If you (or anyone) has thoughts about the direction to take in solving this, i'd love to hear them. Thanks Antonio - 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: [tools-2.0] Exposing a context map entry as a reference
On Fri, Mar 13, 2009 at 3:25 PM, Antonio Petrelli antonio.petre...@gmail.com wrote: 2009/3/13 Nathan Bubna nbu...@gmail.com: On Thu, Mar 12, 2009 at 4:14 PM, Antonio Petrelli antonio.petre...@gmail.com wrote: Is there a way to solve this problem? Yes. :) But i don't know if it can be done internal to Tiles2Tool with the current API you have for it. I have the suspicion that if it had a more Velocity-ish API (rather than the tag-like one it has), this might not be an issue. The reason that Tiles2Tool has this structure is that I foresee a sort of automatic generation of code (JSP taglib, FreeMarker template directives, Velocity tools, etc.). I think that more Velocity-ish methods will be added. sounds good. So, i am considering adding a page/context scope to the Tools infrastructure. Or maybe try to have just one context per request? I discovered an easier way: using Renderable, because the context parameter is connected to the current template. I will commit this code soon. heh. very nice. Renderable is still a new toy to me, so i hadn't thought of it. Thanks a lot! Antonio - 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: Is there any way to print a block of text without any rendering in Velocity template?
Note that #literal() works well, but only so long as its contents are valid, parse-able VTL. For this reason, it will be deprecated in the next version (1.7) and replaced with this textblock syntax: #[[ you can put absolutely anything in here ]]# But until then, #literal() is the best way to do this when the content is valid VTL. If it is not, the workaround for 1.6 and earlier is to put the content in a separate file and use #include to bring it in. Just FYI On Wed, Mar 11, 2009 at 1:30 AM, bluejoe bluejoe2...@gmail.com wrote: Thank you very very ... much! #literal()...#end is just what I need! -bluejoe - Original Message - From: apa...@recks.org To: Velocity Users List user@velocity.apache.org Sent: Wednesday, March 11, 2009 4:11 PM Subject: Re: Is there any way to print a block of text without any rendering in Velocity template? Hi, there is a #literal()...#end directive for this in newer Velocity versions. See: http://velocity.apache.org/engine/releases/velocity-1.6.1/user-guide.html#stringliterals Hope this helps, Christoph bluejoe wrote: In Velocity template, is there any way to print a block of text without any rendering? For exmaple, I want to process such text as below: hello, $user.name! #noparse This text is formatted exactly as it is typed. using $user.name to get current user's name. #end when be rendered, I expect it looks like: hello, bluejoe! This text is formatted exactly as it is typed. using $user.name to get current user's name. Is there any directives in VTL? I need your help. - 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: Trouble accessing Map values in Velocity
It looks to me like the class that implements the $pageValues.get(key) method is not declared public. Make sure that both the pageValues class and the get method therein are both declared public. On Tue, Mar 10, 2009 at 2:36 PM, scadh sc...@hotmail.com wrote: I have a Controller method that returns a ModelAndView. The pertinent part of the code is: { Map model = new HashMap(); model.put(pageValues, contentService.getPageValues(channel, landingName).getValues()); return new ModelAndView(nominate/landing, model); } The getValues() method returns a Map, which I put into the model with key pageValues. I am unable to directly reference any values in the Map in the view. I expected this to work, but it doesn't: $pageValues.get(key) However, when referenced indirectly from within a foreach loop, it works fine: #foreach($key in $pageValues.keySet()) li$key $pageValues.get($key)/li #end Is my syntax incorrect attempting to access a Map inside another Map? Can't seem to figure it out, and time is short! I would greatly appreciate any assistance that anyone could provide. -- View this message in context: http://www.nabble.com/Trouble-accessing-Map-values-in-Velocity-tp22444107p22444107.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: [tools-2.0] Exposing a context map entry as a reference
On Thu, Mar 5, 2009 at 5:43 AM, Antonio Petrelli antonio.petre...@gmail.com wrote: Hi all, probably this is a stupid question, but please be patient, I'm almost a noob with Velocity. With a request-scoped tool I set an entry in the context: velocityContext.put(stringTest, this is a test); Is it possible to expose it as a reference, i.e.: $stringTest That sounds like it should have worked. A few questions... First, how are you getting the velocityContext in your tool? Via public void setVelocityContext(Context velocityContext) method or configure(Map)? Is the put(stringTest,...) call done in that method or a different one? Have you used that request-scoped tool in that same template prior to the $stringTest reference? Tools are not instantiated until first requested in that scope by a template. I tried with ContextTool too, but the stringTest key is not present: iterating all the keys I see only the registered tools. If the template can't see it with $stringTest, then ContextTool can't either. Thanks in advance Antonio - 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: [tools-2.0] Exposing a context map entry as a reference
Got a link to the code for $tiles.importAttribute(...)? Just for completeness... On Thu, Mar 5, 2009 at 7:22 AM, Antonio Petrelli antonio.petre...@gmail.com wrote: 2009/3/5 Nathan Bubna nbu...@gmail.com: On Thu, Mar 5, 2009 at 7:03 AM, Antonio Petrelli antonio.petre...@gmail.com wrote: 2009/3/5 Nathan Bubna nbu...@gmail.com: On Thu, Mar 5, 2009 at 5:43 AM, Antonio Petrelli antonio.petre...@gmail.com wrote: Hi all, probably this is a stupid question, but please be patient, I'm almost a noob with Velocity. With a request-scoped tool I set an entry in the context: velocityContext.put(stringTest, this is a test); Is it possible to expose it as a reference, i.e.: $stringTest how are you getting the velocityContext in your tool? Via public void setVelocityContext(Context velocityContext) method or configure(Map)? Via setVelocityContext (I prefer it for clarity). Is the put(stringTest,...) call done in that method or a different one? A different one, see: http://svn.eu.apache.org/repos/asf/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/template/ImportAttributeVModel.java and: http://svn.eu.apache.org/repos/asf/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/context/VelocityUtil.java (see the setAttribute method, the scope variable is null). Have you used that request-scoped tool in that same template prior to the $stringTest reference? Yes, $stringTest never existed before. Have you got a link to the actual tool and the template too? It might be easiest for me to just see them directly. If i still don't see the problem, perhaps i'll try to build and run it myself (assuming you already checked in the stuff in question). Sure! You can try this webapp: http://svn.eu.apache.org/repos/asf/tiles/sandbox/trunk/tiles-test-sandbox/ You need to install Tiles 2.2.0-SNAPSHOT and tiles-velocity sandbox module: http://svn.eu.apache.org/repos/asf/tiles/framework/trunk/ http://svn.eu.apache.org/repos/asf/tiles/sandbox/trunk/tiles-velocity/ When you will open the index page, click on: Velocity: Test Put List Tag This link calls the tesputlist.vm template. The problematic code is: http://svn.eu.apache.org/repos/asf/tiles/sandbox/trunk/tiles-test-sandbox/src/main/webapp/velocity/putattributeslayout.vm where the stringTest and list references are not found. Thanks for your patience :-) Antonio - 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: [tools-2.0] Exposing a context map entry as a reference
I looked through most of the code and don't see the problem, assuming that ImportAttributeModel.getImportedAttributes(...) works as expected. I've got some other things to do at the moment, but i'll try to find some time to install and run it myself today. I've been meaning to get to that anyway. On Thu, Mar 5, 2009 at 7:41 AM, Antonio Petrelli antonio.petre...@gmail.com wrote: 2009/3/5 Nathan Bubna nbu...@gmail.com: Got a link to the code for $tiles.importAttribute(...)? Just for completeness... http://svn.eu.apache.org/repos/asf/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/template/Tiles2Tool.java See the importAttribute method. This calls the ImportAttributeVModel: http://svn.eu.apache.org/repos/asf/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/template/ImportAttributeVModel.java Thanks Antonio - 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: [tools-2.0] Exception management
On Fri, Feb 27, 2009 at 3:13 AM, Antonio Petrelli antonio.petre...@gmail.com wrote: Hi all Is there a way to have a better exception management with VelocityViewServlet? I would like to see an HTTP 500 if exceptions happen. Sounds fine to me. Feel free to open a JIRA issue and/or submit a patch. Thanks Antonio - 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: read only mode?
For starters, you should definitely use this setting: runtime.introspector.uberspect = org.apache.velocity.util.introspection.SecureUberspector This Uberspect implementation blocks the following packages and classes by default, but you can add more to your velocity.properties if you wish: introspector.restrict.packages = java.lang.reflect introspector.restrict.classes = java.lang.Class introspector.restrict.classes = java.lang.ClassLoader introspector.restrict.classes = java.lang.Compiler introspector.restrict.classes = java.lang.InheritableThreadLocal introspector.restrict.classes = java.lang.Package introspector.restrict.classes = java.lang.Process introspector.restrict.classes = java.lang.Runtime introspector.restrict.classes = java.lang.RuntimePermission introspector.restrict.classes = java.lang.SecurityManager introspector.restrict.classes = java.lang.System introspector.restrict.classes = java.lang.Thread introspector.restrict.classes = java.lang.ThreadGroup introspector.restrict.classes = java.lang.ThreadLocal You should probably read and follow advice in this article: http://wiki.apache.org/velocity/BuildingSecureWebApplications And in general, you should take care not to put any objects into your context that have public methods which can change back-end state. Use wrapper objects, if necessary. On Fri, Feb 27, 2009 at 8:57 AM, ChadDavis chadmichaelda...@gmail.com wrote: I'm building a system where users can customize their site's look and feel by uploading templates that will override the built-in templates. I'm trying to explore the security aspects of this right now. It seems that the method invocation stuff, property setting, and anything else that could cause state change on my back end is a threat. I would appreciate advise on enumerating the dangerous aspects of the template language, and then ideas on how to block that stuff. Is there a way to turn off features of the language? - 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: read only mode?
On Fri, Feb 27, 2009 at 9:35 AM, ChadDavis chadmichaelda...@gmail.com wrote: Thanks for the info. I was planning on using wrapper objects. The 'users' will be admins of the sites, FYI. So there will be a certain amount of accountability. I'm more concerned about goof ups. wrappers are good for this. then you decide exactly what you trust them with. if there are objects you want/need to put in the context but don't want to write a wrapper for, just restrict them with SecureUberspector; this does prevent them from being rendered, but it does prevent them from calling any methods on them. As for the Uberspector -- is that supposed to be backup against developer error? I mean, it's at first glance hard to imagine how something like SecurityManager would end up in the context. well, given the other things it restricts by default (Class, ClassLoader, java.lang.reflect.* etc), yeah, it's unlikely. but some people let untrusted 3rd parties write templates. why take chances in such cases? :) On Fri, Feb 27, 2009 at 10:21 AM, Nathan Bubna nbu...@gmail.com wrote: For starters, you should definitely use this setting: runtime.introspector.uberspect = org.apache.velocity.util.introspection.SecureUberspector This Uberspect implementation blocks the following packages and classes by default, but you can add more to your velocity.properties if you wish: introspector.restrict.packages = java.lang.reflect introspector.restrict.classes = java.lang.Class introspector.restrict.classes = java.lang.ClassLoader introspector.restrict.classes = java.lang.Compiler introspector.restrict.classes = java.lang.InheritableThreadLocal introspector.restrict.classes = java.lang.Package introspector.restrict.classes = java.lang.Process introspector.restrict.classes = java.lang.Runtime introspector.restrict.classes = java.lang.RuntimePermission introspector.restrict.classes = java.lang.SecurityManager introspector.restrict.classes = java.lang.System introspector.restrict.classes = java.lang.Thread introspector.restrict.classes = java.lang.ThreadGroup introspector.restrict.classes = java.lang.ThreadLocal You should probably read and follow advice in this article: http://wiki.apache.org/velocity/BuildingSecureWebApplications And in general, you should take care not to put any objects into your context that have public methods which can change back-end state. Use wrapper objects, if necessary. On Fri, Feb 27, 2009 at 8:57 AM, ChadDavis chadmichaelda...@gmail.com wrote: I'm building a system where users can customize their site's look and feel by uploading templates that will override the built-in templates. I'm trying to explore the security aspects of this right now. It seems that the method invocation stuff, property setting, and anything else that could cause state change on my back end is a threat. I would appreciate advise on enumerating the dangerous aspects of the template language, and then ideas on how to block that stuff. Is there a way to turn off features of the language? - 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 - 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: [tools-2.0] How to access Writer in tool
On Thu, Feb 26, 2009 at 1:41 PM, Antonio Petrelli antonio.petre...@gmail.com wrote: Hi all Is there a way to access the writer that is used to write in the response, from a request-scoped tool? In Velocity 1.6, we introduced the org.apache.velocity.runtime.Renderable interface, which has a boolean execute(context, writer) method. If, when rendering a reference, Velocity comes across a Renderable, it calls that method instead of calling toString() and writing that value. but even if you do implement Renderable, please consider having your toString() be functional (e.g. passing a StringWriter and null context to execute(...)). I tried using the HttpServletResponse's writer, but it writes included resources in wrong order (as I suspected). It is the same effect that you would have in JSP tags when you use HttpServletResponse's writer instead of PageContext's one. yeah, we want content to run through Velocity, direct writing is frowned upon. I took a look at TilesTool and I noticed that, in fact, the included resources are transformed in strings and then returned to the template. Sincerely I don't like it. it keeps things orderly and flexible, allowing, for instance, tools to grab each other out of the context and interact with the same API. but yes, it can be a performance hit in situations involving a lot of content. In TilesViewServlet I noticed that, if bufferOutput is true, a StringWriter is used, otherwise the HttpServletResponse's one is used. I wish to use the correct writer in both cases. please do! but your options are restricted to Renderable (Velocity 1.6+) or toString() (any version). Velocity is not in the business of handing out the writer to objects before it is time to render them, sorry. Users can hack that in easily by extending VelocityView and overwriting performMerge(..) to drop the writer in the context, but that won't work well for a TilesTool. Thanks in advance Antonio - 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: Problem with $velocityHasNext in Spring
That would be because $velocityHasNext was introduced in Velocity 1.6.x. It doesn't exist in Velocity 1.5. On Sun, Feb 22, 2009 at 8:03 PM, Eddie Ridwan eddie.rid...@zoominti.com wrote: I am using Velocity views in Spring 2.5 (velocity-1.5.jar). The problem I have is that $velocityHasNext does not seem to be recognized as a foreach loop variable. Here is my template excerpt: #foreach ($pagerLink in $resultpage.getPagerLinks()) #set ($value = $resultpage.getStartPage() + $velocityCount - 1) #if ($resultpage.getCurrentPage() == $velocityCount) td class=b$value #if( $velocityHasNext ) | #end/td #else td class=ba href=keypagelist.htm?offset=$pagerLink$value/a#if( $velocityHasNext ) | #end/td #end $resultpage.getPagerLinks().size()*$velocityCount* [$velocityHasNext] #end None of the #if statements recognizes $velocityHasNext. In the debugging line: $resultpage.getPagerLinks().size()*$velocityCount* [$velocityHasNext] $velocityCount is correctly resolved to the current item count, but $velocityHasNext is not resolved and is merely rendered as the text $velocityHasNext. I tried to explicitly include the following directive in my own velocity.properties file: directive.foreach.iterator.name = velocityHasNext but it made no difference. Grateful for any ideas. Eddie Ridwan - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: tools 1.4=2.0 upgrade, configuration question
Yes, if you need to programmatically manipulate the VelocityEngine properties, rather than set them via a velocity.properties file, this is still the way to go. You are sure you specified the org.apache.velocity.tools.view.class property in your init-params? Can you share your code and config, perhaps i can spot a mistake that is not obvious to you. Did you get any exceptions or log messages? Make sure your VelocityView subclass has a constructor that accepts a JeeConfig object. On Mon, Feb 23, 2009 at 11:04 AM, rhild rh...@yahoo.com wrote: With 1.4 I could override the loadConfiguration method of VelocityViewServlet to modify/add properties of the velocity configuration at runtime. From a previous post last year it seems the way to do this now is: http://www.nabble.com/Tools-2.0---VelocityLayoutServlet---loadConfiguration-td18268452.html When I try this approach the MyVelocityView class I created is not used. I am setting up the init params for the servlet as indicated. Question: Does the link above still represent the best way to accomplish what used to be done by overriding loadConfiguration() in VelocityViewServlet? If not, what would you recommend. thanks, -Ray -- View this message in context: http://www.nabble.com/tools-1.4%3D%3E2.0-upgrade%2C-configuration-question-tp22167805p22167805.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: [tools-2.0] How to create HTTP-request-based application-wide tool
Ok, i think i've got it now. Storing things in a ThreadLocal should allow an application scoped tool to have separate copies for each request, however, i don't see how you are going to automate setting those things into the ThreadLocal at each request. Perhaps you already have a plan for this, though? I can't think of a way to do that without requiring users to take an extra step such as use a custom VelocityView class or do something manual like $mytool.set($context.this) before using other functions. VelocityTools isn't in the business of setting request values into threadlocals for application-scoped tools, at least not yet. My inclination would be to avoid trying to keep this all in one class. Split your concerns. The simplest would probably be to put anything application scoped into a ServletContext attribute(s) and have a request-scoped tool pull that out when needed. For instance, you might have a MyToolAPI object that can live at the application level and a MyTool that is request-scoped. MyTool would look for the MyToolAPI in the servletContext attributes during configure(Map). If none is found, then it creates it and sets it in there for later ones to find. Then MyTool merely forwards a getFoo() request to myToolAPI.getFoo(request). This setup would keep creation of the request-scoped MyTool very cheap and limit any heavy lifting in MyToolAPI to once-per application. Does that make sense? On Wed, Feb 25, 2009 at 7:32 AM, Antonio Petrelli antonio.petre...@gmail.com wrote: I think that I've been pretty cryptic if you understood exactly the opposite that I wished to say, so I am sorry and thanks for the patience :-D First of all I wish to have an application scoped tool. This tool needs request, response and Velocity context, all things that, presumably, are bound to the request. So, at a first glance, it seems impossible to have an application-wide tool that uses request-scoped objects. But what if I use ThreadLocal to store request, response, Velocity context? Will it work? Thanks Antonio 2009/2/25 Nathan Bubna nbu...@gmail.com: I'm not sure i understand. So, you want the tool to be request-scoped, but have the instance (or things it creates) live for the length of the application? If that's it, then i don't think ThreadLocal will help. Or is it simply that you expect there to be a lot of instances of *the tool* created for every request and wish to share things between those instances. If that's it, then why not just store them as request attributes? I'm not sure i see why ThreadLocal is needed, though yeah, that should work too. I'm also not sure why you expect there to be a lot of instances of your tool created for every request. Have you seen this happening? The tool management code for Tools 2.0 stores the request-scoped tools in the request to allow them to be shared. The intention is that request scoped tools would only need to be created once per-request, even when request includes and forwards are involved. I'll admit i haven't tested that carefully though, so i'd like to know if i've misunderstood how RequestDispatcher handles request attributes for forwards and includes. On Wed, Feb 25, 2009 at 3:28 AM, Antonio Petrelli antonio.petre...@gmail.com wrote: Hi all I need to create a tool that is based on HTTP requests for Tiles 2. I succesfully did it through extending ImportSupport class, so I can access the request protected field. However, I don't feel comfortable with this solution, because this tool needs to be request-scoped and I need to create, at every request, a lot of objects that are potentially reusable. Is there a way to make this tool application-wide? Or is there a way (a repository?) to access a registered application-wide object, instead of creating it over and over? Thanks a lot in advance Antonio - 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 - 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: tools 1.4=2.0 upgrade, configuration question
Odd. Which VelocityViewServlet does your VelocityServlet extend? It should be extending org.apache.velocity.tools.view.VelocityViewServlet. Also, which version of VelocityTools 2 are you using? On Wed, Feb 25, 2009 at 9:01 AM, rhild rh...@yahoo.com wrote: Here is the code: package atr.servlet; import org.apache.log4j.Logger; import org.apache.velocity.tools.view.VelocityView; import org.apache.velocity.tools.view.JeeConfig; import org.apache.velocity.app.VelocityEngine; import atr.utils.SystemProperties; public class ConfigurableVelocityView extends VelocityView { static Logger logger = Logger.getLogger(ConfigurableVelocityView.class.getName()); public ConfigurableVelocityView(JeeConfig config) { super(config); } protected void configure(JeeConfig config, VelocityEngine engine) { super.configure(config, engine); logger.info(Using ConfigurableVelocityView); String[] props = { webapp.resource.loader.cache, webapp.resource.loader.modificationCheckInterval, velocimacro.library.autoreload }; for (String prop : props) { String value = SystemProperties.INSTANCE.getProperty(prop); if (value != null value.length() 0) { engine.setProperty(prop, value); logger.info(setting custom Velocity property: name= + prop + , value= + value); } } } } here is the relevant piece of web.xml: servlet servlet-namevelocity/servlet-name servlet-classatr.servlet.VelocityServlet/servlet-class init-param param-nameorg.apache.velocity.tools.view.class/param-name param-valueatr.servlet.ConfigurableVelocityView/param-value /init-param /servlet atr.servlet.VelocityServlet extends VelocityViewServlet. I still use a velocity.properties file. I just want to selectively override some properties based on the environment I'm in. For instance, I want to leave the properties file as it would be for a production environment, with template caching on and macro autoreloading off, etc. But in a dev environment I'd override those. When I try the code as shown I get no exceptions thrown or additional log mesages from Velocity. There is no indication that my code above runs as the log messages don't appear and the behavior of velocity does not change, i.e. templates are still cached. -- View this message in context: http://www.nabble.com/tools-1.4%3D%3E2.0-upgrade%2C-configuration-question-tp22167805p22207069.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: [tools-2.0] How to create HTTP-request-based application-wide tool
On Wed, Feb 25, 2009 at 9:10 AM, Antonio Petrelli antonio.petre...@gmail.com wrote: 2009/2/25 Nathan Bubna nbu...@gmail.com: Ok, i think i've got it now. Storing things in a ThreadLocal should allow an application scoped tool to have separate copies for each request, however, i don't see how you are going to automate setting those things into the ThreadLocal at each request. Perhaps you already have a plan for this, though? Almost a plan. In case of a request-scoped tool, if setRequest, setResponse, setVelocityContext methods are present, they are invoked at each request, am I right? In case of an application-scoped tool, are these methods being called? If yes, then the implementation will use a ThreadLocal instead of a plain object. No. Sorry, an application scoped tool will only have such properties set once; when it is first requested from the context. After that initial creation and configuration, it is left entirely to its own devices. My inclination would be to avoid trying to keep this all in one class. Split your concerns. The simplest would probably be to put anything application scoped into a ServletContext attribute(s) and have a request-scoped tool pull that out when needed. For instance, you might have a MyToolAPI object that can live at the application level and a MyTool that is request-scoped. MyTool would look for the MyToolAPI in the servletContext attributes during configure(Map). If none is found, then it creates it and sets it in there for later ones to find. Then MyTool merely forwards a getFoo() request to myToolAPI.getFoo(request). This setup would keep creation of the request-scoped MyTool very cheap and limit any heavy lifting in MyToolAPI to once-per application. Does that make sense? A delegate, then. Thanks, it is a good suggestion! However, if the answer to the question above is yes I think that I will need to develop less code. Ah, but if they answer were yes, then i would have had to develop more, have slightly slower running tool management, and also have a lot more concerns about thread safety when writing such tools or helping users to do so. :) Thank you Antonio - 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: [tools-2.0] How to create HTTP-request-based application-wide tool
On Wed, Feb 25, 2009 at 9:23 AM, Antonio Petrelli antonio.petre...@gmail.com wrote: 2009/2/25 Antonio Petrelli antonio.petre...@gmail.com: In case of an application-scoped tool, are these methods being called? Answer: only once, at creation. That's odd, it's an unintended feature? Sort of. It is very much intended that application tools are only configured once. To simplify the configuration process, all tools are provided the current context upon configuration, regardless of scope. This, of course, means that application scoped tools get one shot at request scoped objects, if they want. Generally, they don't want it and should just ignore those config parameters. Antonio - 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: tools 1.4=2.0 upgrade, configuration question
On Wed, Feb 25, 2009 at 11:25 AM, rhild rh...@yahoo.com wrote: I was using beta 2. I just updated to beta 3 and all is well now. I don't know why I didn't notice sooner I was one version behind. While I have your attention a few more questions. I see that beta 3 includes velocity 1.5. Is there any reason to think the beta 3 would have any problems with the latest 1.6.1? None at all. It should work great with 1.6. Since I am already extending VelocityViewServlet it would be cleaner to override int() there to configure the engine rather than extend VelocityView, if it will work the way I want. I want velocity.properties to be used and then add to or modify from there. If I understand the code you gave overriding init() it is throwing out the original config and starting from scratch, which is not what I want. Am I understanding that code correctly? If so, is there an easy way to modify the config versus starting from scratch in init(). If the answer is no, that's OK. What I have now works. The answer is no; if you drop a new VelocityEngine into the VelocityView, then all configuration done on the previous engine is for naught. This is why i recommend having your own VelocityView subclass.However, if you really prefer to just have the VelocityViewServlet subclass, it's not terribly complicated to duplicate that effort yourself. You can copy the code that does it out of the VelocityView class. This is open source, after all. :) thanks, -Ray Nathan Bubna wrote: Odd. Which VelocityViewServlet does your VelocityServlet extend? It should be extending org.apache.velocity.tools.view.VelocityViewServlet. Also, which version of VelocityTools 2 are you using? -- View this message in context: http://www.nabble.com/tools-1.4%3D%3E2.0-upgrade%2C-configuration-question-tp22167805p22209874.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: org.apache.velocity.runtime.log.Log4JLogChute initialization failed
That's just the wrapping exception; it doesn't tell much of anything. I need the cause exception that was caught and wrapped by that VelocityException. On Thu, Feb 19, 2009 at 8:58 PM, Chachad, Ketan ketan.chac...@atosorigin.com wrote: The stack trace is as follows: org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration. at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.jav a:206) at org.apache.velocity.runtime.log.LogManager.updateLog(LogManager.java:255 ) at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstanc e.java:795) at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:25 0) at org.apache.velocity.app.VelocityEngine.init(VelocityEngine.java:107) at site.app.action.webapp.WebAppStandardAction.executeSupAction(WebAppStand ardAction.java:123) at site.app.action.AppAction.executeAction(AppAction.java:78) at site.app.struts.AbstractAction.execute(AbstractAction.java:108) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestPr ocessor.java:421) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java: 226) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415) at org.apache.struts.action.HttpServlet.service(HttpServlet.java:760) at org.apache.struts.action.HttpServlet.service(HttpServlet.java:853) ... Log4J version used by the web application is 1.2.8. Please let me know if there are any settings need to be done in the log4j.properties file or while setting the properties of VelocityEngine object before calling its init() method. Regards, Ketan K. Chachad -Original Message- From: Nathan Bubna [mailto:nbu...@gmail.com] Sent: Thursday, February 19, 2009 8:47 PM To: Velocity Users List Subject: Re: org.apache.velocity.runtime.log.Log4JLogChute initialization failed There should be a stack trace that went with that message. What did it say? Also, do you have log4j on your classpath? If so, what version? On Thu, Feb 19, 2009 at 4:49 AM, Chachad, Ketan ketan.chac...@atosorigin.com wrote: Hi, I have used Velocity in my web application. I am not using any velocity.properties file as loading the file was becoming a problem. So to initialize VelocityEngine the code used is as follows: VelocityEngine ve = new VelocityEngine(); ve.setProperty(resource.loader, webapp); ve.setProperty(webapp.resource.loader.class,org.apache.velocity.tools .view.servlet.WebappLoader); ve.setProperty(webapp.resource.loader.path,/WEB-INF/templates/); ve.setApplicationAttribute(javax.servlet.ServletContext,this.servlet.g etServletContext()); ve.init(); While the web application works fine on my local host, but when it was deployed on to the test application server, it gave the following error Error Code500 MessageFailed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration. Can anyone tell me what needs to be done to avoid this error? Regards, Ketan K. Chachad | Atos Origin India | Tower I - France | ketan.chac...@atosorigin.com mailto:ketan.chac...@atosorigin.com | D: +91 22 67 33 34 63 | M: +91 98 19 17 02 71 - 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 - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: org.apache.velocity.runtime.log.Log4JLogChute initialization failed
There should be a stack trace that went with that message. What did it say? Also, do you have log4j on your classpath? If so, what version? On Thu, Feb 19, 2009 at 4:49 AM, Chachad, Ketan ketan.chac...@atosorigin.com wrote: Hi, I have used Velocity in my web application. I am not using any velocity.properties file as loading the file was becoming a problem. So to initialize VelocityEngine the code used is as follows: VelocityEngine ve = new VelocityEngine(); ve.setProperty(resource.loader, webapp); ve.setProperty(webapp.resource.loader.class,org.apache.velocity.tools .view.servlet.WebappLoader); ve.setProperty(webapp.resource.loader.path,/WEB-INF/templates/); ve.setApplicationAttribute(javax.servlet.ServletContext,this.servlet.g etServletContext()); ve.init(); While the web application works fine on my local host, but when it was deployed on to the test application server, it gave the following error Error Code500 MessageFailed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration. Can anyone tell me what needs to be done to avoid this error? Regards, Ketan K. Chachad | Atos Origin India | Tower I - France | ketan.chac...@atosorigin.com mailto:ketan.chac...@atosorigin.com | D: +91 22 67 33 34 63 | M: +91 98 19 17 02 71 - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: caching with multiple resource loaders
Sure, the default implementation class is: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java?revision=729843view=markup You can change that using this property: resource.manager.class = org.apache.velocity.runtime.resource.ResourceManagerImpl The ResourceManager sits atop the ResourceCache and the ResourceLoaders, coordinating their activity. I think the basic problem is that when multiple loaders are configured, the ResourceManager is not paying attention to which loader a cached resource came from. I imagine changing the refreshResource method to check if a cached resource that came from a lower-rung resource loader can be found in a higher one should do the trick. If you do get around to fixing this for yourself, would you consider sharing the fix? On Tue, Feb 17, 2009 at 8:51 AM, ChadDavis chadmichaelda...@gmail.com wrote: Can you give me a little low down on how the ResourceManager works with the ResourceLoaders? Maybe I can do a little fix and build for my own needs. On Mon, Feb 16, 2009 at 10:30 PM, Nathan Bubna nbu...@gmail.com wrote: I don't think you're doing anything wrong, just something that no one else has tried. I think this is a limitation of the default ResourceManager implementation. Would you open a JIRA issue for this? It seems like something that could and should be fixed. On Mon, Feb 16, 2009 at 4:16 PM, ChadDavis chadmichaelda...@gmail.com wrote: I've got an app where I use a file resource loader followed by a classpath resource loader. I want the templates in the file location to override the templates on the classpath. This works partially. If a template with the same name is in both locations, it definitely picks up the one in the file system. If I remove the filesystem template, during run time, the template on the classpath is then found. So far, so good. If I then, however, try to put the template back in the file system location, it is NOT picked up. Note, this is all during run time. If I restart my app ( a web application -- not using the velocity servlet ), the filesystem template is again picked up. Here is my configuration: #resource.loader=class resource.loader=file, class # File resource loader information # file.resource.loader.description=Velocity File Resource Loader file.resource.loader.class=org.apache.velocity.runtime.resource.loader.FileResourceLoader file.resource.loader.cache=true file.resource.loader.modificationCheckInterval=1 file.resource.loader.path=/home/readyportal/Desktop/machineOneWorkspaces/bipSpace/BIP/src/wego/velocity/templates/ #file.resource.loader.path=/home/readyportal/ReadyPortal/conf/velocity/templates/ # # Class resource loader information # class.resource.loader.description=Velocity Classpath Resource Loader class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader class.resource.loader.cache=true class.resource.loader.modificationCheckInterval=1 Other notes: If I turn the caching off on the classpath resource loader ( i.e. change only the class.resource.loader.cache to false in the above config ), everything works at runtime. What am I doing wrong? - 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 - 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: build failure in distrobution 1.6.1
This was with src distribution (zip|tar.gz) file? Odd. I wasn't able to replicate it. I download the zip version on windows. I also had no trouble with the latest 1.6.2 test build. On Tue, Feb 17, 2009 at 9:54 AM, ChadDavis chadmichaelda...@gmail.com wrote: When I do the default ant build, I get: BUILD FAILED /home/readyportal/Desktop/velocity-1.6.1/build/build.xml:1147: The following error occurred while executing this line: /home/readyportal/Desktop/velocity-1.6.1/build/testcases.xml:90: org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource './site.vsl' I can make it work, but I was wondering if might be doing something wrong? - 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: Problem with $actionURL in Spring Portlet
$actionURL is not something defined by Velocity. Velocity is just a template engine, it doesn't know anything about action URL's unless some other part of the application tells it about them. You should ask about this on the Spring Portlet forum. On Tue, Feb 10, 2009 at 3:19 AM, blaise17 cla...@autonomy.com wrote: I have a spring-velocity portlet and am trying to use velocity's $actionURL but it doesn't resolve the variable and so doesn't work, it just gives me a 404 on trying to access that action (through a form). I've tried it both as ${actionURL} and $actionURL. I assume it must be something to do with my spring config or a missing velocity command before it (like the equivalent of portlet:defineObjects /)? Anyone know? Thanks -- View this message in context: http://www.nabble.com/Problem-with-%24actionURL-in-Spring-Portlet-tp21931675p21931675.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: Is Veltag dead?
Yes, Veltag is dead. It has been replaced by the VelocityViewTag, which is part of VelocityTools 2.0: http://velocity.apache.org/tools/devel/view.tag.html On Tue, Feb 10, 2009 at 3:47 AM, blaise17 cla...@autonomy.com wrote: Hi, I'm trying to work out how to use veltag but I can't seem to find it... The only sites I can find don't contain valid references or links and I can't find it in the svn as the directories that the velocity site lists it being in don't seem to exist. It's not mentioned on the current velocity site, only on ones with older version numbers in, so I was just wondering if it's vanished? Or is it in the main velocity jar now? Or was it accepted by the jakarta taglibs project? I can't seem to find it in either of those places, but maybe I'm just not looking in the right place? Thanks for any help -- View this message in context: http://www.nabble.com/Is-Veltag-dead--tp21932027p21932027.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: Velocity - Struts- XML
VelocityTools 2 has an XmlTool. Even if that doesn't fit your particular need, the source code for it shows how to load an xml file into a dom object and use the data that way. On Wed, Feb 4, 2009 at 5:26 AM, Sathish Jayapal sjaya...@gmail.com wrote: I have an application that uses struts actions rendering some information and template's body content is from a XML file. I'm not sure how to go about merging XML information along with struts actionform. I tried various examples to get some information. I was able to velocity working for populating information from actionform. But am not sure of to integrate or merge XML data to the same JSP. I tried different options, I tried to use VelocityContext, and put my parsed XML into that context, send that to be rendered, but I was getting the famous Resource Exception. I tried to use parse XML data put into action's request, velocity throws an exception. Can anybody help me to understand how to merge data from struts action and XML content?? Thanks!! - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: avoid html escaping temporally
Struts as the view component? Did you mean Velocity? What component is doing the escaping? That's not something Velocity does by default. Without knowing what is doing the escaping, it is hard to say how to avoid it. On Wed, Jan 21, 2009 at 11:30 AM, Mariano Kohan marianoko...@gmail.com wrote: Hello, I'm developing in a web application using struts as the view component. The application escapes the html characters (for example and ) inside all the printed variables. Is there any way to avoid this html escaping temporally (only for a few variables that i know contains the , characters)? Thanks, Mariano - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: Template lose track of variable?
On Wed, Jan 21, 2009 at 2:51 PM, Steve Cohen sco...@javactivity.org wrote: Thanks much, Tim, but in this case 1) tn is not null, but tn.USFormattedTn is null (perhaps because some dependent object failed in the background). cannot be the case - the function merely applies formatting to the single data element within the tn object (in this case the 1-). Since the log entry shows a value for tn, there is no possibility of null here. 2) There are multiple calls to $tn.USFormattedTn, and the happy path cases work fine, but edge cases are misspelled: there is only one path in this particular template 3) Someone accidentally calls the .vm directly and not through the controller (robots can do this in some cases, or bad links). impossible. There is only one path into the templates from my code. there is no back door 4) The value of $tn goes null between the controller debug statement and the forward to the .vm. I investigated this and found it impossible - no code does it anyway, although if we are talking about machine glitches, of course, nothing is impossible. So, are we talking about machine glitches, then? i doubt it, those are rare. has this happened only once? this does sound like it'll be very difficult to find, especially without more info than a few log messages. Velocity version? How are you filling the context? Context class? Are you sure there isn't a race condition involved? that's always my first suspicion in such mysterious errors. Under the covers, most standard Velocity Context implementations use HashMaps. i doubt those are simply losing track of a key/value pair. White, Tim wrote: I can see from my logs that the context passed to this template in this instance had the tn variable and that it wasn't found by Velocity: 2009-01-20 16:58:15,902 [robo/AIM:jrelay/2701] TRACE velocity.VelociWrapper - {tn=203-999-, lang=English} 2009-01-20 16:58:15,910 [robo/AIM:jrelay/2701] DEBUG Velocity - ResourceManager : found /resources/en_US/number/ExitComplete.vm with loader org.apache.velocity.tools.view.servlet.WebappLoader 2009-01-20 16:58:15,911 [robo/AIM:jrelay/2701] DEBUG Velocity - Null reference [template '/resources/en_US/number/ExitComplete.vm', line 6, column 56] : $tn.USFormattedTn cannot be resolved. When I've had problems like these in the past, here are some things that it's turned out to be (using your variable as an example): 1) tn is not null, but tn.USFormattedTn is null (perhaps because some dependent object failed in the background). 2) There are multiple calls to $tn.USFormattedTn, and the happy path cases work fine, but edge cases are misspelled: #if ($allisgood) Your TN is: $tn.USFormattedTn #else Your TN is: $tn.usformattedtn #end 3) Someone accidentally calls the .vm directly and not through the controller (robots can do this in some cases, or bad links). 4) The value of $tn goes null between the controller debug statement and the forward to the .vm. Just some ideas of the kinds of things that this has been for me in the past - I hope you can figure it out! Tim This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments. - 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 - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: Template lose track of variable?
On Wed, Jan 21, 2009 at 3:27 PM, Steve Cohen sco...@javactivity.org wrote: Nathan Bubna wrote: On Wed, Jan 21, 2009 at 2:51 PM, Steve Cohen sco...@javactivity.org wrote: Thanks much, Tim, but in this case 1) tn is not null, but tn.USFormattedTn is null (perhaps because some dependent object failed in the background). cannot be the case - the function merely applies formatting to the single data element within the tn object (in this case the 1-). Since the log entry shows a value for tn, there is no possibility of null here. 2) There are multiple calls to $tn.USFormattedTn, and the happy path cases work fine, but edge cases are misspelled: there is only one path in this particular template 3) Someone accidentally calls the .vm directly and not through the controller (robots can do this in some cases, or bad links). impossible. There is only one path into the templates from my code. there is no back door 4) The value of $tn goes null between the controller debug statement and the forward to the .vm. I investigated this and found it impossible - no code does it anyway, although if we are talking about machine glitches, of course, nothing is impossible. So, are we talking about machine glitches, then? i doubt it, those are rare. has this happened only once? this does sound like it'll be very difficult to find, especially without more info than a few log messages. Velocity version? How are you filling the context? Context class? Are you sure there isn't a race condition involved? that's always my first suspicion in such mysterious errors. Under the covers, most standard Velocity Context implementations use HashMaps. i doubt those are simply losing track of a key/value pair. Only once that I know of. Yes, probably very difficult to find, possibly not worth the effort unless I catch it happening again. agreed. Using 1.6.1. Context is constructed from Properties objects (a Properties is-a Map) that my code passes around. Only right before it is passed to Velocity is the context constructed, using the VelocityContext(Map) constructor. in case you didn't already know, that constructor will use that Properties object as it's internal context store. it doesn't copy things over. so, if the whole lifecycle of your Properties object or VelocityContext is not completely contained within a single thread, then you have thread-safety issues. I have checked the pass-around path and I see no way that this properties object could have gotten corrupted between the time it was logged and the time velocity looked at it. It's a linear path between putting the object in the properties and passing the properties to my Velocity wrapper for conversion to a Context and passage to Velocity for merger with the template. There are no threading issues here - all this happens in one thread so I don't see a race condition. they're usually awfully hard to see, that's why i always suspect them when i can't see a problem that only rarely happens. once i (or my boss) decides such a bug needs squashing, i just start trying to replicate it. until i can make it happen at will, there's no way for me to know if i have really found and/or fixed it. anything and everything else is just speculation until the bug can be replicated. I fully expected, when I saw this, to find an error in my code or template, but surprisingly to me, I cannot. ah, but the nasty bugs are never the visible ones. such things stopped surprising me years ago, though they never fail to irritate me immensely. - 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: WebappResourceLoader: ResourceNotFoundException
Agreed. Let's change that. Besides, most methods that need Velocity to be init'ed will now call it themselves if used before init() has been called. There is absolutely no reason to call init from any constructor. On Mon, Jan 19, 2009 at 11:12 PM, Byron Foster by...@base2.cc wrote: On Jan 19, 2009, at 13:44 , lacco wrote: Okay, it works now: The init method shouldn't be called at all when setting properties by hand... Besides, the servlet context has to be set. My final version: VelocityEngine ve = new VelocityEngine(); ve.setApplicationAttribute(javax.servlet.ServletContext, servletContext); ve.setProperty(resource.loader, webapp); ve.setProperty(webapp.resource.loader.class, org.apache.velocity.tools.view.servlet.WebappLoader); ve.setProperty(webapp.resource.loader.path, /WEB-INF/classes/de/hpi/petrinet/serialization/erdf); Template t = ve.getTemplate( petrinet.erdf.vm ); Yea, I think this is confusing. Calling the non default constructors for VelocityEngine calls the init() method, but calling the default constructor does not. So, if you call VelocityEngine(props) then you can't set any more properties after that point. - 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: regex in template
On Tue, Jan 13, 2009 at 3:37 PM, Jason Berk jb...@purdueefcu.com wrote: Velocity rocks, but I do have a few questions: 1. when/where is the javadoc for the 1.6 engine? http://velocity.apache.org/engine/releases/velocity-1.6/apidocs/index.html 2. is it possible to do a regex in a template? If you are running on a JDK that supports it (1.5+), yes. Something like this: #set( $regex = foo ) I would do #set( $regex = 'foo' ) just to ensure Velocity doesn't interpolate your regex. #foreach( $item in $itemList ) #if( $item.getItemId().startsWith($regex) ) Assuming that getItemId() returns a String, you will need to use the matches(String regex) method. startsWith() doesn't expect a regex. ...do something... #end #end Make sense? Thanks, Jason The PEN is now mightier than the PIN. Simply use your PEN instead of your PIN and sign for your PEFCU Visa Check Card purchases. Earn bonus points redeemable for gift and travel awards. Combine PEFCU Visa check card and credit card points for even more rewards. ***This is a transmission from Purdue Employees Federal Credit Union (PEFCU) and is intended solely for its authorized recipient(s), and may contain information that is confidential and or legally privileged. If you are not an addressee, or the employee or agent responsible for delivering it to an addressee, you are hereby notified that any use, dissemination, distribution, publication or copying of the information contained in this email is strictly prohibited. If you have received this transmission in error, please notify us by telephoning (765) 497-3328 or returning the email. You are then instructed to delete the information from your computer. Thank you for your cooperation.*** - 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: Problem's trying to access VM pages in a JAR file.
We would need to see more of your velocity.properties (particularly your resource.loader properties) to answer your question. On Thu, Jan 8, 2009 at 10:08 AM, mass...@gmail.com wrote: Hi! I'm trying to create a modular application, and each module will be a JAR with VM pages within the JAR and they will be place in the classpath, I read that the ClasspathResourceLoader can load templates placed in the classpath, but I'm having some problems, the first problem is that I can't use velocimacro.library=pages/VM_global_library.vm in my velocity,properties, because the velocity can't find this resource, and if I put the VM-global_library in a jar no prolbem regarding find the file ocur but all the pages I try to access gives the following error: Unable to find resource '/pages/login.vm' (for example). If someone knows exactly how to config the velocity.properties to access the VM pages in a JAR file, or have any ideia of what I'm doing wrong please answer me. - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: LinkTool and xHTML
VelocityTools 1.1 does not support tool configuration, i think. Back then, the xhtml setting was for the whole toolbox only; you couldn't set it on a per-tool basis: toolbox xhtmltrue/xhtml tool keylink/key /toolbox Tools 1.2, 1.3 and 1.4 all support individual tool parameters: tool keylink/key scoperequest/scope classorg.apache.velocity.tools.struts.StrutsLinkTool/class parameter name=foo value=bar/ /tool However, i just double-checked and the LinkTool still expects the xhtml setting to be global in all 1.x versions. So, you can't actually use parameters for that particular setting. And yes, Tools 2 makes all such things much easier. :) On Wed, Jan 7, 2009 at 11:13 PM, Manish prol...@gmx.net wrote: Thanks, I am using Velocity Tools 1.1 (using standard StrutsLinkTool) and thus use toolbox.xml - how do I set the xhtml property to true here? This doesn't seem to work - tool xhtml=true keylink/key scoperequest/scope classorg.apache.velocity.tools.struts.StrutsLinkTool/class /tool Do I need to subclass it? Is there a simpler way to set this property in toolbox.xml (google is just showing me tools.xml examples) rgds, - Manish I tried this as well, but it's not working either! :( tool keylink/key scoperequest/scope classorg.apache.velocity.tools.struts.StrutsLinkTool/class property name=xhtml value=true/ /tool Obviously, I can subclass it very easily -- but the organizational policies may not allow using custom tools for links when StrutsLinkTool is available. :( Is it not possible to configure tools in Velocity tools 1.x? New Velocity tools 2 seem to make it quite easy! TIA, - Manish - 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: velocimarco.library property and StringResourceLoader
On Thu, Jan 8, 2009 at 7:18 AM, Steve Cohen sco...@javactivity.org wrote: Raymond Auge wrote: Thanks, Ray. Further comments and questions inline Hey Steve, I just re-purposed our entire Velocity usage to use StringResourceLoader where before we were calling evaluate() ALL THE TIME... it was killer on resources as you might imagine. Hmm. I haven't noticed resource problems yet. I'm not calling evaluate() now; I am using the VelocityEngine.mergeTemplate() approach. Does mergeTemplate() have a greater or lesser resource-consumption footprint than evaluate()? ... so I guess my question now boils down to what the tradeoffs are in resource consumption between evaluate() and mergeTemplate(). I was looking at StringResourceLoader more as a tool of development convenience than as a tool of resource maximization, but it looks like that may not be not its primary purpose. ... StringResourceLoader is to allow Strings to be turned into cache-able Template objects, so that your string template needn't be re-parsed on every request. It uses more memory than evaluate, but saves you processor cycles. if anything, evaluate() is the convenience tool and StringResourceLoader is for more production-type situations (IMHO). - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: velocimarco.library property and StringResourceLoader
On Thu, Jan 8, 2009 at 9:35 AM, Raymond Auge ra...@liferay.com wrote: On Thu, 2009-01-08 at 08:53 -0800, Nathan Bubna wrote: On Thu, Jan 8, 2009 at 6:39 AM, Raymond Auge ra...@liferay.com wrote: ... I do have a question of my own. How many strings in the repository is too many? Or an overall size. Can they have a time-to-live? ... There is currently no limit besides the available memory. There's also no expiry for them. StringResourceRepositoryImpl just uses a synchronized hashmap to store StringResource instances. But StringResourceRepository is an interface, so fancier implementations are possible. And yet, you would really lose the performance benefit if you were to drop them into some slower storage than memory, where you would have to serialize them again, anyway... so that being the case... perhaps using an LRU cache with a max size could be the solution to not killing memory with tones of random VTL strings. That would work great for your particular setup, where you are always checking if the resource is already stored in the repo. Others, however, may expect that strings in the repo don't disappear based on usage anymore than a lesser-used file would disappear from the file system, so that really couldn't be the default implementation. You would just have to set the string.resource.loader.repository.class property or manually set the repo via: StringResourceLoader.setRepository(StringResourceLoader.REPOSITORY_NAME_DEFAULT, myStringResourceRepo); Cool! -- Raymond Augé Senior Software Engineer Liferay, Inc. Enterprise. Open Source. For Life. - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: velocimarco.library property and StringResourceLoader
On Thu, Jan 8, 2009 at 10:04 AM, Raymond Auge ra...@liferay.com wrote: On Thu, 2009-01-08 at 09:46 -0800, Nathan Bubna wrote: That would work great for your particular setup, where you are always checking if the resource is already stored in the repo. Others, however, may expect that strings in the repo don't disappear based on usage anymore than a lesser-used file would disappear from the file system, so that really couldn't be the default implementation. Very true. I wasn't implying that for a default to Velocity, but as a solution to the potential memory issue in my scenario. You would just have to set the string.resource.loader.repository.class property or manually set the repo via: StringResourceLoader.setRepository(StringResourceLoader.REPOSITORY_NAME_DEFAULT, myStringResourceRepo); Regarding this, we already have: props.setProperty( org.apache.velocity.app.VelocityEngine.RESOURCE_MANAGER_CLASS, com.liferay.portal.velocity.LiferayResourceManager); props.setProperty( org.apache.velocity.app.VelocityEngine.RESOURCE_MANAGER_CACHE_CLASS, com.liferay.portal.velocity.LiferayResourceCache); Will the rendered Template objects fall into this cache anyway? If so, is there any reason to change the repository configuration? yeah, each String that you put into the repository, when requested, is parsed into a Template which will be managed/cached by the classes above. But that String will still be sitting in the repository too. If the repository is becoming a memory issue (as always, be wary of premature optimization), then it might behoove you to create your own StringResourceRepository that doesn't keep everything around. Thanks, -- Raymond Augé Senior Software Engineer Liferay, Inc. Enterprise. Open Source. For Life. - To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org
Re: LinkTool and xHTML
Just call the setXHTML(boolean) method to change this behavior. or if you are configuring this in a tools.xml (Tools 2) or toolbox.xml (Tools 1), then you can set an xhtml property for the tool to true. On Tue, Jan 6, 2009 at 9:44 PM, Manish prol...@gmx.net wrote: This is a question about Velocity's LinkTool http://velocity.apache.org/tools/devel/view/LinkTool.html The addQueryData() method of this tool creates parameters with an ampersand - ; but xHTML specifies that correct way to write an ampersand in a xhtml is to use the ampersand character reference amp; -- so that would make param=value as amp;param=value. Is there any xHTML compatible method available in newer versions of LinkTool? rgds, - Manish - 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