[xwiki-devs] Create a Download-Button which returns a rendered file
Hi Devs, i want to render with a macro a content into different file-types which can be downloaded. I think i must use response/request to "deliver", but not sure how i can do that. Is there an example where i can learn from? regards, Matthias -- View this message in context: http://xwiki.475771.n2.nabble.com/Create-a-Download-Button-which-returns-a-r... Sent from the XWiki- Dev mailing list archive at Nabble.com.
It depends of the kind of macro. In wiki macro the response is "response" binding (so $response in Velocity for example). Here is an example: http://extensions.xwiki.org/xwiki/bin/view/Extension/Generate+downloaded+con... In a Java macro you will have to @Inject org.xwiki.container.Container component (xwiki-platform-container-api module) to access the response or go access the response from the XWikiContext if you already use it. On Sun, Dec 8, 2013 at 10:19 PM, Matthias Wegner <[email protected]> wrote:
Hi Devs,
i want to render with a macro a content into different file-types which can be downloaded. I think i must use response/request to "deliver", but not sure how i can do that. Is there an example where i can learn from?
regards, Matthias
-- View this message in context: http://xwiki.475771.n2.nabble.com/Create-a-Download-Button-which-returns-a-r... Sent from the XWiki- Dev mailing list archive at Nabble.com. _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
Almost Perfect. I use now {{velocity}} #if($request.getParameter("onsong")) #set($content=$request.getParameter("onsong")) $response.setContentType("text/plain"); $response.setCharacterEncoding('UTF-8') $response.setHeader("Content-Disposition", "attachment; filename=onsong.txt"); $response.writer.print($content.replace("/Newline/", "\n")) $context.setFinished(true); #end {{/velocity}} {{html}} <form><button title="Download OnSong" type="submit" name="onsong" value="First Line/Newline/Second Line/Newline/Third Line"> <../../../resources/icons/silk/link_add.png> </button></form> {{/html}} Do you know how i can breakline the string for the writer? \n does not work. Regards, Matthias -- View this message in context: http://xwiki.475771.n2.nabble.com/Create-a-Download-Button-which-returns-a-r... Sent from the XWiki- Dev mailing list archive at Nabble.com.
On 12/09/2013 05:47 PM, Matthias Wegner wrote:
Almost Perfect. I use now
{{velocity}} #if($request.getParameter("onsong")) #set($content=$request.getParameter("onsong")) $response.setContentType("text/plain"); $response.setCharacterEncoding('UTF-8') $response.setHeader("Content-Disposition", "attachment; filename=onsong.txt"); $response.writer.print($content.replace("/Newline/", "\n")) $context.setFinished(true); #end {{/velocity}}
{{html}} <form><button title="Download OnSong" type="submit" name="onsong" value="First Line/Newline/Second Line/Newline/Third Line"> <../../../resources/icons/silk/link_add.png> </button></form>
You shouldn't hardcode any URL. Use: $xwiki.getSkinFile('icons/silk/link_add.png')
{{/html}}
Do you know how i can breakline the string for the writer? \n does not work.
Velocity doesn't allow \n as an escape sequence, but you can use an actual newline: $response.writer.print($content.replace("/Newline/", " "))
Regards, Matthias
-- Sergiu Dumitriu http://purl.org/net/sergiu
participants (3)
-
Matthias Wegner -
Sergiu Dumitriu -
Thomas Mortagne