XML building - velocity 1.4
Hi, I want to build xml by replacing existing XML text elements with some other text. I built the Document with SAXBuilder and put the root element in the context. My template is like this : #set ($rootelem = $root.getRootElement()) $rootelem #foreach($elem in $rootelem.getChildren()) #set ($newelem = $elem) #if ($elem.getName().equalsIgnoreCase(serviceInstanceId)) got it $newelem.getText() $newelem.setText(OTHERTEXT) $newelem #end #end When I merge with the template, I get the text of the existing node correctly( $newelem.getText()) After setText when I print the $newelem I expect the new text (OTHERTEXT) in the element. But I get the empty element. I never see new text element in the element. Any help is appreciated. -- Thanks Regards, Anagha
Disable echo in VTL
Hi, I'm building the XML in the VTL. At some point I retrieve the value of an element and set its text as $elem.setText( $sometext ) #foreach($elem in $rootelem.getChildren()) #set ($elemname = $elem.getName()) #set( $sometext = $userprops.get($elemname) ) $elem.setText( $sometext ) #end In the output I get each element printed as --- [Element: serviceName/] where serviceName is the the element name. This happens for all the elements in the for loop. I want to disable this output on the console/file which comes from setText I tried : VelocityEngine ve = new VelocityEngine(); ve.setProperty(VelocityEngine.VM_MESSAGES_ON, false); But still the elements are printed which is not desired. Also I get a lot of new lines in the output which I want to disable. Any pointers? -- Thanks Regards, Anagha
Re: Disable echo in VTL
Hi, Use as below #foreach($elem in $rootelem.getChildren())## #set ($elemname = $elem.getName())## #set( $sometext = $userprops.get($elemname) )## #set($tempVariable = $elem.setText( $sometext ))## #end## to ignore the return value from setText, just pretend as assigning to a variable ( its the way i used in my templates). If anyone has a better way to ignore such unneccesary return values from printing, pls let me know. For unnecessary new lines, in your for loop, there will be new lines each after a statement. So if you put ## i.e comment as EOL, it will ignore those new lines. There are lot of bugs reported for formatting and new lines in velocity. Please go through the forum mails for further reference. Regards, Ravi On 2/7/06, Anagha [EMAIL PROTECTED] wrote: Hi, I'm building the XML in the VTL. At some point I retrieve the value of an element and set its text as $elem.setText( $sometext ) #foreach($elem in $rootelem.getChildren()) #set ($elemname = $elem.getName()) #set( $sometext = $userprops.get($elemname) ) $elem.setText( $sometext ) #end In the output I get each element printed as --- [Element: serviceName/] where serviceName is the the element name. This happens for all the elements in the for loop. I want to disable this output on the console/file which comes from setText I tried : VelocityEngine ve = new VelocityEngine(); ve.setProperty(VelocityEngine.VM_MESSAGES_ON, false); But still the elements are printed which is not desired. Also I get a lot of new lines in the output which I want to disable. Any pointers? -- Thanks Regards, Anagha
Re: component based templates with Velocity (+ tools?)
On Monday 6 February 2006 4:49 pm, Nathan Bubna wrote: gosh, time flies... since that time, we really haven't pursued the Velocimacro library idea very thoroughly. we do have a start to it in our Wiki, but the contributions are thin and organization/formatting is uneven. well, we were thinking that our approach would be to create some suitably generic component tools which could be contributed to this and then extend those to meet our more specific needs as far as doing compentized work, i agree that Click has probably gone furthest in supporting compenent-oriented web development with Velocity. before you do anything else, you should probably look into what they're doing first. yes, it looks interesting ... I hadn't heard of it before so started examining it yesterday afternoon. My first impression is that we could use it, but that the Velocity Tools approach might integrate more easily with what we currently have and the way we do things. I could be wrong about that, of course ;D 2. Create a suite of Velocity Tools, each with an accompanying velocity template ... or multiple templates - which template was used could be determined by the presence or absence of vm files based upon convention? conventions are good. would this be something like the MultiViewsTool? possibly - I haven't played with that one yet (but it's on my list now! :D) for example: a MenuTool might have a template that looked like this: #set ( $Menu.name = 'main menu' ) #* a string which identifies which type of menu we're dealing with *# #set ( $Menu.site = $Config.siteName ) #* so it knows where to get the correct menu items *# ul #foreach ( $MenuItem in $Menu.items ) lia href=$MenuItem.getURL()$MenuItem.getText()/a/li #end /ul Through its interface with the Velocity Tool, this one 'main menu' template file could then be used globally and multiple times in the same view. not sure i follow... sorry - that's not a very clear description! Let me clarify: - a view here is considered equivalent to a 'page' (i.e. a URL identified resource which is requested by an end-user). A view itself would not have a 'template' as such - it would simply consist of a bunch of directives that specify things like 'I want these components with the following parameters', 'I want this layout', 'Put these components here and those ones there' etc... - views would be constructed from components organised into a layout. - Our design team would then be able to write just a single template for each component (i.e. it would be 'global' ... unless a template for the same component was found in a location specified by convention as being 'more specific'). There would only need to be a single *.vm template file (containing the HTML or whatever, written by our design team). Now, in theory, this is achievable using #parse and so on (aside from as the view layer for Struts, this is the main way we use Velocity at present: as an elaborate form of SSI - which I think is a waste of an excellent and versatile tool!) By rigorously conceiving of one's sites as being constructed from 'components', and making tools that define the properties and methods available to them, it would be possible to store and retrieve data about those things that aid management of the views. For example: one feature request we have received from our design team is the ability to define what stylesheets or javascripts a particular 'component' depends upon and have these automatically loaded in the head section of a document. Because accessibility and standards-compliance is a big issue, they would also like to be able to do things like dynamically changing the heading level of a particular template depending on where it was used (this is easily achieved using VTL, but only in ways that are too prone to human error). From this perspective, what we are proposing is to use a suite of Velocity Tools as a simple way of managing the complexities of the view layer. A beneficial side-effect would be a clearer separation of display and logic in a way that suits our organisational setup. ... that was a longer clarification than I intended it to be ... does it clarify? ;D Chris DISCLAIMER: This e-mail is confidential and should not be used by anyone who is not the original intended recipient. If you have received this e-mail in error please inform the sender and delete it from your mailbox or any other storage mechanism. Neither Macmillan Publishers Limited nor any of its agents accept liability for any statements made which are clearly the sender's own and not expressly made on behalf of Macmillan Publishers Limited or one of its agents. Please note that neither Macmillan Publishers Limited nor any of its agents accept any responsibility for viruses that may be contained in this e-mail or its attachments and it is your
Re: Disable echo in VTL
I used a macro for this purpose ## ## convenience directive to invoke a method and ignore the return value ## #macro( call $foo )#if($foo)#**##end#end ## the comment in the if-statement avoids an empty if-body parser error ... #call( $elem.setText( $sometext ) ) Beware... some people may argue that putting such code in templates is not the right place(TM), if you desire to follow the MVC paradigm. The newlines and whitespaces is something that needs adressing in velocity, see the proposed solutions in the wiki: http://wiki.apache.org/jakarta-velocity/VelocityWhitespaceGobbling Cheers, Christoph Anagha wrote: Hi, I'm building the XML in the VTL. At some point I retrieve the value of an element and set its text as $elem.setText( $sometext ) #foreach($elem in $rootelem.getChildren()) #set ($elemname = $elem.getName()) #set( $sometext = $userprops.get($elemname) ) $elem.setText( $sometext ) #end In the output I get each element printed as --- [Element: serviceName/] where serviceName is the the element name. This happens for all the elements in the for loop. I want to disable this output on the console/file which comes from setText I tried : VelocityEngine ve = new VelocityEngine(); ve.setProperty(VelocityEngine.VM_MESSAGES_ON, false); But still the elements are printed which is not desired. Also I get a lot of new lines in the output which I want to disable. Any pointers? -- Thanks Regards, Anagha - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Can we use File object in VTL?
Hi, I'm using VTL to build Java file. I need to change/insert some keywords, variables in the Java file based on context paramters. Instead of putting the whole Java file in .vm file, can I load the file in some test program and put the File descriptor in the context? Later in .vm I'll retrieve this file descriptor from context and output some lines of the file. I'have tried in similar way for .xml' where I load and built Document object from XML in test program. I put the root element of the xml in the context and later processed the doc in .vm by extracting root from context. I want to know can we do on similar lines for File descriptor object. Any help is welcome. -- Thanks Regards, Anagha
Re: Can we use File object in VTL?
Hi Anagha, I sometimes use velocity to generate diverse ASCII files from CSV or other inputs. I use my own TemplateTool that has some few goodies in the context - like the ClassTool used in the macro below. ## ## Macro to write a text to a file. ## #macro( fileWrite $filename $text ) #set( $out = $Class.newInstance(java.io.FileOutputStream, $filename) ) #set( $data = $text.getBytes() ) #call( $out.write($data) ) #call( $out.close() ) #end ## ## ## convenience directive to invoke a method and ignore the return value ## #macro( call $foo )#if($foo)#**##end#end ## ## ## Some helpful local context tools: ## #set( $LF = $Context.formDecode(%0A) ) #set( $Integer = 1 ) #set( $Long = $Integer.longValue() ) #set( $now = $date.clone() ) ## ## ## Some simple formatters ## #macro( digits4 $number )#* *##set( $id = $number )#* -- access the macro paramter, ensure its a String *##set( $id = $id.trim() )#* -- prepend the padding, clipping whitespace artefacts *##set( $len = $id.length() - 4 )#* -- compute the offset for the rest length *#$id.substring($len)## -- emit the resulting padded string #end #macro( digits2 $number )#* *##set( $id = $number )#* *##set( $id = 00$id.trim() )#* *##set( $len = $id.length() - 2 )#* *#$id.substring($len)## #end #macro( dateStr $d )#* *##set( $y = $d.year + 1900 )#* *##digits4($y)#digits2($d.month)#digits2($d.date)#digits2($d.hours)#digits2($d.minutes)#digits2($d.seconds)## #end You can do things like: ## -- read file #set( $text = #parse($inputName) ) #set( $lines = $text.trim().split($LF) ) #foreach( $line in $lines ) ... #end ... #set( $filename = E${statelliteId}_${orderId}_#digits4($nr)_#dateStr($now).ORD ) writing output to: $filename #fileWrite( $filename $order )## This does things that maybe should have been done in perl ;) Cheers, Christoph Anagha wrote: Hi, I'm using VTL to build Java file. I need to change/insert some keywords, variables in the Java file based on context paramters. Instead of putting the whole Java file in .vm file, can I load the file in some test program and put the File descriptor in the context? Later in .vm I'll retrieve this file descriptor from context and output some lines of the file. I'have tried in similar way for .xml' where I load and built Document object from XML in test program. I put the root element of the xml in the context and later processed the doc in .vm by extracting root from context. I want to know can we do on similar lines for File descriptor object. Any help is welcome. -- Thanks Regards, Anagha - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: component based templates with Velocity (+ tools?)
On Tuesday 7 February 2006 2:04 pm, Robert Koberg wrote: I was just curious if this needs to be dynamic. Couldn't you pregenerate all these things? This is what we do for our CMS. CMS users select layouts for pages (or falls back to an ancestor that had a layout defined). Several content pieces or XML components can be assigned to defined regions on a page. CMS users can choose things at the folder level like should a snailtrail or paging information show. We use XML configuration, content and XSL to transform to a static file. That file can be a velocity page, just as much as possible is pregenerated. I guess in other words, it sounds like you want to build a CMS. well, I think we would certainly like this to be a part of a broader CMS project. At present we do almost exactly what you do: we use XSL to transform XML - first into 'xml snippets' (that roughly correspond to the content 'entities' we would want to create Velocity Tools for), then into a static HTML files. Subsequently, Velocity is used to pull these static HTML files in to various points on a page. What we want to do is use Velocity to overcome the problems inherent to this approach; which are: 1. If the design or layout of things changes, or even if we just change the content a little, we have to 're-rip' stuff (run through the XSLs). With the amount of content we have, and the frequency of changes, this is a burden. 2. Authoring XSLs requires a certain expertise and knowledge of the XML formats we use; authoring Velocity templates requires very little. We can produce XHTML Velocity templates very quickly which produce standards-compliant, accessible code. However, we hit a bottleneck (and a significant source of errors) when parts (or all) of these templates need to be written as XSLs. 3. As with most organisations, our design team is responsible for all the HTML, CSS, Javascript etc that is used to display pages under normal circumstances; and our development team is responsible for everything else. The static-file approach you mention requires extensive interaction between these departments that is a source of delays and errors. What we need to do is get rid of the stage where XSLs are producing HTML. By making Velocity Tools that retrieve data associated with content 'entities' (whether from 'xml snippets' or a database or wherever) and insert this into the context in a standardised, pre-agreed manner, rebuilding, xsl editing, and inter-departmental coopertation is not necessary every time there is a change in the appearance of a site etc ... So, yes - it is certainly related to content management, but Velocity Tools in themselves would not be a CMS! :D Chris DISCLAIMER: This e-mail is confidential and should not be used by anyone who is not the original intended recipient. If you have received this e-mail in error please inform the sender and delete it from your mailbox or any other storage mechanism. Neither Macmillan Publishers Limited nor any of its agents accept liability for any statements made which are clearly the sender's own and not expressly made on behalf of Macmillan Publishers Limited or one of its agents. Please note that neither Macmillan Publishers Limited nor any of its agents accept any responsibility for viruses that may be contained in this e-mail or its attachments and it is your responsibility to scan the e-mail and attachments (if any). No contracts may be concluded on behalf of Macmillan Publishers Limited or its agents by means of e-mail communication. Macmillan Publishers Limited Registered in England and Wales with registered number 785998 Registered Office Brunel Road, Houndmills, Basingstoke RG21 6XS - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: can anybody help me on this please
if you are using the latest (1.2) release of VelocityTools, then $text.label.one should work just fine. see http://jakarta.apache.org/velocity/tools/struts/MessageTool.html#get() On 2/6/06, Magnus Kvalheim [EMAIL PROTECTED] wrote: Are you using VelocityStruts(Velocity-tools)? Because I experienced the same problems there. Accessing label.one=foobar as $text.label.one didn't work, so I had to use $text.get('label.one') However, properties without dots work fine in velocitystruts label_one=foobar $text.label_one Can anyone confirm this issue? best Magnus Shashikanth Duchetty wrote: but it doesn't work. If I remove . in between them it works fine thanks Shashi On 2/7/06, Sreeni Gali [EMAIL PROTECTED] wrote: Yeah definitly you can do this. On 2/5/06, Shashikanth Duchetty [EMAIL PROTECTED] wrote: Hi all, can I keep such property in properties file some.one.like=somexyz thanks Shashi - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: XML building - velocity 1.4
I've never used SAXBuilder... Are you sure that $newelem.toString() always displays the same as $newelem.getText() - Original Message - From: Anagha [EMAIL PROTECTED] To: velocity-user velocity-user@jakarta.apache.org Sent: Tuesday, February 07, 2006 12:34 AM Subject: XML building - velocity 1.4 Hi, I want to build xml by replacing existing XML text elements with some other text. I built the Document with SAXBuilder and put the root element in the context. My template is like this : #set ($rootelem = $root.getRootElement()) $rootelem #foreach($elem in $rootelem.getChildren()) #set ($newelem = $elem) #if ($elem.getName().equalsIgnoreCase(serviceInstanceId)) got it $newelem.getText() $newelem.setText(OTHERTEXT) $newelem #end #end When I merge with the template, I get the text of the existing node correctly( $newelem.getText()) After setText when I print the $newelem I expect the new text (OTHERTEXT) in the element. But I get the empty element. I never see new text element in the element. Any help is appreciated. -- Thanks Regards, Anagha - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: OutOfMemoryException Processing Velocity Template
Hmm. I wasn't aware of the leak issue, I'll make a note of that. As for other work arounds, I have one that will work just fine for my situation. But I'm still curious about the specialized tiles tool for the purpose of streaming output to the browser, instead of buffering the whole page in a string before sending it as the tiles tool does. But that's another question, and probably for the tiles developers. Thank you for your help. -Evan -Original Message- From: Malcolm Edgar [mailto:[EMAIL PROTECTED] Sent: Monday, February 06, 2006 8:35 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template If your are reloading your application a lot, i.e. doing development work, the singleton pattern causes a memory leak. This could be expressed in OOME when rendering templates. regards Malcolm Edgar On 2/7/06, Nathan Bubna [EMAIL PROTECTED] wrote: i'm not sure. Edgar? as for your question about a specialized TilesTool... i'm not aware of this having been done. if it has, it wasn't shared with the list. have you taken the other advice in the thread and profiled your application? if you aren't up for writing a specialized TilesTool, then there may be other ways you can cut down on your memory use. On 2/6/06, e v a n [EMAIL PROTECTED] wrote: Yes it looks like we still are using v1.1 in out project. How does this affect the rendering of large HTML files and getting OOMEs when doing so? Evan -Original Message- From: Nathan Bubna [mailto:[EMAIL PROTECTED] Sent: Monday, February 06, 2006 1:11 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template that depends on which version of VelocityTools you are using. in 1.2, we rewrote things to use a VelocityEngine instead of the singleton, which was causing problems for us. On 2/6/06, e v a n [EMAIL PROTECTED] wrote: I believe that I'm using the singletone pattern. I using the VelocityViewServlet to startup velocity, and I believe its written to use the runtime singleton by calling Velocity.init(). Is that correct? -Evan -Original Message- From: Malcolm Edgar [mailto:[EMAIL PROTECTED] Sent: Saturday, February 04, 2006 4:35 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template Are you using Velocity singleton pattern or VelocityEngine? regards Malcolm Edgar On 2/4/06, e v a n [EMAIL PROTECTED] wrote: Hello, I just picked up on this thread[1] from 5-10-2005 today because I'm running into a similar issue trying to render a large HTML page via velocity that's included via Tiles. In this post [2] in the thread, there is talk of making a specialized TilesTool for cases where large html files need to be written out with Velocity. To anyone's knowledge, has anyone come up with such a patch? Thank You, Evan Leonard [1] - http://www.nabble.com/RE%3A-OutOfMemoryException-Processing-Velo city -T emplat e-t5193.html [2] - http://www.nabble.com/Re:-OutOfMemoryException-Processing-Veloci ty-T em plate- p23480.html - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- --- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- --- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: OutOfMemoryException Processing Velocity Template
And here all the time I thought it was a Tomcat issue with reloading. All of my web applications use the VelocityEngine rather than the singleton, and I notice that Tomcat throws an OutOfMemoryException after a lot of reloads. Is there something I should be during in the HttpServlet destroy method to clear out the VelocityEngine? Barbara Baughman X2157 On Tue, 7 Feb 2006, e v a n wrote: Hmm. I wasn't aware of the leak issue, I'll make a note of that. As for other work arounds, I have one that will work just fine for my situation. But I'm still curious about the specialized tiles tool for the purpose of streaming output to the browser, instead of buffering the whole page in a string before sending it as the tiles tool does. But that's another question, and probably for the tiles developers. Thank you for your help. -Evan -Original Message- From: Malcolm Edgar [mailto:[EMAIL PROTECTED] Sent: Monday, February 06, 2006 8:35 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template If your are reloading your application a lot, i.e. doing development work, the singleton pattern causes a memory leak. This could be expressed in OOME when rendering templates. regards Malcolm Edgar On 2/7/06, Nathan Bubna [EMAIL PROTECTED] wrote: i'm not sure. Edgar? as for your question about a specialized TilesTool... i'm not aware of this having been done. if it has, it wasn't shared with the list. have you taken the other advice in the thread and profiled your application? if you aren't up for writing a specialized TilesTool, then there may be other ways you can cut down on your memory use. On 2/6/06, e v a n [EMAIL PROTECTED] wrote: Yes it looks like we still are using v1.1 in out project. How does this affect the rendering of large HTML files and getting OOMEs when doing so? Evan -Original Message- From: Nathan Bubna [mailto:[EMAIL PROTECTED] Sent: Monday, February 06, 2006 1:11 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template that depends on which version of VelocityTools you are using. in 1.2, we rewrote things to use a VelocityEngine instead of the singleton, which was causing problems for us. On 2/6/06, e v a n [EMAIL PROTECTED] wrote: I believe that I'm using the singletone pattern. I using the VelocityViewServlet to startup velocity, and I believe its written to use the runtime singleton by calling Velocity.init(). Is that correct? -Evan -Original Message- From: Malcolm Edgar [mailto:[EMAIL PROTECTED] Sent: Saturday, February 04, 2006 4:35 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template Are you using Velocity singleton pattern or VelocityEngine? regards Malcolm Edgar On 2/4/06, e v a n [EMAIL PROTECTED] wrote: Hello, I just picked up on this thread[1] from 5-10-2005 today because I'm running into a similar issue trying to render a large HTML page via velocity that's included via Tiles. In this post [2] in the thread, there is talk of making a specialized TilesTool for cases where large html files need to be written out with Velocity. To anyone's knowledge, has anyone come up with such a patch? Thank You, Evan Leonard [1] - http://www.nabble.com/RE%3A-OutOfMemoryException-Processing-Velo city -T emplat e-t5193.html [2] - http://www.nabble.com/Re:-OutOfMemoryException-Processing-Veloci ty-T em plate- p23480.html - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- --- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- --- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail:
Re: OutOfMemoryException Processing Velocity Template
I have this issue with Tomcat JSP apps as well as Velocity. So it is a Tomcat issue. I think it holds on to static references in the classloader. Tomcat's great in general but the deployment I find is really not robust. WILL - Original Message - From: Barbara Baughman [EMAIL PROTECTED] To: Velocity Users List velocity-user@jakarta.apache.org Sent: Tuesday, February 07, 2006 1:33 PM Subject: RE: OutOfMemoryException Processing Velocity Template And here all the time I thought it was a Tomcat issue with reloading. All of my web applications use the VelocityEngine rather than the singleton, and I notice that Tomcat throws an OutOfMemoryException after a lot of reloads. Is there something I should be during in the HttpServlet destroy method to clear out the VelocityEngine? Barbara Baughman X2157 On Tue, 7 Feb 2006, e v a n wrote: Hmm. I wasn't aware of the leak issue, I'll make a note of that. As for other work arounds, I have one that will work just fine for my situation. But I'm still curious about the specialized tiles tool for the purpose of streaming output to the browser, instead of buffering the whole page in a string before sending it as the tiles tool does. But that's another question, and probably for the tiles developers. Thank you for your help. -Evan -Original Message- From: Malcolm Edgar [mailto:[EMAIL PROTECTED] Sent: Monday, February 06, 2006 8:35 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template If your are reloading your application a lot, i.e. doing development work, the singleton pattern causes a memory leak. This could be expressed in OOME when rendering templates. regards Malcolm Edgar On 2/7/06, Nathan Bubna [EMAIL PROTECTED] wrote: i'm not sure. Edgar? as for your question about a specialized TilesTool... i'm not aware of this having been done. if it has, it wasn't shared with the list. have you taken the other advice in the thread and profiled your application? if you aren't up for writing a specialized TilesTool, then there may be other ways you can cut down on your memory use. On 2/6/06, e v a n [EMAIL PROTECTED] wrote: Yes it looks like we still are using v1.1 in out project. How does this affect the rendering of large HTML files and getting OOMEs when doing so? Evan -Original Message- From: Nathan Bubna [mailto:[EMAIL PROTECTED] Sent: Monday, February 06, 2006 1:11 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template that depends on which version of VelocityTools you are using. in 1.2, we rewrote things to use a VelocityEngine instead of the singleton, which was causing problems for us. On 2/6/06, e v a n [EMAIL PROTECTED] wrote: I believe that I'm using the singletone pattern. I using the VelocityViewServlet to startup velocity, and I believe its written to use the runtime singleton by calling Velocity.init(). Is that correct? -Evan -Original Message- From: Malcolm Edgar [mailto:[EMAIL PROTECTED] Sent: Saturday, February 04, 2006 4:35 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template Are you using Velocity singleton pattern or VelocityEngine? regards Malcolm Edgar On 2/4/06, e v a n [EMAIL PROTECTED] wrote: Hello, I just picked up on this thread[1] from 5-10-2005 today because I'm running into a similar issue trying to render a large HTML page via velocity that's included via Tiles. In this post [2] in the thread, there is talk of making a specialized TilesTool for cases where large html files need to be written out with Velocity. To anyone's knowledge, has anyone come up with such a patch? Thank You, Evan Leonard [1] - http://www.nabble.com/RE%3A-OutOfMemoryException-Processing-Velo city -T emplat e-t5193.html [2] - http://www.nabble.com/Re:-OutOfMemoryException-Processing-Veloci ty-T em plate- p23480.html - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- --- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- --- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED]
Re: Can we use File object in VTL?
Christoph, Thanks for suggestions. Currently I'm using vel-1.4 and tried a sample macro from your script below. #macro( fileWrite $filename $text ) #set( $out = $Class.newInstance(java.io.FileOutputStream, $filename) ) #set( $data = $text.getBytes() ) #call( $out.write($data) ) #call( $out.close() ) #end ## #macro( call $foo )#if($foo)#**##end#end #fileWrite( SampJava intercae ABC{} ) I'm expecting that a file SampJava should be created with the text intercae ABC{} in it. Here I see Class: variable is not set. This is not working, Pls have a look for this macro. Also, in vel-1.4 I did see ContextTool class, pls. let me know its package. Thanks, Anagha On 2/7/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi Anagha, I sometimes use velocity to generate diverse ASCII files from CSV or other inputs. I use my own TemplateTool that has some few goodies in the context - like the ClassTool used in the macro below. ## ## Macro to write a text to a file. ## #macro( fileWrite $filename $text ) #set( $out = $Class.newInstance(java.io.FileOutputStream, $filename) ) #set( $data = $text.getBytes() ) #call( $out.write($data) ) #call( $out.close() ) #end ## ## ## convenience directive to invoke a method and ignore the return value ## #macro( call $foo )#if($foo)#**##end#end ## ## ## Some helpful local context tools: ## #set( $LF = $Context.formDecode(%0A) ) #set( $Integer = 1 ) #set( $Long = $Integer.longValue() ) #set( $now = $date.clone() ) ## ## ## Some simple formatters ## #macro( digits4 $number )#* *##set( $id = $number )#* -- access the macro paramter, ensure its a String *##set( $id = $id.trim() )#* -- prepend the padding, clipping whitespace artefacts *##set( $len = $id.length() - 4 )#* -- compute the offset for the rest length *#$id.substring($len)## -- emit the resulting padded string #end #macro( digits2 $number )#* *##set( $id = $number )#* *##set( $id = 00$id.trim() )#* *##set( $len = $id.length() - 2 )#* *#$id.substring($len)## #end #macro( dateStr $d )#* *##set( $y = $d.year + 1900 )#* *##digits4($y)#digits2($d.month)#digits2($d.date)#digits2($d.hours)#digits2($d.minutes)#digits2($d.seconds)## #end You can do things like: ## -- read file #set( $text = #parse($inputName) ) #set( $lines = $text.trim().split($LF) ) #foreach( $line in $lines ) ... #end ... #set( $filename = E${statelliteId}_${orderId}_#digits4($nr)_#dateStr($now).ORD ) writing output to: $filename #fileWrite( $filename $order )## This does things that maybe should have been done in perl ;) Cheers, Christoph Anagha wrote: Hi, I'm using VTL to build Java file. I need to change/insert some keywords, variables in the Java file based on context paramters. Instead of putting the whole Java file in .vm file, can I load the file in some test program and put the File descriptor in the context? Later in .vm I'll retrieve this file descriptor from context and output some lines of the file. I'have tried in similar way for .xml' where I load and built Document object from XML in test program. I put the root element of the xml in the context and later processed the doc in .vm by extracting root from context. I want to know can we do on similar lines for File descriptor object. Any help is welcome. -- Thanks Regards, Anagha - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Thanks Regards, Anagha