[xwiki-commits] r1382 - xwiki/trunk/src/main/java/com/xpn/xwiki/web

jeremi joslin jeremi23 at gmail.com
Wed Oct 11 17:46:44 CEST 2006


Hi Arjunan,
here is some comments on your commit :
* the header is the one of Intellij instead of the one of XWiki
* You have system.out in the code, should be removed
* the comments in the code is not really nice. If you really need
comment, use // instead of /* */ if the comment is on one line.
* some comments are useless
* your comments is not in javadoc format

jeremi

On 10/11/06, Arjunan <arjunan at users.forge.objectweb.org> wrote:
> 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;
> +    }
> +}
>
>
>
>
>
> --
> You receive this message as a subscriber of the xwiki-commits at objectweb.org mailing list.
> To unsubscribe: mailto:xwiki-commits-unsubscribe at objectweb.org
> For general help: mailto:sympa at objectweb.org?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
>
>
>


-- 
jeremi




More information about the Xwiki-notifications mailing list