You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by lu...@apache.org on 2011/10/10 09:27:50 UTC

svn commit: r1180801 - in /turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload: DefaultUploadService.java UploadService.java

Author: ludwig
Date: Mon Oct 10 07:27:49 2011
New Revision: 1180801

URL: http://svn.apache.org/viewvc?rev=1180801&view=rev
Log:
Added methods from the streaming API

Modified:
    turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/DefaultUploadService.java
    turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/UploadService.java

Modified: turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/DefaultUploadService.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/DefaultUploadService.java?rev=1180801&r1=1180800&r2=1180801&view=diff
==============================================================================
--- turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/DefaultUploadService.java (original)
+++ turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/DefaultUploadService.java Mon Oct 10 07:27:49 2011
@@ -22,6 +22,7 @@ package org.apache.fulcrum.upload;
 
 
 import java.io.File;
+import java.io.IOException;
 import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
@@ -35,6 +36,7 @@ import org.apache.avalon.framework.conte
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileItemIterator;
 import org.apache.commons.fileupload.FileUploadException;
 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
 import org.apache.commons.fileupload.servlet.ServletFileUpload;
@@ -253,4 +255,51 @@ public class DefaultUploadService
     {
         this.applicationRoot = context.get( "urn:avalon:home" ).toString();
     }
+
+    /**
+     * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
+     * compliant <code>multipart/form-data</code> stream.
+     *
+     * @param request The servlet request to be parsed.
+     *
+     * @return An iterator to instances of <code>FileItemStream</code>
+     *         parsed from the request, in the order that they were
+     *         transmitted.
+     *
+     * @throws ServiceException if there are problems reading/parsing
+     *                             the request or storing files. This 
+     *                             may also be a network error while 
+     *                             communicating with the client or a 
+     *                             problem while storing the uploaded 
+     *                             content.
+     */    
+    public FileItemIterator getItemIterator(HttpServletRequest req) throws ServiceException {
+        ServletFileUpload upload = new ServletFileUpload();
+        try
+        {
+            return upload.getItemIterator(req);
+        } 
+        catch (FileUploadException e)
+        {
+            throw new ServiceException(UploadService.ROLE, e.getMessage(), e);
+        } 
+        catch (IOException e)
+        {
+            throw new ServiceException(UploadService.ROLE, e.getMessage(), e);
+        }        
+    }
+
+    /**
+     * Utility method that determines whether the request contains multipart
+     * content.
+     *
+     * @param request The servlet request to be evaluated. Must be non-null.
+     *
+     * @return <code>true</code> if the request is multipart;
+     *         <code>false</code> otherwise.
+     */      
+    public boolean isMultipart(HttpServletRequest req)
+    {
+        return ServletFileUpload.isMultipartContent(req);
+    }
 }

Modified: turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/UploadService.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/UploadService.java?rev=1180801&r1=1180800&r2=1180801&view=diff
==============================================================================
--- turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/UploadService.java (original)
+++ turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/UploadService.java Mon Oct 10 07:27:49 2011
@@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletReq
 
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileItemIterator;
 
 /**
  * <p> This service handles parsing <code>multipart/form-data</code>
@@ -181,6 +182,27 @@ public interface UploadService
         int sizeMax, String path)
         throws ServiceException;
 
+
+    /**
+     * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
+     * compliant <code>multipart/form-data</code> stream.
+     *
+     * @param request The servlet request to be parsed.
+     *
+     * @return An iterator to instances of <code>FileItemStream</code>
+     *         parsed from the request, in the order that they were
+     *         transmitted.
+     *
+     * @throws ServiceException if there are problems reading/parsing
+     *                             the request or storing files. This 
+     *                             may also be a network error while 
+     *                             communicating with the client or a 
+     *                             problem while storing the uploaded 
+     *                             content.
+     */
+    FileItemIterator getItemIterator(HttpServletRequest req) throws ServiceException;
+    
+    
     /**
      * <p> Retrieves the value of <code>size.max</code> property of the
      * {@link org.apache.fulcrum.upload.UploadService}.
@@ -212,4 +234,16 @@ public interface UploadService
      * @return Returns the headerEncoding.
      */
     String getHeaderEncoding();
+
+    /**
+     * Utility method that determines whether the request contains multipart
+     * content.
+     *
+     * @param request The servlet request to be evaluated. Must be non-null.
+     *
+     * @return <code>true</code> if the request is multipart;
+     *         <code>false</code> otherwise.
+     */    
+    boolean isMultipart(HttpServletRequest req);
+    
 }