Subscribe via Feed

Things that make you go... AH HAH!!

Jeremy Hodge, Mar 14, 2010 10:55:11 PM




   
                    var con = facesContext.getExternalContext();
            var writer = facesContext.getResponseWriter();
            var response = con.getResponse();
           
            response.setContentType('application/x-gzip');
            response.setHeader('Cache-Control', 'no-cache');
            response.setHeader('Content-disposition', 'attachment, filename="' + database.getTitle().split(' ').join('') + '-' + new Date().toUTCString() + '.xml.gz"');
             
            writer.write(session.createDxlExporter().exportDxl(database.getAllDocuments()));
        }]]>
   




Make sure you have gzip compression turned on ....



5 responses to Things that make you go... AH HAH!!

Jeremy Hodge, June 2, 2010 12:52 PM

Actually, if you read RFC822 which defines the basis and structure upon which HTTP headers are built, delimiters are defined to be "specials" "linear whitespace" or "comment" ... specials are special characters and is defined as ( ) < > @ , ; : \ " . [ or ] ... so while semi-colon gets used 99.9% of the time, a comma is acceptable ... which explains why the code above works, exactly as its displayed...


demha, June 2, 2010 12:06 PM

Just it's "response.setHeader('Content-disposition', 'attachment; filename..." with a ; not a ,


Tim Tripcony, March 15, 2010 12:34 AM

Jeremy, check out the demo app I posted for AD111: it includes an example of streaming a dynamically generated Symphony document; you could do the same for PDF, ZIP files to combine user-assembled collections of files... sky's the limit. Just be darned sure you're using the response stream (as opposed to the response writer) and the beforeRenderResponse event (and don't forget to call facesContext.responseComplete) if you're sending binary data or Domino will throw a hissy fit exception.


Jeremy Hodge, March 14, 2010 11:36 PM

Hey karsten. Yes absolutely. The ah hah wasn't really about the ability to provide the dxl as a zip but the fact that anything you can get the writer to stream, you can get the server to compress and deliver as a download for you. I def. Agree on wanting a dxl streamer, but my thoughts are going to towards a user a la cart system of some type and being able to deliver customized selections in a single compressed file. I need to delve further into the writer to see what else and how else to stream content.


Karsten Lehmann, March 14, 2010 11:22 PM

Not a good idea for large databases :-)
I wished there was a function in the Notes Java API to stream the DXL code out (well you can using JNI and C API functions, but there is no standard method for it).
In your example, the whole database DXL code is held in server memory in a String object before it is written to the Writer...