[xwiki-commits] r1026 - 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 resources web/templates

jeremi joslin jeremi23 at gmail.com
Thu Apr 6 04:48:25 CEST 2006


Hi,
what is it for:
  #end
+    ##set($hello="hello")
 </div>

in xwiki/trunk/src/main/web/templates/exception.vm?

Jérémi

On 4/6/06, Nguyen Viet Chung <chungnv at users.forge.objectweb.org> wrote:
> Author: chungnv
> Date: 2006-04-06 04:36:20 +0200 (Thu, 06 Apr 2006)
> New Revision: 1026
>
> 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/UploadAction.java
>    xwiki/trunk/src/main/java/com/xpn/xwiki/web/Utils.java
>    xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiAction.java
>    xwiki/trunk/src/main/resources/ApplicationResources.properties
>    xwiki/trunk/src/main/web/templates/exception.vm
> Log:
> Fix bug upload big file in XWiki-170 .
> When upload big file over size max saying nice message.
> When upload big file . if throws Exception Java Heap Space Out Of Memory . Saying nice message .
>
> Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiException.java
> ===================================================================
> --- xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiException.java 2006-03-31 10:09:15 UTC (rev 1025)
> +++ xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiException.java 2006-04-06 02:36:20 UTC (rev 1026)
> @@ -167,6 +167,9 @@
>      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 10:09:15 UTC (rev 1025)
> +++ xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java      2006-04-06 02:36:20 UTC (rev 1026)
> @@ -39,10 +39,7 @@
>  import com.xpn.xwiki.render.XWikiVelocityRenderer;
>  import com.xpn.xwiki.store.XWikiStoreInterface;
>  import com.xpn.xwiki.util.Util;
> -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 com.xpn.xwiki.web.*;
>  import org.apache.commons.jrcs.diff.Diff;
>  import org.apache.commons.jrcs.diff.DifferentiationFailedException;
>  import org.apache.commons.jrcs.diff.Revision;
> @@ -1657,9 +1654,17 @@
>              // get the translated content
>              if (getDatabase() != null)
>                  context.setDatabase(getDatabase());
> -
> -            context.getWiki().getAttachmentStore().saveAttachmentContent(attachment, context, true);
> -        } finally {
> +           /* 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 {
>              if (database != null)
>                  context.setDatabase(database);
>          }
> @@ -1687,8 +1692,15 @@
>              // 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 10:09:15 UTC (rev 1025)
> +++ xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPlugin.java     2006-04-06 02:36:20 UTC (rev 1026)
> @@ -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,10 +29,7 @@
>  import java.util.ArrayList;
>  import java.util.List;
>
> -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.fileupload.*;
>  import org.apache.commons.logging.Log;
>  import org.apache.commons.logging.LogFactory;
>
> @@ -72,7 +69,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
> @@ -127,8 +124,9 @@
>          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();
>          }
> @@ -137,11 +135,14 @@
>          }
>
>          try {
> -            XWikiRequest request = context.getRequest();
>              List list = fileupload.parseRequest(request.getHttpServletRequest());
> -            // We store the file list in the context
> +            // We store the file list in the context, throw Exception ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE
>              context.put("fileuploadlist", list);
> -        } catch (FileUploadException e) {
> +        }catch (FileUploadBase.SizeLimitExceededException  e) {
> +              throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
> +                    XWikiException.ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE,
> +                    "Exception uploaded file");
> +        }catch(FileUploadException e){
>              throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
>                      XWikiException.ERROR_XWIKI_APP_UPLOAD_PARSE_EXCEPTION,
>                      "Exception while parsing uploaded file", e);
> @@ -185,16 +186,24 @@
>          if (fileitem==null)
>              return null;
>
> -        byte[] data = new byte[(int)fileitem.getSize()];
> -        InputStream fileis = null;
> -        try {
> -            fileis = fileitem.getInputStream();
> -            fileis.read(data);
> -            fileis.close();
> +        byte[] data = null ;
> +        try{
> +
> +            if(fileitem.getSize() > Integer.MAX_VALUE){
> +                data = new byte[Integer.MAX_VALUE] ;
> +            }else{
> +                data = new byte[(int)fileitem.getSize()];
> +            }
> +
> +            InputStream fileis = fileitem.getInputStream();
> +            if(fileis != null){
> +                fileis.read(data);
> +                fileis.close();
> +            }
> +
>          } catch (IOException e) {
> -            throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
> -                    XWikiException.ERROR_XWIKI_APP_UPLOAD_FILE_EXCEPTION,
> -                    "Exception while reading uploaded parsed file", e);
> +            XWikiException exp = new XWikiException(XWikiException.MODULE_XWIKI_APP,
> +                   XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE,"Java Heap Space, Out of memory exception");
>          }
>          return data;
>      }
>
> 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 10:09:15 UTC (rev 1025)
> +++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/UploadAction.java       2006-04-06 02:36:20 UTC (rev 1026)
> @@ -35,46 +35,67 @@
>      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);
>
> -        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);
> +        XWikiAttachment attachment = olddoc.getAttachment(filename);
>
>          if (attachment==null) {
>              attachment = new XWikiAttachment();
> -            doc.getAttachmentList().add(attachment);
> +            olddoc.getAttachmentList().add(attachment);
>          }
>          attachment.setContent(data);
>          attachment.setFilename(filename);
> -
>          // TODO: handle Author
>          attachment.setAuthor(username);
>
> +
>          // Add the attachment to the document
> -        attachment.setDoc(doc);
> +        attachment.setDoc(olddoc);
>
>          // Save the content and the archive
> -        doc.saveAttachmentContent(attachment, context);
> +        try{
> +             olddoc.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();
> +            }
> +        }
>
>          // forward to attach page
>          String redirect = fileupload.getFileItem("xredirect", context);
> @@ -83,7 +104,9 @@
>          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 10:09:15 UTC (rev 1025)
> +++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/Utils.java      2006-04-06 02:36:20 UTC (rev 1026)
> @@ -428,8 +428,14 @@
>                  }
>              }
>          }
> -        catch (Exception e) {
> -            e.printStackTrace();
> +        catch (XWikiException e) {
> +            if(e.getCode() ==XWikiException.ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE){
> +
> +                context.put("exception",e);
> +            }else {
> +                e.printStackTrace();
> +            }
> +
>          }
>          return fileupload;
>      }
>
> Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiAction.java
> ===================================================================
> --- xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiAction.java        2006-03-31 10:09:15 UTC (rev 1025)
> +++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiAction.java        2006-04-06 02:36:20 UTC (rev 1026)
> @@ -145,6 +145,7 @@
>                          Utils.parseTemplate(page, context);
>                      } else {
>                          String page = Utils.getPage(request, renderResult);
> +                        String url = context.getRequest().getRequestURI() ;
>                          Utils.parseTemplate(page, !page.equals("direct"), context);
>                      }
>
> @@ -152,11 +153,10 @@
>                  return null;
>              } catch (Throwable e) {
>                  if (!(e instanceof XWikiException)) {
> -                    e = new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_UNKNOWN,
> +                   e = new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_UNKNOWN,
>                              "Uncaught exception", e);
>                  }
>
> -                vcontext.put("exp", e);
>                  try {
>                      XWikiException xex = (XWikiException) e;
>                      if (xex.getCode() == XWikiException.ERROR_XWIKI_ACCESS_DENIED) {
> @@ -167,8 +167,13 @@
>                          String page = Utils.getPage(request, "userinactive");
>                          Utils.parseTemplate(page, context);
>                          return null;
> +                    }else if(xex.getCode() == XWikiException.ERROR_XWIKI_APP_ATTACHMENT_NOT_FOUND){
> +                        String page = Utils.getPage(request, "exception");
> +                        context.put("message","attachmentdoesnotexist");
> +                        Utils.parseTemplate(page, context);
> +                        return null;
>                      }
> -
> +                    vcontext.put("exp", e);
>                      Log log = LogFactory.getLog(XWikiAction.class);
>                      if (log.isWarnEnabled()) {
>                          log.warn("Uncaught exception: " + e.getMessage(), e);
> @@ -201,7 +206,7 @@
>                      xwiki.getNotificationManager().verify(context.getDoc(), mapping.getName(), context);
>                  } catch (Throwable e) {
>                      e.printStackTrace();
> -                }
> +                    }
>
>                  if (monitor != null)
>                      monitor.endTimer("notify");
>
> Modified: xwiki/trunk/src/main/resources/ApplicationResources.properties
> ===================================================================
> --- xwiki/trunk/src/main/resources/ApplicationResources.properties      2006-03-31 10:09:15 UTC (rev 1025)
> +++ xwiki/trunk/src/main/resources/ApplicationResources.properties      2006-04-06 02:36:20 UTC (rev 1026)
> @@ -196,10 +196,11 @@
>  attachmentdoesnotexist=The attachment does not exist.
>  wikicontentcannotbeempty= The content of a wiki page is not allowed to be completely empty.
>  fileuploadislarge=XWiki has a default limit of around 10Mb for attached files. This limit can be changed using the upload_maxsize parameter. Check the FAQ for more information.
> -javaheapspace=Out of memory Exception
> +javaheapspace=Upload file fail . Java Heap Space Out of memory Exception !
>  notsupportcharacters=File name does not support characters '\\' '/' ';'
>  youcanclicktoedit=You can click on "Edit this Page" to create it.
>  thistemplatedoesnotexist=This template does not exist
> +historyattachdoesnotexist=Attachment of history version does not exist
>
>  chartwizard=Chart Wizard
>  chwhide=hide
>
> Modified: xwiki/trunk/src/main/web/templates/exception.vm
> ===================================================================
> --- xwiki/trunk/src/main/web/templates/exception.vm     2006-03-31 10:09:15 UTC (rev 1025)
> +++ xwiki/trunk/src/main/web/templates/exception.vm     2006-04-06 02:36:20 UTC (rev 1026)
> @@ -1,11 +1,14 @@
>  #template("xwiki.vm")
>  #template("httpheader.vm")
>  #template("header.vm")
> -#template("baseheader.vm")
> +#template("viewheader.vm")
>  <div id="xwikicontent">
>      #set($message = $xwiki.parseMessage())
>      #if($message)
> -    $message
> +    <center>
> +        <h2>$message</h2>
> +        <br/><br/>
> +    </center>
>      #else
>      $msg.get("problemoccured")
>      #end
> @@ -16,6 +19,7 @@
>          $exp.getFullMessage()
>      </pre>
>      #end
> +    ##set($hello="hello")
>  </div>
>  #template("basefooter.vm")
>  #template("footer.vm")
>
>
>
>
>
> --
> 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
>
>
>


--
Blog: http://www.jeremi.info
LinkedIn: https://www.linkedin.com/profile?viewProfile=&key=1437724
Project Manager XWiki: http://www.xwiki.org
skype: jeremi23 -- msn et gtalk : jeremi23 at gmail.com


More information about the Xwiki-notifications mailing list