[stringtemplate-interest] Generating big documents

John Snyders jjsnyders at rcn.com
Wed Dec 27 13:43:31 PST 2006


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20061227/81fb989e/attachment.html 


More information about the stringtemplate-interest mailing list