r1025 - in xwiki/trunk/src/main: java/com/xpn/xwiki java/com/xpn/xwiki/doc java/com/xpn/xwiki/plugin/fileupload java/com/xpn/xwiki/web web web/templates

Jeremi Joslin jeremi at users.forge.objectweb.org
Fri Mar 31 12:09:16 CEST 2006


Author: jeremi
Date: 2006-03-31 12:09:15 +0200 (Fri, 31 Mar 2006)
New Revision: 1025

Added:
   xwiki/trunk/src/main/web/xwiki.js
Modified:
   xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiException.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPlugin.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/UploadAction.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/Utils.java
   xwiki/trunk/src/main/web/templates/attach.vm
Log:
revert to the 1022 version

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiException.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiException.java	2006-03-31 06:37:33 UTC (rev 1024)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiException.java	2006-03-31 10:09:15 UTC (rev 1025)
@@ -167,8 +167,6 @@
     public static final int ERROR_XWIKI_APP_REDIRECT_EXCEPTION = 11010;
     public static final int ERROR_XWIKI_APP_SEND_RESPONSE_EXCEPTION = 11011;
     public static final int ERROR_XWIKI_APP_SERVICE_NOT_FOUND = 11012;
-    public static final int ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE = 11013;
-    public static final int ERROR_XWIKI_APP_JAVA_HEAP_SPACE = 11014;
     public static final int ERROR_XWIKI_EXPORT_XSL_FILE_NOT_FOUND = 12001;
     public static final int ERROR_XWIKI_EXPORT_PDF_FOP_FAILED = 12002;
     public static final int ERROR_XWIKI_EXPORT_XSL_FAILED = 12003;

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java	2006-03-31 06:37:33 UTC (rev 1024)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java	2006-03-31 10:09:15 UTC (rev 1025)
@@ -39,7 +39,10 @@
 import com.xpn.xwiki.render.XWikiVelocityRenderer;
 import com.xpn.xwiki.store.XWikiStoreInterface;
 import com.xpn.xwiki.util.Util;
-import com.xpn.xwiki.web.*;
+import com.xpn.xwiki.web.EditForm;
+import com.xpn.xwiki.web.ObjectAddForm;
+import com.xpn.xwiki.web.PrepareEditForm;
+import com.xpn.xwiki.web.Utils;
 import org.apache.commons.jrcs.diff.Diff;
 import org.apache.commons.jrcs.diff.DifferentiationFailedException;
 import org.apache.commons.jrcs.diff.Revision;
@@ -491,7 +494,7 @@
         URL url = context.getURLFactory().createAttachmentURL(filename, getWeb(), getName(), action, querystring, context);
         return context.getURLFactory().getURL(url, context);
     }
-    
+
     public String getAttachmentRevisionURL(String filename, String revision, XWikiContext context) {
         URL url = context.getURLFactory().createAttachmentRevisionURL(filename, getWeb(), getName(), revision, null, context);
         return context.getURLFactory().getURL(url, context);
@@ -1654,17 +1657,9 @@
             // get the translated content
             if (getDatabase() != null)
                 context.setDatabase(getDatabase());
-           /* File Upload  is big can throws Exception ERROR_XWIKI_APP_JAVA_HEAP_SPACE
-             when saveAttachmentContent */            
-           context.getWiki().getAttachmentStore().saveAttachmentContent(attachment, context,true);
-        }catch(java.lang.OutOfMemoryError e){
-            context.getWiki().getAttachmentStore().cleanUp(context);
-            context.getWiki().flushCache();
-            throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
-                    XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE,
-                    "Out Of Memory Exception");
-        }
-        finally {
+
+            context.getWiki().getAttachmentStore().saveAttachmentContent(attachment, context, true);
+        } finally {
             if (database != null)
                 context.setDatabase(database);
         }
@@ -1692,15 +1687,8 @@
             // get the translated content
             if (getDatabase() != null)
                 context.setDatabase(getDatabase());
-            try{
-               context.getWiki().getAttachmentStore().deleteXWikiAttachment(attachment, context, true);
-            }catch(java.lang.OutOfMemoryError e){
-                context.getWiki().getAttachmentStore().cleanUp(context);
-                throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
-                    XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE,
-                    "Out Of Memory Exception"); 
-            }
 
+            context.getWiki().getAttachmentStore().deleteXWikiAttachment(attachment, context, true);
         } finally {
             if (database != null)
                 context.setDatabase(database);

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPlugin.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPlugin.java	2006-03-31 06:37:33 UTC (rev 1024)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPlugin.java	2006-03-31 10:09:15 UTC (rev 1025)
@@ -1,25 +1,25 @@
-/*
- * Copyright 2006, XpertNet SARL, and individual contributors as indicated
- * by the contributors.txt.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- *
- * @author ludovic
- * @author sdumitriu
- */
+/*
+ * Copyright 2006, XpertNet SARL, and individual contributors as indicated
+ * by the contributors.txt.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * @author ludovic
+ * @author sdumitriu
+ */
 
 package com.xpn.xwiki.plugin.fileupload;
 
@@ -29,7 +29,10 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.commons.fileupload.*;
+import org.apache.commons.fileupload.DefaultFileItem;
+import org.apache.commons.fileupload.DiskFileUpload;
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileUploadException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -69,7 +72,7 @@
     public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context) {
         return new FileUploadPluginApi((FileUploadPlugin) plugin, context);
     }
-
+    
     /**
      *  endRendering to make sure we don't leave files in temp directories
      * @param context Context of the request
@@ -124,9 +127,8 @@
         fileupload.setSizeMax(uploadMaxSize);
         fileupload.setSizeThreshold(uploadSizeThreashold);
         context.put("fileupload", fileupload);
-        XWikiRequest request = context.getRequest() ;
 
-        if (tempdir != null) {
+        if (tempdir!=null) {
             fileupload.setRepositoryPath(tempdir);
             (new File(tempdir)).mkdirs();
         }
@@ -135,14 +137,11 @@
         }
 
         try {
+            XWikiRequest request = context.getRequest();
             List list = fileupload.parseRequest(request.getHttpServletRequest());
-            // We store the file list in the context, throw Exception ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE
+            // We store the file list in the context
             context.put("fileuploadlist", list);
-        }catch (FileUploadBase.SizeLimitExceededException  e) {
-              throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
-                    XWikiException.ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE,
-                    "Exception uploaded file");
-        }catch(FileUploadException e){
+        } catch (FileUploadException e) {
             throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
                     XWikiException.ERROR_XWIKI_APP_UPLOAD_PARSE_EXCEPTION,
                     "Exception while parsing uploaded file", e);
@@ -186,35 +185,16 @@
         if (fileitem==null)
             return null;
 
-        byte[] data = null ;
-        if(fileitem.getSize() > Integer.MAX_VALUE){
-            data = new byte[Integer.MAX_VALUE] ;
-        }else{
-            try{
-                data = new byte[(int)fileitem.getSize()];
-            }catch(Exception e ){
-                XWikiException exp = new XWikiException(XWikiException.MODULE_XWIKI_APP,
-                        XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE,"Java Heap Space, Out of memory exception");
-
-            }
-
-        }
+        byte[] data = new byte[(int)fileitem.getSize()];
+        InputStream fileis = null;
         try {
-            InputStream fileis = fileitem.getInputStream();
-            if(fileis != null){
-              fileis.read(data);
-              fileis.close();
-            }
-
+            fileis = fileitem.getInputStream();
+            fileis.read(data);
+            fileis.close();
         } catch (IOException e) {
-            XWikiException exp = new XWikiException(XWikiException.MODULE_XWIKI_APP,
-                   XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE,"Java Heap Space, Out of memory exception");
-
-            /*
             throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
                     XWikiException.ERROR_XWIKI_APP_UPLOAD_FILE_EXCEPTION,
                     "Exception while reading uploaded parsed file", e);
-            */
         }
         return data;
     }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java	2006-03-31 06:37:33 UTC (rev 1024)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java	2006-03-31 10:09:15 UTC (rev 1025)
@@ -31,8 +31,8 @@
         XWikiRequest request = context.getRequest();
         XWikiResponse response = context.getResponse();
         XWikiDocument doc = context.getDoc();
-        XWikiAttachment attachment =null;
-        String filename = null;
+        XWikiAttachment attachment = null;
+        String filename;
         String path = request.getPathInfo();
         if (context.getMode() == XWikiContext.MODE_PORTLET)
             filename = request.getParameter("filename");
@@ -42,37 +42,14 @@
         if (request.getParameter("id") != null) {
             int id = Integer.parseInt(request.getParameter("id"));
             attachment = (XWikiAttachment) doc.getAttachmentList().get(id);
-            doc.deleteAttachment(attachment, context);
         } else {
-
-            try{
-                attachment = doc.getAttachment(filename);
-            }catch(Exception e){
-                if(attachment != null){
-                    return false ;
-                }
-            }
-            try{
-                doc.deleteAttachment(attachment, context);
-            }catch(XWikiException e){
-                if(e.getCode()==XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE){
-                    context.put("message","javaheapspace");
-                    return true;
-                }else{
-                    e.printStackTrace();
-                }
-            }
-
-
-
+            attachment = doc.getAttachment(filename);
         }
 
+        doc.deleteAttachment(attachment, context);
         // forward to attach page
         String redirect = Utils.getRedirect("attach", context);
         sendRedirect(response, redirect);
         return false;
     }
-    public String render(XWikiContext context) throws XWikiException {
-        return "exception";
-    }
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/UploadAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/UploadAction.java	2006-03-31 06:37:33 UTC (rev 1024)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/UploadAction.java	2006-03-31 10:09:15 UTC (rev 1025)
@@ -35,60 +35,47 @@
     public boolean action(XWikiContext context) throws XWikiException {
         XWikiResponse response = context.getResponse();
         XWikiDocument doc = context.getDoc();
+
         String username = context.getUser();
-        Object exception = context.get("exception");
-        // check Exception File upload is large
-        if(exception != null){
-            if(exception instanceof XWikiException){
-                XWikiException exp = (XWikiException) exception ;
-                if(exp.getCode() == XWikiException.ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE) {
-                    context.put("message","fileuploadislarge");
-                    return true ;
-                }
-            }
-        }
+
         FileUploadPlugin fileupload = (FileUploadPlugin) context.get("fileuploadplugin");
+
         String filename = fileupload.getFileItem("filename", context);
+        if (filename!=null) {
+         if (filename.indexOf("/") != -1 || filename.indexOf("\\") != -1 || filename.indexOf(";") != -1){
+             context.put("message","notsupportcharacters");
+             return true ;
+         }
+        }
+        byte[] data = fileupload.getFileItemData("filepath", context);
 
-        byte[] data = data = fileupload.getFileItemData("filepath", context);
         if (filename==null) {
             String fname = fileupload.getFileName("filepath", context);
             int i = fname.indexOf("\\");
             if (i==-1)
-                i = fname.indexOf("/");
+                i = fname.indexOf ("/");
             filename = fname.substring(i+1);
         }
         filename = filename.replaceAll("\\+"," ");
-
-        //XWikiDocument olddoc = (XWikiDocument) doc.clone();
         // Read XWikiAttachment
         XWikiAttachment attachment = doc.getAttachment(filename);
+
         if (attachment==null) {
             attachment = new XWikiAttachment();
             doc.getAttachmentList().add(attachment);
         }
         attachment.setContent(data);
         attachment.setFilename(filename);
+
         // TODO: handle Author
         attachment.setAuthor(username);
 
-
         // Add the attachment to the document
         attachment.setDoc(doc);
 
         // Save the content and the archive
-        try{
-             doc.saveAttachmentContent(attachment, context);
-        }catch(XWikiException e){
-            // check Exception is ERROR_XWIKI_APP_JAVA_HEAP_SPACE when saving Attachment
-            if(e.getCode() == XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE){
-                context.put("message","javaheapspace");
-                return true ;
-            }else{
-                e.printStackTrace();
-            }
-        }
-        //context.getWiki().saveDocument(doc,olddoc,context);
+        doc.saveAttachmentContent(attachment, context);
+
         // forward to attach page
         String redirect = fileupload.getFileItem("xredirect", context);
         if ((redirect == null)||(redirect.equals("")))
@@ -96,9 +83,7 @@
         sendRedirect(response, redirect);
         return false;
     }
-
     public String render(XWikiContext context) throws XWikiException {
         return "exception";
     }
-
 }
\ No newline at end of file

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/Utils.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/Utils.java	2006-03-31 06:37:33 UTC (rev 1024)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/Utils.java	2006-03-31 10:09:15 UTC (rev 1025)
@@ -38,7 +38,9 @@
 import org.apache.struts.upload.MultipartRequestWrapper;
 
 import javax.servlet.http.HttpServletRequest;
-import java.io.*;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
 import java.net.URL;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
@@ -426,16 +428,8 @@
                 }
             }
         }
-        catch (XWikiException e) {
-           if(e.getCode() ==XWikiException.ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE){
-           /* Check Exception is ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE = true
-              then put Exception so UploadAction can catching and return messenge
-                                                                                    */
-                context.put("exception",e);
-           }else {
-               e.printStackTrace();
-           }
-
+        catch (Exception e) {
+            e.printStackTrace();
         }
         return fileupload;
     }

Modified: xwiki/trunk/src/main/web/templates/attach.vm
===================================================================
--- xwiki/trunk/src/main/web/templates/attach.vm	2006-03-31 06:37:33 UTC (rev 1024)
+++ xwiki/trunk/src/main/web/templates/attach.vm	2006-03-31 10:09:15 UTC (rev 1025)
@@ -56,18 +56,8 @@
   if (form.filename.value=="")
    form.filename.value = fname;
   else {
-   if (confirm("$msg.get("doyouwanttoreplace") '" + fname + "' ?")){
+   if (confirm("$msg.get("doyouwanttoreplace") '" + fname + "' ?"))
      form.filename.value = fname;
-   }else{
-
-     fname = form.filename.value;
-     if(fname.indexOf('\\') != -1 || fname.indexOf('/') != -1
-             || fname.indexOf(':') != -1 || fname.indexOf(';') != -1 ){
-         alert("filename cannot contain any of the following characters \n '\\' '/' ':' ';'");
-         return false ;
-     }
-     return true ;
-   }
   }
   return true;
 }
@@ -83,4 +73,4 @@
 </form>
 </div>
 #template("basefooter.vm")
-#template("footer.vm")
\ No newline at end of file
+#template("footer.vm")

Copied: xwiki/trunk/src/main/web/xwiki.js (from rev 1022, xwiki/trunk/src/main/web/xwiki.js)





More information about the Xwiki-notifications mailing list