Masquer les derniers auteurs
Paul Libbrecht (admin) 1.1 1 // {{groovy}}
2
3
4 import com.xpn.xwiki.api.Attachment
5 import com.xpn.xwiki.api.Document
6 import org.apache.commons.io.IOUtils
7 import java.util.zip.ZipOutputStream
8 import java.util.zip.ZipEntry
9
10 def page = request.getParameter("page");
11 Document pageDoc = null;
12 try {
Paul Libbrecht (admin) 2.1 13 pageDoc = xwiki.getDocument(page);
Paul Libbrecht (admin) 1.1 14 } catch(Exception ex) {}
15
16 if(page && pageDoc) {
17 System.err.println("Should download attachments from page ${pageDoc}.");
Paul Libbrecht (admin) 2.1 18 response.setContentType("application/zip");
19 response.addHeader("Content-Disposition", "attachment; filename=${pageDoc.getName()}_attachments.zip");
Paul Libbrecht (admin) 1.1 20
21
22 ZipOutputStream out = null;
Paul Libbrecht (admin) 2.1 23 System.err.println("Attachments list's size: ${pageDoc.document.attachmentList.size()}.");
Paul Libbrecht (admin) 1.1 24 try {
25 out = new ZipOutputStream(response.getOutputStream());
26 for(Attachment att in pageDoc.getAttachmentList()) {
27 System.err.println("Outputting " + att.filename);
28 ZipEntry entry = new ZipEntry(att.filename);
29 out.putNextEntry(entry);
30 IOUtils.copy(att.contentInputStream, out);
31 }
32 } catch (Exception ex) {
33 ex.printStackTrace();
34 } finally {
35 try {
36 if(out!=null) out.close();
37 } catch(Exception e) {}
38 }
39
40 } else {
Paul Libbrecht (admin) 2.1 41 println("Sorry, I need a page parameter.");
Paul Libbrecht (admin) 1.1 42 }
43
44
45 // {{/groovy}}
This wiki is licensed under a Creative Commons 2.0 license
XWiki 13.10 - Documentation - Conditions