r1382 - xwiki/trunk/src/main/java/com/xpn/xwiki/web

Arjunan arjunan at users.forge.objectweb.org
Wed Oct 11 17:04:06 CEST 2006


Author: arjunan
Date: 2006-10-11 17:04:05 +0200 (Wed, 11 Oct 2006)
New Revision: 1382

Added:
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/ZipEntryDownloadAction.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/ZipExplorerAction.java
Log:
Files added for document manager from CSPL side 

Added: xwiki/trunk/src/main/java/com/xpn/xwiki/web/ZipEntryDownloadAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/ZipEntryDownloadAction.java	2006-10-11 13:21:45 UTC (rev 1381)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/ZipEntryDownloadAction.java	2006-10-11 15:04:05 UTC (rev 1382)
@@ -0,0 +1,74 @@
+package com.xpn.xwiki.web;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.XWiki;
+import com.xpn.xwiki.plugin.XWikiPluginManager;
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.doc.XWikiAttachment;
+
+import java.util.Iterator;
+import java.io.IOException;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.io.FileOutputStream;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: ravenees
+ * Date: Oct 4, 2006
+ * Time: 5:10:29 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class ZipEntryDownloadAction extends XWikiAction {
+
+     public boolean action(XWikiContext context) throws XWikiException {
+        System.out.println("((((((( inside ZipEntryDownloadAction )))))))");
+
+        XWikiRequest request = context.getRequest();
+        XWikiResponse response = context.getResponse();
+        XWikiDocument doc = context.getDoc();
+        String path = request.getRequestURI().trim();
+        String filename = Utils.decode(path.substring(path.lastIndexOf("/")+1),context);
+
+        XWikiAttachment attachment = null;
+        String originalAttachment = request.getParameter("zipfile").trim();
+
+        if (originalAttachment!=null) {
+             Iterator itr = doc.getAttachmentList().iterator();
+             while(itr.hasNext()){
+                attachment = (XWikiAttachment)itr.next();
+                if(originalAttachment.equalsIgnoreCase(attachment.getFilename())){
+                     break;
+                }
+             }
+        }
+
+        if (attachment==null) {
+            Object[] args = { filename };
+            throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
+                    XWikiException.ERROR_XWIKI_APP_ATTACHMENT_NOT_FOUND,
+                    "Attachment {0} not found", null, args);
+        }
+
+        XWikiPluginManager plugins = context.getWiki().getPluginManager();
+        attachment = plugins.downloadAttachment(attachment, context);
+
+        String mimetype = attachment.getMimeType(context);
+        response.setContentType(mimetype);
+        try {
+            byte[] data = attachment.getContent(context);
+            if(data != null )
+                response.setContentLength(data.length);
+
+            response.getOutputStream().write(data);
+            response.getOutputStream().close();
+
+        }catch (IOException e) {
+            throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
+                    XWikiException.ERROR_XWIKI_APP_SEND_RESPONSE_EXCEPTION,
+                    "Exception while sending response", e);
+        }
+        return true;
+     }
+}

Added: xwiki/trunk/src/main/java/com/xpn/xwiki/web/ZipExplorerAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/ZipExplorerAction.java	2006-10-11 13:21:45 UTC (rev 1381)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/ZipExplorerAction.java	2006-10-11 15:04:05 UTC (rev 1382)
@@ -0,0 +1,71 @@
+package com.xpn.xwiki.web;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.api.Document;
+import com.xpn.xwiki.doc.ArchiveAttachmentExplorer;
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.doc.XWikiAttachment;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: ravenees
+ * Date: Sep 27, 2006
+ * Time: 5:03:32 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class ZipExplorerAction extends XWikiAction{
+
+    /**
+     *
+     * Gives the rennderer i.e the response templete (zipexplorer.vm)
+     * */
+    public String render(XWikiContext context) throws XWikiException {
+        return "zipexplorer";
+    }
+
+    /**
+     * ZIPEXPLORERACTION :- is to explore the archive files with extension .zip
+     *
+     * */
+    public boolean action(XWikiContext context) throws XWikiException {
+        System.out.println("((((((( inside ZipExplorerAction )))))))");
+
+        XWikiRequest request = context.getRequest();
+        XWikiResponse response = context.getResponse();
+        XWikiDocument doc = context.getDoc();
+        XWikiAttachment attachment = null;
+        /*
+         The complete URL String including the filename
+        */
+        String path = request.getPathInfo();
+        String filename;
+        if (context.getMode() == XWikiContext.MODE_PORTLET){
+            /*
+             Getting the file name from the request parameter "filename"
+            */
+            filename = request.getParameter("filename");
+            
+        }
+        else{
+            /*
+            Parsing the URL to get the filename
+            */
+            filename = Utils.decode(path.substring(path.lastIndexOf("/") + 1), context);
+        }
+
+        /*
+        Getting the attachment form the attachment list
+        */
+
+        request.setAttribute("zipfile",filename);
+
+        if (request.getParameter("id") != null) {
+            int id = Integer.parseInt(request.getParameter("id"));
+            attachment = (XWikiAttachment) doc.getAttachmentList().get(id);
+        } else {
+            attachment = doc.getAttachment(filename);
+        }
+        return true;
+    }
+}





More information about the Xwiki-notifications mailing list