jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jalka...@apache.org
Subject svn commit: r646060 - in /incubator/jspwiki/trunk: .classpath ChangeLog lib/commons-fileupload-1.2.1.jar lib/commons-io-1.4.jar lib/multipartrequest.jar src/com/ecyrd/jspwiki/Release.java src/com/ecyrd/jspwiki/attachment/AttachmentServlet.java
Date Tue, 08 Apr 2008 20:31:03 GMT
Author: jalkanen
Date: Tue Apr  8 13:31:01 2008
New Revision: 646060

URL: http://svn.apache.org/viewvc?rev=646060&view=rev
Log:
JSPWIKI-56: Replaced MultiPartRequest library with Apache Commons Fileupload to remove LGPL
dependency.

Added:
    incubator/jspwiki/trunk/lib/commons-fileupload-1.2.1.jar   (with props)
    incubator/jspwiki/trunk/lib/commons-io-1.4.jar   (with props)
Removed:
    incubator/jspwiki/trunk/lib/multipartrequest.jar
Modified:
    incubator/jspwiki/trunk/.classpath
    incubator/jspwiki/trunk/ChangeLog
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/attachment/AttachmentServlet.java

Modified: incubator/jspwiki/trunk/.classpath
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/.classpath?rev=646060&r1=646059&r2=646060&view=diff
==============================================================================
--- incubator/jspwiki/trunk/.classpath (original)
+++ incubator/jspwiki/trunk/.classpath Tue Apr  8 13:31:01 2008
@@ -16,7 +16,6 @@
 	<classpathentry kind="lib" path="lib/oscache.jar" sourcepath="/Users/jalkanen/Java/oscache-2.2/src/java"/>
 	<classpathentry kind="lib" path="lib/oro.jar"/>
 	<classpathentry kind="lib" path="lib/nekohtml.jar"/>
-	<classpathentry kind="lib" path="lib/multipartrequest.jar"/>
 	<classpathentry kind="lib" path="lib/lucene.jar"/>
 	<classpathentry kind="lib" path="tests/lib/junit.jar"/>
 	<classpathentry kind="lib" path="tests/etc"/>
@@ -32,6 +31,7 @@
 	<classpathentry kind="lib" path="lib/jakarta-taglibs-jstl-1.1.2.jar"/>
 	<classpathentry kind="lib" path="lib/jakarta-tablibs-standard-1.1.2.jar"/>
 	<classpathentry kind="lib" path="lib/jug-asl-2.0.0.jar"/>
+	<classpathentry kind="lib" path="lib/commons-fileupload-1.2.1.jar"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/JVM
1.5.0"/>
 	<classpathentry kind="output" path="classes"/>
 </classpath>

Modified: incubator/jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=646060&r1=646059&r2=646060&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Tue Apr  8 13:31:01 2008
@@ -1,21 +1,28 @@
-2007-3-05  Dirk Frederickx <dirk.frederickx@gmail.com>
+2008-04-08  Janne Jalkanen <jalkanen@apache.org>
+
+        * 2.7.0-svn-7
+        
+        * [JSPWIKI-56] Replaced MultiPartLibrary with Apache Commons
+        FileUpload library, as MultiPartLibrary was LGPL.
+
+2007-04-05  Dirk Frederickx <dirk.frederickx@gmail.com>
 
         * 2.7.0-svn-6
         
         * [JSPWIKI-233] Bugfix PreferencesTab.jsp
         
-2007-3-05  Dirk Frederickx <dirk.frederickx@gmail.com>
+2007-04-05  Dirk Frederickx <dirk.frederickx@gmail.com>
 
         * 2.7.0-svn-5
         
         * [JSPWIKI-230] Make TimeZone configuration more user-friendly. Adjusted all jsp
time-formatting
         to take timezone setting into account. 
         
-2007-3-05  Dirk Frederickx <dirk.frederickx@gmail.com>
+2007-04-05  Dirk Frederickx <dirk.frederickx@gmail.com>
 
         * Commit related JIRA id's
         
-2007-3-05  Dirk Frederickx <dirk.frederickx@gmail.com>
+2007-04-05  Dirk Frederickx <dirk.frederickx@gmail.com>
 
         * 2.7.0-svn-4
         

Added: incubator/jspwiki/trunk/lib/commons-fileupload-1.2.1.jar
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/lib/commons-fileupload-1.2.1.jar?rev=646060&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/jspwiki/trunk/lib/commons-fileupload-1.2.1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/jspwiki/trunk/lib/commons-io-1.4.jar
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/lib/commons-io-1.4.jar?rev=646060&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/jspwiki/trunk/lib/commons-io-1.4.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java?rev=646060&r1=646059&r2=646060&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java Tue Apr  8 13:31:01 2008
@@ -77,7 +77,7 @@
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "6";
+    public static final String     BUILD         = "7";
     
     /**
      *  This is the generic version string you should use

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/attachment/AttachmentServlet.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/attachment/AttachmentServlet.java?rev=646060&r1=646059&r2=646060&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/attachment/AttachmentServlet.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/attachment/AttachmentServlet.java Tue Apr
 8 13:31:01 2008
@@ -27,7 +27,7 @@
 import java.net.SocketException;
 import java.security.Permission;
 import java.security.Principal;
-import java.util.Enumeration;
+import java.util.List;
 import java.util.Properties;
 
 import javax.servlet.ServletConfig;
@@ -36,10 +36,12 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import net.iamvegan.multipartrequest.HttpServletMultipartRequest;
-import net.iamvegan.multipartrequest.MultipartFile;
-import net.iamvegan.multipartrequest.ProgressListener;
-
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileItemFactory;
+import org.apache.commons.fileupload.FileUploadException;
+import org.apache.commons.fileupload.ProgressListener;
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
+import org.apache.commons.fileupload.servlet.ServletFileUpload;
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 
@@ -558,6 +560,7 @@
      *  @return The page to which we should go next.
      *  @throws RedirectException If there's an error and a redirection is needed
      *  @throws IOException If upload fails
+     * @throws FileUploadException 
      */
     protected String upload( HttpServletRequest req )
         throws RedirectException,
@@ -570,10 +573,16 @@
 
         String progressId = req.getParameter( "progressid" );
 
+        // Check that we have a file upload request
+        if( !ServletFileUpload.isMultipartContent(req) )
+        {
+            throw new RedirectException( "Not a file upload", errorPage );
+        }
+        
         try
         {
-            HttpServletMultipartRequest multi;
-
+            FileItemFactory factory = new DiskFileItemFactory();
+            
             // Create the context _before_ Multipart operations, otherwise
             // strict servlet containers may fail when setting encoding.
             WikiContext context = m_engine.createContext( req, WikiContext.ATTACH );
@@ -582,45 +591,68 @@
 
             m_engine.getProgressManager().startProgress( pl, progressId );
 
-            multi = new HttpServletMultipartRequest( req,
-                                                     Long.MAX_VALUE,
-                                                     HttpServletMultipartRequest.SAVE_TO_TMPDIR,
-                                                     HttpServletMultipartRequest.ABORT_ON_MAX_LENGTH,
-                                                     "UTF-8",
-                                                     pl );
-
-            nextPage        = validateNextPage( multi.getParameter( "nextpage" ), errorPage
);
-            String wikipage = multi.getParameter( "page" );
-            String changeNote = multi.getParameter( "changenote" );
-
-            //
-            // FIXME: Kludge alert.  We must end up with the parent page name,
-            //        if this is an upload of a new revision
-            //
-
-            int x = wikipage.indexOf("/");
-
-            if( x != -1 ) wikipage = wikipage.substring(0,x);
+            ServletFileUpload upload = new ServletFileUpload(factory);
+            upload.setHeaderEncoding("UTF-8");
+            upload.setFileSizeMax( m_maxSize );
+            upload.setProgressListener( pl );
+            List<FileItem> items = upload.parseRequest( req );
+            
+            String wikipage = null, changeNote = null;
+            FileItem actualFile = null;
+            
+            for( FileItem item : items )
+            {
+                if( item.isFormField() )
+                {
+                    if( item.getFieldName().equals("page") )
+                    {
+                        //
+                        // FIXME: Kludge alert.  We must end up with the parent page name,
+                        //        if this is an upload of a new revision
+                        //
+
+                        wikipage = item.getString("UTF-8");
+                        int x = wikipage.indexOf("/");
+
+                        if( x != -1 ) wikipage = wikipage.substring(0,x);
+                    }
+                    else if( item.getFieldName().equals("changenote") )
+                    {
+                        changeNote = item.getString("UTF-8");
+                    }
+                    else if( item.getFieldName().equals( "nextpage" ) )
+                    {
+                        nextPage = validateNextPage( item.getString("UTF-8"), errorPage );
+                    }
+                }
+                else
+                {
+                    actualFile = item;
+                }
+            }
 
             //
-            //  Go through all files being uploaded.
-            //
-            Enumeration files = multi.getFileParameterNames();
-            long fileSize = 0L;
-            while( files.hasMoreElements() )
+            // FIXME: Unfortunately, with Apache fileupload we will get the form fields in
+            //        order.  This means that we have to gather all the metadata from the
+            //        request prior to actually touching the uploaded file itself.  This
+            //        is because the changenote appears after the file upload box, and we
+            //        would not have this information when uploading.  This also means
+            //        that with current structure we can only support a single file upload
+            //        at a time.
+            //
+            String filename = actualFile.getName();
+            long   fileSize = actualFile.getSize();
+            InputStream in  = actualFile.getInputStream();
+            
+            try
             {
-                String part = (String) files.nextElement();
-                MultipartFile multiFile = multi.getFileParameter(part);
-                fileSize += multiFile.getSize();
-                InputStream in = multiFile.getInputStream();
-
-                String filename = multiFile.getName();
-
                 executeUpload( context, in, filename, nextPage, wikipage, changeNote, fileSize
);
             }
+            finally
+            {
+                in.close();
+            }
 
-            // Inform the JSP page of which file we are handling:
-            // req.setAttribute( ATTR_ATTACHMENT, wikiname );
         }
         catch( ProviderException e )
         {
@@ -637,6 +669,15 @@
             log.warn( msg + " (attachment: " + attName + ")", e );
 
             throw e;
+        }
+        catch (FileUploadException e)
+        {
+            // Show the submit page again, but with a bit more
+            // intimidating output.
+            msg = "Upload failure: " + e.getMessage();
+            log.warn( msg + " (attachment: " + attName + ")", e );
+
+            throw new IOException( msg );
         }
         finally
         {



Mime
View raw message