[stringtemplate-interest] Generating big documents

Nate misc at n4te.com
Wed Dec 27 14:36:39 PST 2006


One part we haven't discussed is the output. I haven't tried it, but I 
think it works something like this...

StringTemplate template = ...
template.write(template.getGroup().getStringTemplateWriter(new 
FileWriter("out.txt")));

-Nate


John Snyders wrote:
> Just because the attributes are given to ST just before the template 
> is invoked doesn't mean that all the data the attributes represent 
> must be in memory. The data can be fetched as it is read by template 
> attribute references. I don't see this as violating the push pattern 
> as long as the data was generated before the template is invoked and 
> there are no order dependencies of the attribute properties.
>  
> To keep things simple imagine a web request that kicks off a process 
> that generates a large data file. You can create an object (call it 
> ResultData) that represents this file and give it to ST as an 
> attribute (called data). The object has a member (called lines) that 
> implements collection and has an iterator over the lines of the file. 
> Each time the iterator is used it reads and returns the next line of 
> the file. The template may look like this
>  
> Report foo generated on $data.reportDate$
> $data.lines : doLine() }
> $footer()$
>  
> Disclaimer: I have not done this but see no reason why it won't work.
>  
> -John
>  
>
>     -----Original Message-----
>     *From:* stringtemplate-interest-bounces at antlr.org
>     [mailto:stringtemplate-interest-bounces at antlr.org]*On Behalf Of
>     *Adam Bennett
>     *Sent:* Wednesday, December 27, 2006 1:51 PM
>     *To:* stringtemplate-interest at antlr.org
>     *Subject:* [stringtemplate-interest] Generating big documents
>
>     Our web application has the ability to generate reports as HTML or
>     XML documents.  These documents are potentially very large
>     (20MB with some of our test data).  Early on we had problems with
>     the server running out of memory while generating these because
>     all the data was brought into memory from the database.  Our
>     solution was to stream the results from the database while
>     generating the document.
>      
>     Can StringTemplate be used to generate such documents?  I cannot
>     see how to avoid bringing all the data into memory because
>     StringTemplate requires all data to be passed as an attribute.
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
>   



More information about the stringtemplate-interest mailing list