r1549 - xwiki/trunk/core/src/main/java/com/xpn/xwiki/plugin/zipexplorer
Vincent Massol
vmassol at users.forge.objectweb.org
Tue Nov 14 12:24:12 CET 2006
Author: vmassol
Date: 2006-11-14 12:24:11 +0100 (Tue, 14 Nov 2006)
New Revision: 1549
Modified:
xwiki/trunk/core/src/main/java/com/xpn/xwiki/plugin/zipexplorer/ZipExplorerPlugin.java
Log:
Added comments in the code and fixed code alignment
Modified: xwiki/trunk/core/src/main/java/com/xpn/xwiki/plugin/zipexplorer/ZipExplorerPlugin.java
===================================================================
--- xwiki/trunk/core/src/main/java/com/xpn/xwiki/plugin/zipexplorer/ZipExplorerPlugin.java 2006-11-14 11:15:35 UTC (rev 1548)
+++ xwiki/trunk/core/src/main/java/com/xpn/xwiki/plugin/zipexplorer/ZipExplorerPlugin.java 2006-11-14 11:24:11 UTC (rev 1549)
@@ -104,26 +104,29 @@
*/
public XWikiAttachment downloadAttachment(XWikiAttachment attachment, XWikiContext context) {
String url = context.getRequest().getRequestURI();
- String filename;
+ // If the requested download URL doesn't point to a zip, return the original attachment
if (!attachment.getFilename().endsWith(".zip"))
return attachment;
+
+ // If the URL doesn't point to a file inside the ZIP, return the original attachement. Otherwise, compute the
+ // relative file location inside the ZIP file so that we can extract it content below.
+ String filename;
try {
filename = getFileLocationFromZipURL(url, context.getAction().trim());
}
catch(Exception e){
filename = "";
}
-
if (filename.length() == 0)
return attachment;
- XWikiAttachment newAttachment;
-
- newAttachment = new XWikiAttachment();
+ // Create the new attachment pointing to the file inside the ZIP
+ XWikiAttachment newAttachment = new XWikiAttachment();
newAttachment.setDoc(attachment.getDoc());
newAttachment.setAuthor(attachment.getAuthor());
newAttachment.setDate(attachment.getDate());
+
try {
byte[] stream = attachment.getContent(context);
ByteArrayInputStream bais = new ByteArrayInputStream(stream);
@@ -150,7 +153,6 @@
return newAttachment;
}
-
/**
* @return the content of an entry in the zip file
*/
@@ -164,7 +166,6 @@
return baos.toByteArray();
}
-
public List getFileList(Document doc, String attachmentName, XWikiContext context) {
List zipList = null;
@@ -203,30 +204,30 @@
return zipList;
}
- public Vector getFileTreeList(Document doc, String attachmentName, XWikiContext context) {
+ public Vector getFileTreeList(Document doc, String attachmentName, XWikiContext context) {
List flatList = getFileList(doc, attachmentName, context);
- Map fileTree = new HashMap();
- Iterator it = flatList.iterator();
- Vector res = new Vector();
- while(it.hasNext()){
- String url = (String) it.next();
- StringBuffer buf = new StringBuffer(url.length());
- String parentBuf = "";
- String[] aUrl = url.split("/");
- for (int i = 0; i < aUrl.length; i++){
- if (i == aUrl.length - 1 && !url.endsWith("/"))
+ Map fileTree = new HashMap();
+ Iterator it = flatList.iterator();
+ Vector res = new Vector();
+ while(it.hasNext()) {
+ String url = (String) it.next();
+ StringBuffer buf = new StringBuffer(url.length());
+ String parentBuf = "";
+ String[] aUrl = url.split("/");
+ for (int i = 0; i < aUrl.length; i++) {
+ if (i == aUrl.length - 1 && !url.endsWith("/"))
buf.append(aUrl[i]);
- else
+ else
buf.append(aUrl[i] + "/");
- ListItem item = new ListItem(buf.toString(), aUrl[i], parentBuf);
- if (!fileTree.containsKey(buf.toString()))
+ ListItem item = new ListItem(buf.toString(), aUrl[i], parentBuf);
+ if (!fileTree.containsKey(buf.toString()))
res.add(item);
- fileTree.put(buf.toString(), item);
- parentBuf = buf.toString();
- }
- }
- return res;
- }
+ fileTree.put(buf.toString(), item);
+ parentBuf = buf.toString();
+ }
+ }
+ return res;
+ }
String getFileLink(Document doc, String attachmentName, String fileName, XWikiContext context) {
String link = doc.getAttachmentURL(attachmentName);
More information about the Xwiki-notifications
mailing list