|
nk4um Moderator
Posts: 756
|
Hey Tom,
Thanks for documenting this - I''ve used this trick once or twice (I think in the package tool) but this will be very helpful
to others.
After all the pain you went through its pouring salt on the wounds but I should mention how it''s done on NetKernel 4 (for
future reference).
context.sink("httpResponse:/header/Content-disposition", "attachment; filename="+filename);
The HTTP transport on NK4 is now a full resource oriented address space - you can source from the httpRequest: and sink to
the httpResponse: makes these sort of tasks fairly painless.
NK4 public preview is imminent. Watch this space.
|
|
nk4um User
Posts: 129
|
Greetings, I''ve searched quite a bit for the answer to the question " Can I modify the http header ?". The answer is yes, but it wasn''t obvious for me, so maybe it''s not obvious for others either. Well documented is how you can set the mimetype : In my case that came down to
<instr> <type>cast</type> <operand>this:response</operand> <operator> <cast> <mimetype>application/vnd.ms-excel</mimetype> </cast> </operator> <target>this:response</target> </instr>
|
That was easy. And then I got stuck. My excel browser plug-in executed nicely, but it can''t handle the same filename twice. Solution : use a random filename. Very well, but where do I set it ? I studied the SpreadsheetML specification, but although
that one does - somewhere - contain the name of the workbook, that didn''t solve my problem. Some more Mr Google taught me that I should modify the httpheader. Cool. But how ? I studied the code that handles the mimetype,
but did not strike gold. Frustration was about to settle in, when I remembered that Peter once made a package-application
to my specifications. Its in ext-install-1.2.4.jar and it''s really small (but powerful). And the solution is, HTTPResponseCode !
<instr> <type>cast</type> <operand>this:response</operand> <operator> <cast> <mimetype>application/vnd.ms-excel</mimetype> </cast> </operator> <target>this:response</target> </instr>
|
<instr> <type>xslt</type> <operand>var:param</operand> <operator>content_disposition.xsl</operator> <target>var:response_code</target> </instr>
|
<instr> <type>HTTPResponseCode</type> <operand>this:response</operand> <param>var:response_code</param> <target>this:response</target> </instr>
|
I even made two possible actions for the enduser. In one he still opens the excel browser plug-in, in the other he can download
(and save) the xml file (and open it whenever he wants). Here''s the content_disposition.xsl for that:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:outputmethod="xml" /> <xsl:templatematch="/nvp"> <HTTPResponseCode> <code>200</code> <header> <name>Content-disposition</name> <xsl:choose> <xsl:whentest="string-length(a) > 0"> <value>attachment; filename= <xsl:value-ofselect="a" />_ <xsl:value-ofselect="b" />.xml </value> </xsl:when> <xsl:otherwise> <value>attachment; filename=default_match.xml</value> </xsl:otherwise> </xsl:choose> </header> </HTTPResponseCode> </xsl:template> </xsl:stylesheet>
|
Maybe this is all ''obvious'', but I hope someone finds it useful. Regards, Tom
|