Depuis la version 1.1 >
modifié par Paul Libbrecht (admin)
sur 2016/08/18 23:48
À la version < 6.2 >
modifié par Paul Libbrecht (admin)
sur 2016/08/19 20:24
>
Commentaire de modification : Il n'y a aucun commentaire pour cette version

Résumé

Détails

Icon Propriétés de la Page
Contenu
... ... @@ -10,25 +10,33 @@
10 10  def page = request.getParameter("page");
11 11  Document pageDoc = null;
12 12  try {
13 - pageDoc = xwiki.getDocument(page);
13 + pageDoc = xwiki.getDocument(page);
14 14  } catch(Exception ex) {}
15 15  
16 16  if(page && pageDoc) {
17 17   System.err.println("Should download attachments from page ${pageDoc}.");
18 - //System.err.println("content: " + pageDoc.getContent());
19 - response.setContentType("application/zip; filename=${pageDoc.getName()}_attachments.zip");
20 - response.addHeader("Content-Disposition", "attachment");
18 + def uncompressedMimes = ["image/jpeg", "image/png", "application/zip"];
19 + response.setContentType("application/zip");
20 + String name = pageDoc.getName();
21 + if(name=="WebHome") name = pageDoc.getSpace();
22 + response.addHeader("Content-Disposition", "attachment; filename=${name}_attachments.zip");
21 21  
22 22  
23 23   ZipOutputStream out = null;
24 - System.err.println("Attachments list: ${pageDoc.document.attachmentList.size()}.");
26 + System.err.println("Attachments list's size: ${pageDoc.document.attachmentList.size()}.");
25 25   try {
26 26   out = new ZipOutputStream(response.getOutputStream());
27 27   for(Attachment att in pageDoc.getAttachmentList()) {
28 28   System.err.println("Outputting " + att.filename);
29 29   ZipEntry entry = new ZipEntry(att.filename);
32 + entry.setTime(att.getDate().getTime());
33 + entry.setSize(att.filesize);
34 + if(uncompressedMimes.contain(att.mimeType))
35 + entry.setMethod(ZipEntry.STORED);
36 + else
37 + entry.setMethod(ZipEntry.DEFLATED);
30 30   out.putNextEntry(entry);
31 - IOUtils.copy(att.contentInputStream, out);
39 + IOUtils.copy(att.contentInputStream, out, 5*1024*1024);
32 32   }
33 33   } catch (Exception ex) {
34 34   ex.printStackTrace();
... ... @@ -40,8 +40,8 @@
40 40  
41 41  } else {
42 42   println("""
43 -= Download Attachments =
44 -call this page with a parameter ``page`` set to the name of the page, it will put all attachments of that page in a single zip and download it.
51 += Download Attachments Macro =
52 +Use as ~{~{downloadAttachments/~}~} to see a link to a zip of all attachments.
45 45  """);
46 46  }
47 47  
Icon XWiki.WikiMacroClass[0]
Code de la macro
... ... @@ -1,0 +1,4 @@
1 +
2 +{{velocity}}
3 +{{html clean=false}}<a href="$url">Download page attachments</a>{{/html}}
4 +{{/velocity}}
Disponibilité du contenu de la macro
... ... @@ -1,0 +1,1 @@
1 +No content
Catégorie par défaut
... ... @@ -1,0 +1,1 @@
1 +Content
Description de la macro
... ... @@ -1,0 +1,1 @@
1 +Displays a link to a zip archive of all attachments of a page.
Identifiant de la macro
... ... @@ -1,0 +1,1 @@
1 +downloadAttachments
Nom de la macro
... ... @@ -1,0 +1,1 @@
1 +Download Attachments
Support du mode en ligne
... ... @@ -1,0 +1,1 @@
1 +Oui
Visibilité de la macro
... ... @@ -1,0 +1,1 @@
1 +Current User
This wiki is licensed under a Creative Commons 2.0 license
XWiki 13.10 - Documentation - Conditions