dlr         01/05/18 11:26:05

  Modified:    src/java/org/apache/turbine/services/upload
                        FileHandlerUploadService.java
                        OReillyUploadService.java TurbineUploadService.java
  Log:
  Extended BaseUploadService.
  
  Revision  Changes    Path
  1.7       +9 -7      
jakarta-turbine/src/java/org/apache/turbine/services/upload/FileHandlerUploadService.java
  
  Index: FileHandlerUploadService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/upload/FileHandlerUploadService.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FileHandlerUploadService.java     2001/05/13 19:51:43     1.6
  +++ FileHandlerUploadService.java     2001/05/18 18:25:55     1.7
  @@ -66,15 +66,16 @@
    * request & store files.
    *
    * <p> This class is intended for compatibity with old code.  Use
  - * {@link TurbineUploadService} in new applications.
  + * {@link org.apache.turbine.services.upload.TurbineUploadService} in
  + * new applications.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Rafal Krzewski</a>
  - * @version $Id: FileHandlerUploadService.java,v 1.6 2001/05/13 19:51:43 jvanzyl 
Exp $
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel Rall</a>
  + * @version $Id: FileHandlerUploadService.java,v 1.7 2001/05/18 18:25:55 dlr Exp $
    * @deprecated use TurbineUploadService
    */
   public class FileHandlerUploadService
  -    extends TurbineBaseService
  -    implements UploadService
  +    extends BaseUploadService
   {
       /**
        * <p>Processes an <a href="http://rf.cx/rfc1867.html";>RFC
  @@ -92,16 +93,17 @@
                                 String path )
           throws TurbineException
       {
  -        String fileRepository = TurbineUpload.getRepository();
  +        String fileRepository = getRepository();
           FileHandler handler = new FileHandler( req, params, fileRepository );
  -        handler.setMaxSize( TurbineUpload.getSizeMax() );
  +        handler.setMaxSize( getSizeMax() );
           try
           {
               handler.saveStream();
           }
           catch (Exception e)
           {
  -            throw new TurbineException("File upload using FileHandler failed", e);
  +            throw new TurbineException("File upload using FileHandler failed",
  +                                       e);
           }
       }
   }
  
  
  
  1.8       +4 -5      
jakarta-turbine/src/java/org/apache/turbine/services/upload/OReillyUploadService.java
  
  Index: OReillyUploadService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/upload/OReillyUploadService.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- OReillyUploadService.java 2001/05/13 19:51:43     1.7
  +++ OReillyUploadService.java 2001/05/18 18:25:56     1.8
  @@ -66,19 +66,18 @@
   
   /**
    * <p> This is an implementation of the {@link UploadService} using
  - * the O'Reilly multipart request parser from the book Java Servlet
  - * Programming by Jason Hunter.
  + * the O'Reilly multipart request parser from the book <i>Java Servlet
  + * Programming</i> by Jason Hunter.
    *
    * <p> This class is intended for compatibity with old code.  Use
    * {@link TurbineUploadService} in new applications.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Rafal Krzewski</a>
  - * @version $Id: OReillyUploadService.java,v 1.7 2001/05/13 19:51:43 jvanzyl Exp $
  + * @version $Id: OReillyUploadService.java,v 1.8 2001/05/18 18:25:56 dlr Exp $
    * @deprecated use TurbineUploadService
    */
   public class OReillyUploadService
  -    extends TurbineBaseService
  -    implements UploadService
  +    extends BaseUploadService
   {
       /** Holds a vector of the filenames that were uploaded. */
       private Vector filenames = null;
  
  
  
  1.15      +43 -59    
jakarta-turbine/src/java/org/apache/turbine/services/upload/TurbineUploadService.java
  
  Index: TurbineUploadService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/upload/TurbineUploadService.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- TurbineUploadService.java 2001/05/05 14:03:45     1.14
  +++ TurbineUploadService.java 2001/05/18 18:25:57     1.15
  @@ -59,7 +59,6 @@
   import java.io.OutputStream;
   import java.util.Hashtable;
   import java.util.Properties;
  -import javax.servlet.ServletConfig;
   import javax.servlet.ServletContext;
   import javax.servlet.ServletInputStream;
   import javax.servlet.ServletRequest;
  @@ -89,43 +88,13 @@
    * html widget.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Rafal Krzewski</a>
  - * @version $Id: TurbineUploadService.java,v 1.14 2001/05/05 14:03:45 jvanzyl Exp $
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel Rall</a>
  + * @version $Id: TurbineUploadService.java,v 1.15 2001/05/18 18:25:57 dlr Exp $
    */
   public class TurbineUploadService
  -    extends TurbineBaseService
  -    implements UploadService
  +    extends BaseUploadService
   {
       /**
  -     * A maximum lenght of a single header line that will be
  -     * parsed. (1024 bytes).
  -     */
  -    public static final int MAX_HEADER_SIZE = 1024;
  -
  -    /**
  -     * Initializes the service.
  -     *
  -     * This method processes the repository path, to make it relative to the web
  -     * application root, if neccessary
  -     *
  -     * @param config the ServletConfig of the Turbine servlet
  -     */
  -    public void init(ServletConfig config)
  -    {
  -        String path = getProperties()
  -            .getProperty(UploadService.REPOSITORY_KEY,
  -                         UploadService.REPOSITORY_DEFAULT.toString());
  -        if(!path.startsWith("/")) 
  -        {
  -            String realPath = config.getServletContext().getRealPath(path);
  -            if(realPath != null)
  -            {
  -                path = realPath;
  -            }
  -        }
  -        getProperties().setProperty(UploadService.REPOSITORY_KEY, path);
  -    }
  -
  -    /**
        * <p> Processes an <a href="http://rf.cx/rfc1867.html";>RFC
        * 1867</a> compliant <code>multipart/form-data</code> stream.
        *
  @@ -262,43 +231,51 @@
       }
   
       /**
  -     * <p> Retrieves field name from 'Content-disposition' header.
  +     * <p> Retrieves file name from 'Content-disposition' header.
        *
  -     * @return A String with the field name for the current
  +     * @return A String with the file name for the current
        * <code>encapsulation</code>.
        */
  -    protected String getFieldName()
  +    protected String getFileName()
       {
  +        String fileName = null;
           String cd = getHeader("Content-disposition");
  -        if(cd == null || !cd.startsWith("form-data"))
  -            return null;
  -        int start = cd.indexOf("name=\"");
  -        int end = cd.indexOf('"', start+6);
  -        if(start == -1 || end == -1)
  -            return null;
  -        return cd.substring(start+6,end);
  +        if(cd.startsWith("form-data") || cd.startsWith("attachment"))
  +        {
  +            int start = cd.indexOf("filename=\"");
  +            int end = cd.indexOf('"', start + 10);
  +            if(start != -1 && end != -1 && (start + 10) != end)
  +            {
  +                String str = cd.substring(start + 10, end).trim();
  +                if (str.length() > 0)
  +                {
  +                    fileName = str;
  +                }
  +            }
  +        }
  +        return fileName;
       }
   
       /**
  -     * <p> Retrieves file name from 'Content-disposition' header.
  +     * <p> Retrieves field name from 'Content-disposition' header.
        *
  -     * @return A String with the file name for the current
  +     * @return A String with the field name for the current
        * <code>encapsulation</code>.
        */
  -    protected String getFileName()
  +    protected String getFieldName()
       {
  +        String fieldName = null;
           String cd = getHeader("Content-disposition");
  -        if(!cd.startsWith("form-data") && !cd.startsWith("attachment"))
  -            return null;
  -        int start = cd.indexOf("filename=\"");
  -        int end = cd.indexOf('"', start+10);
  -        if(start == -1 || end == -1 || (start + 10) == end)
  -            return null;
  -        String str = cd.substring(start+10,end).trim();
  -        if( str.length() == 0) 
  -            return null;
  -        else
  -            return str;
  +        if(cd != null && cd.startsWith("form-data"))
  +        {
  +            int start = cd.indexOf("name=\"");
  +            int end = cd.indexOf('"', start+6);
  +            if(start != -1 && end != -1)
  +            {
  +                fieldName = cd.substring(start + 6, end);
  +            }
  +        }
  +        return fieldName;
       }
   
       /**
  @@ -320,6 +297,8 @@
   
       /**
        * Stores parsed headers as key - value pairs.
  +     * <p>
  +     * <b>TODO: Correct this multi-threading nightmare.</b>
        */
       Hashtable headers;
   
  @@ -336,12 +315,17 @@
       protected void parseHeaders( String headerPart )
       {
           if (headers == null)
  +        {
               headers = new Hashtable();
  +        }
           else
  +        {
               headers.clear();
  +        }
  +
           char buffer[] = new char[MAX_HEADER_SIZE];
           boolean done = false;
  -        int j=0;
  +        int j = 0;
           int i;
           String header, headerName, headerValue;
           try
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to