You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jm...@apache.org on 2002/03/24 22:45:11 UTC

cvs commit: jakarta-turbine-fulcrum/src/util/org/apache/fulcrum/util/parser DefaultParameterParser.java ParameterParser.java

jmcnally    02/03/24 13:45:11

  Modified:    .        build.xml default.properties deps.list project.xml
               src/services/org/apache/fulcrum/intake/model
                        FileItemField.java
               src/services/org/apache/fulcrum/intake/validator
                        FileValidator.java
               src/services/org/apache/fulcrum/upload TurbineUpload.java
                        TurbineUploadService.java UploadService.java
               src/util/org/apache/fulcrum/util/parser
                        DefaultParameterParser.java ParameterParser.java
  Removed:     src/services/org/apache/fulcrum/upload
                        BaseUploadService.java DefaultFileItem.java
                        FileItem.java MultipartStream.java
  Log:
  moved most of the file upload functionality into a commons component.  The
  service is a thin wrapper around this component.
  
  Revision  Changes    Path
  1.46      +15 -1     jakarta-turbine-fulcrum/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/build.xml,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- build.xml	18 Mar 2002 23:32:37 -0000	1.45
  +++ build.xml	24 Mar 2002 21:45:11 -0000	1.46
  @@ -16,6 +16,7 @@
       <pathelement location="${commons-email.jar}"/>
       <pathelement location="${commons-lang.jar}"/>
       <pathelement location="${commons-codec.jar}"/>
  +    <pathelement location="${commons-fileupload.jar}"/>
       <pathelement location="${jaf.jar}"/>
       <pathelement location="${javamail.jar}"/>
       <pathelement location="${jdbc.jar}"/>
  @@ -207,6 +208,12 @@
       />
   
       <available
  +      classname="org.apache.commons.fileupload.FileUpload"
  +      property="commons-fileupload.present"
  +      classpathref="classpath"
  +    />
  +
  +    <available
         classname="org.apache.commons.mail.SimpleEmail"
         property="commons-email.present"
         classpathref="classpath"
  @@ -327,6 +334,13 @@
       </antcall>
     </target>
   
  +  <target name="check.commons-fileupload" unless="commons-fileupload.present">
  +    <antcall target="property-warning">
  +      <param name="name" value="commons-fileupload.jar"/>
  +      <param name="value" value="${commons-fileupload.jar}"/>
  +    </antcall>
  +  </target>
  +
     <target name="check.regexp" unless="regexp.present">
       <antcall target="property-warning">
         <param name="name" value="regexp.jar"/>
  @@ -406,7 +420,7 @@
           check.servlet,check.javamail,check.jaf,check.xerces,check.xalan,
           check.xmlrpc,check.commons-collections,check.commons-lang,
           check.commons-codec,check.regexp,check.dvsl,check.dom4j,
  -        include-email,om">
  +        check.commons-fileupload,include-email,om">
   
       <!-- We have some static files that should overwrite
            The torque generated files so overwrite must be
  
  
  
  1.23      +4 -3      jakarta-turbine-fulcrum/default.properties
  
  Index: default.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/default.properties,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- default.properties	14 Mar 2002 19:55:37 -0000	1.22
  +++ default.properties	24 Mar 2002 21:45:11 -0000	1.23
  @@ -8,7 +8,7 @@
   
   name = Fulcrum
   project = fulcrum
  -version = 1.0
  +version = 3.0-b2-dev
   package = org.apache.${project}
   final.name = ${project}-${version}
   
  @@ -46,6 +46,7 @@
   commons-email.jar = ${lib.repo}/commons-email-0.1-dev.jar
   commons-lang.jar = ${lib.repo}/commons-lang-0.1-dev.jar
   commons-codec.jar = ${lib.repo}/commons-codec.jar
  +commons-fileupload.jar = ${lib.repo}/commons-fileupload-1.0-dev.jar
   dom4j.jar = ${lib.repo}/dom4j-1.1.jar
   dvsl.jar = ${lib.repo}/velocity-dvsl-0.40.jar
   jaf.jar = ${lib.repo}/activation-1.0.1.jar
  @@ -56,8 +57,8 @@
   log4j.jar = ${lib.repo}/log4j-1.1.3.jar
   regexp.jar = ${lib.repo}/jakarta-regexp-1.3-dev.jar
   servlet.jar = ${lib.repo}/servlet-2.2.jar
  -stratum.jar = ${lib.repo}/stratum-0.1-dev.jar
  -torque.jar = ${lib.repo}/torque-3.0-dev.jar
  +stratum.jar = ${lib.repo}/stratum-1.0-b2-dev.jar
  +torque.jar = ${lib.repo}/torque-3.0-b2-dev.jar
   velocity.jar = ${lib.repo}/velocity-1.3-dev.jar
   village.jar = ${lib.repo}/village-1.5.3-dev.jar
   xalan.jar = ${lib.repo}/xalan-2.1.0.jar
  
  
  
  1.8       +3 -2      jakarta-turbine-fulcrum/deps.list
  
  Index: deps.list
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/deps.list,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- deps.list	7 Mar 2002 23:43:47 -0000	1.7
  +++ deps.list	24 Mar 2002 21:45:11 -0000	1.8
  @@ -4,6 +4,7 @@
   commons-email-0.1-dev.jar
   commons-lang-0.1-dev.jar
   commons-codec.jar
  +commons-fileupload-1.0-dev.jar
   dom4j-1.1.jar
   jakarta-regexp-1.3-dev.jar
   jdbc2_0-stdext.jar
  @@ -12,8 +13,8 @@
   log4j-1.1.3.jar
   mail-1.2.jar
   servlet-2.2.jar
  -stratum-0.1-dev.jar
  -torque-3.0-dev.jar
  +stratum-1.0-b2-dev.jar
  +torque-3.0-b2-dev.jar
   velocity-1.3-dev.jar
   velocity-dvsl-0.40.jar
   village-1.5.3-dev.jar
  
  
  
  1.14      +7 -0      jakarta-turbine-fulcrum/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/project.xml,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- project.xml	20 Mar 2002 15:20:15 -0000	1.13
  +++ project.xml	24 Mar 2002 21:45:11 -0000	1.14
  @@ -121,6 +121,13 @@
       </dependency>
   
       <dependency>
  +      <name>commons-fileupload</name>
  +      <type>required</type>
  +      <version>1.0</version>
  +      <jar>commons-lang-1.0-dev.jar</jar>
  +    </dependency>
  +
  +    <dependency>
         <name>dom4j</name>
         <type>required</type>
         <version>1.3</version>
  
  
  
  1.4       +1 -1      jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/intake/model/FileItemField.java
  
  Index: FileItemField.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/intake/model/FileItemField.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FileItemField.java	18 Nov 2001 19:18:59 -0000	1.3
  +++ FileItemField.java	24 Mar 2002 21:45:11 -0000	1.4
  @@ -64,8 +64,8 @@
   // import org.apache.fulcrum.intake.validator.InitableByConstraintMap;
   import org.apache.fulcrum.intake.validator.ValidationException;
   import org.apache.fulcrum.intake.validator.Constraint;
  -import org.apache.fulcrum.upload.FileItem;
   import org.apache.fulcrum.ServiceException;
  +import org.apache.commons.fileupload.FileItem;
   
   /**
    * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
  
  
  
  1.2       +2 -2      jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/intake/validator/FileValidator.java
  
  Index: FileValidator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/intake/validator/FileValidator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FileValidator.java	23 Aug 2001 07:20:21 -0000	1.1
  +++ FileValidator.java	24 Mar 2002 21:45:11 -0000	1.2
  @@ -57,7 +57,7 @@
   import java.util.Map;
   import org.apache.regexp.RE;
   import org.apache.fulcrum.ServiceException;
  -import org.apache.fulcrum.upload.FileItem;
  +import org.apache.commons.fileupload.FileItem;
   
   /**
    * A validator that will compare a testValue against the following
  @@ -73,7 +73,7 @@
    * This validator can serve as the base class for more specific validators
    *
    * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
  - * @version $Id: FileValidator.java,v 1.1 2001/08/23 07:20:21 jmcnally Exp $
  + * @version $Id: FileValidator.java,v 1.2 2002/03/24 21:45:11 jmcnally Exp $
    */
   public class FileValidator
       implements Validator, InitableByConstraintMap
  
  
  
  1.4       +17 -26    jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/upload/TurbineUpload.java
  
  Index: TurbineUpload.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/upload/TurbineUpload.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TurbineUpload.java	24 Nov 2001 18:32:40 -0000	1.3
  +++ TurbineUpload.java	24 Mar 2002 21:45:11 -0000	1.4
  @@ -59,6 +59,7 @@
   import org.apache.fulcrum.InstantiationException;
   import org.apache.fulcrum.TurbineServices;
   import org.apache.fulcrum.ServiceException;
  +import org.apache.commons.fileupload.FileUpload;
   
   /**
    * <p> This is a facade class for {@link UploadService}.
  @@ -70,7 +71,7 @@
    * the service's properties and default values for them.
    *
    * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
  - * @version $Id: TurbineUpload.java,v 1.3 2001/11/24 18:32:40 mpoeschl Exp $
  + * @version $Id: TurbineUpload.java,v 1.4 2002/03/24 21:45:11 jmcnally Exp $
    */
   public abstract class TurbineUpload
   {
  @@ -86,31 +87,25 @@
               getService(UploadService.SERVICE_NAME);
       }
   
  +    private static FileUpload getComponent()
  +    {
  +        return (FileUpload)((UploadService)getService()).getComponent();
  +    }
  +
       /**
        * <p> Retrieves the value of 'automatic' property of {@link
        * UploadService}.
        *
        * @return The value of 'automatic' property of {@link
        * UploadService}.
  +     * @deprecated This is left over from coupling with
  +     * ParameterParser.  ParameterParser (and any other use of the
  +     * service) should determine for itself whether to call the
  +     * parseRequest method and not ask the service.
        */
       public static boolean getAutomatic()
       {
  -        UploadService upload = null;
  -        try
  -        {
  -            upload = getService();
  -        }
  -        catch(org.apache.fulcrum.InstantiationException ie)
  -        {
  -            // If the service couldn't be instantiated, it obviously
  -            // can't be used for automatic uploading.
  -            return false;
  -        }
  -
  -        boolean auto = upload.getConfiguration().getBoolean(
  -            UploadService.AUTOMATIC_KEY,UploadService.AUTOMATIC_DEFAULT);
  -
  -        return auto;
  +        return getService().getAutomatic();
       }
   
       /**
  @@ -122,7 +117,7 @@
        */
       public static int getSizeMax()
       {
  -        return getService().getSizeMax();
  +        return getComponent().getSizeMax();
       }
   
       /**
  @@ -133,7 +128,7 @@
        */
       public static int getSizeThreshold()
       {
  -        return getService().getSizeThreshold();
  +        return getComponent().getSizeThreshold();
       }
   
       /**
  @@ -144,7 +139,7 @@
        */
       public static String getRepository()
       {
  -        return getService().getRepository();
  +        return getComponent().getRepositoryPath();
       }
   
       /**
  @@ -162,7 +157,8 @@
       public static ArrayList parseRequest( HttpServletRequest req )
           throws ServiceException
       {
  -        return getService().parseRequest(req, getService().getRepository());
  +        return getService()
  +            .parseRequest(req, getComponent().getRepositoryPath());
       }
   
       /**
  @@ -184,10 +180,5 @@
           throws ServiceException
       {
           return getService().parseRequest(req, path);
  -    }
  -
  -    public static String getUniqueId()
  -    {
  -        return getService().getUniqueId();
       }
   }
  
  
  
  1.8       +89 -251   jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/upload/TurbineUploadService.java
  
  Index: TurbineUploadService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/upload/TurbineUploadService.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TurbineUploadService.java	24 Nov 2001 23:13:59 -0000	1.7
  +++ TurbineUploadService.java	24 Mar 2002 21:45:11 -0000	1.8
  @@ -57,6 +57,7 @@
   import java.io.IOException;
   import java.io.InputStream;
   import java.io.OutputStream;
  +import java.io.File;
   import java.util.Map;
   import java.util.ArrayList;
   import java.util.HashMap;
  @@ -67,6 +68,10 @@
   import javax.servlet.http.HttpServletRequest;
   import org.apache.fulcrum.BaseService;
   import org.apache.fulcrum.ServiceException;
  +import org.apache.fulcrum.InitializationException;
  +
  +import org.apache.commons.fileupload.FileUpload;
  +import org.apache.commons.fileupload.FileUploadException;
   
   /**
    * <p> This class is an implementation of {@link UploadService}.
  @@ -87,297 +92,130 @@
    * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
    * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  - * @version $Id: TurbineUploadService.java,v 1.7 2001/11/24 23:13:59 dlr Exp $
  + * @version $Id: TurbineUploadService.java,v 1.8 2002/03/24 21:45:11 jmcnally Exp $
    */
   public class TurbineUploadService
  -    extends BaseUploadService
  +    extends BaseService
  +    implements UploadService
   {
  +    protected Object component;
  +    private boolean automatic;
  +     
       /**
  -     * @see org.apache.fulcrum.upload.UploadService
  +     * Initializes the service.
  +     *
  +     * This method processes the repository path, to make it relative to the
  +     * web application root, if neccessary
        */
  -    public ArrayList parseRequest(HttpServletRequest req, String path)
  -        throws ServiceException
  +    public void init() throws InitializationException
       {
  -        ArrayList items = new ArrayList();
  -        String contentType = req.getHeader(CONTENT_TYPE);
  +        String repoPath = getConfiguration().getString(
  +            UploadService.REPOSITORY_KEY,
  +            UploadService.REPOSITORY_DEFAULT);
   
  -        if(!contentType.startsWith(MULTIPART_FORM_DATA))
  +        // test for the existence of the path within the webapp directory.
  +        // if it does not exist, assume the path was to be used as is.
  +        String testPath = getRealPath(repoPath);
  +        File testDir = new File(testPath);
  +        if ( testDir.exists() ) 
           {
  -            throw new ServiceException("the request doesn't contain a " +
  -                MULTIPART_FORM_DATA + " stream");
  +            repoPath = testPath;
           }
  -        int requestSize = req.getContentLength();
   
  -        if(requestSize == -1)
  -        {
  -            throw new ServiceException("the request was rejected because " +
  -                "it's size is unknown");
  -        }
  +        getConfiguration().setProperty(UploadService.REPOSITORY_KEY, repoPath);
   
  -        if(requestSize > TurbineUpload.getSizeMax())
  -        {
  -            throw new ServiceException("the request was rejected because " +
  -                "it's size exceeds allowed range");
  -        }
  +        getCategory().debug(
  +            "Upload Service: REPOSITORY_KEY => " + repoPath);
   
  -        try
  -        {
  -            byte[] boundary = contentType.substring(
  -                contentType.indexOf("boundary=")+9).getBytes();
  +        FileUpload upload = new FileUpload();
   
  -            InputStream input = (InputStream)req.getInputStream();
  +        // remove this when getAutomatic() is removed.
  +        automatic = getConfiguration().getBoolean(
  +            UploadService.AUTOMATIC_KEY,
  +            UploadService.AUTOMATIC_DEFAULT);
   
  -            MultipartStream multi = new MultipartStream(input, boundary);
  -            boolean nextPart = multi.skipPreamble();
  -            while(nextPart)
  -            {
  -                Map headers = parseHeaders(multi.readHeaders());
  -                String fieldName = getFieldName(headers);
  -                if (fieldName != null)
  -                {
  -                    String subContentType = getHeader(headers, CONTENT_TYPE);
  -                    if (subContentType != null && subContentType
  -                                                .startsWith(MULTIPART_MIXED))
  -                    {
  -                        // Multiple files.
  -                        byte[] subBoundary =
  -                            subContentType.substring(
  -                                subContentType
  -                                .indexOf("boundary=")+9).getBytes();
  -                        multi.setBoundary(subBoundary);
  -                        boolean nextSubPart = multi.skipPreamble();
  -                        while (nextSubPart)
  -                        {
  -                            headers = parseHeaders(multi.readHeaders());
  -                            if (getFileName(headers) != null)
  -                            {
  -                                FileItem item = createItem(path, headers,
  -                                                           requestSize);
  -                                OutputStream os = item.getOutputStream();
  -                                try
  -                                {
  -                                    multi.readBodyData(os);
  -                                }
  -                                finally
  -                                {
  -                                    os.close();
  -                                }
  -                                item.setFieldName(getFieldName(headers));
  -                                items.add(item);
  -                            }
  -                            else
  -                            {
  -                                // Ignore anything but files inside
  -                                // multipart/mixed.
  -                                multi.discardBodyData();
  -                            }
  -                            nextSubPart = multi.readBoundary();
  -                        }
  -                        multi.setBoundary(boundary);
  -                    }
  -                    else
  -                    {
  -                        if (getFileName(headers) != null)
  -                        {
  -                            // A single file.
  -                            FileItem item = createItem(path, headers,
  -                                                       requestSize);
  -                            OutputStream os = item.getOutputStream();
  -                            try
  -                            {
  -                                multi.readBodyData(os);
  -                            }
  -                            finally
  -                            {
  -                                os.close();
  -                            }
  -                            item.setFieldName(getFieldName(headers));
  -                            items.add(item);
  -                        }
  -                        else
  -                        {
  -                            // A form field.
  -                            FileItem item = createItem(path, headers,
  -                                                       requestSize);
  -                            OutputStream os = item.getOutputStream();
  -                            try
  -                            {
  -                                multi.readBodyData(os);
  -                            }
  -                            finally
  -                            {
  -                                os.close();
  -                            }
  -                            item.setFieldName(getFieldName(headers));
  -                            item.setIsFormField(true);
  -                            items.add(item);
  -                        }
  -                    }
  -                }
  -                else
  -                {
  -                    // Skip this part.
  -                    multi.discardBodyData();
  -                }
  -                nextPart = multi.readBoundary();
  -            }
  -        }
  -        catch(IOException e)
  -        {
  -            throw new ServiceException(
  -                "Processing of " + MULTIPART_FORM_DATA +
  -                    " request failed", e);
  -        }
  +        upload.setSizeMax( getConfiguration().getInt(
  +            UploadService.SIZE_MAX_KEY,
  +            UploadService.SIZE_MAX_DEFAULT) );
  +
  +        upload.setSizeThreshold( getConfiguration().getInt(
  +            UploadService.SIZE_THRESHOLD_KEY,
  +            UploadService.SIZE_THRESHOLD_DEFAULT) );
   
  -        return items;
  +        upload.setRepositoryPath( getConfiguration().getString(
  +            UploadService.REPOSITORY_KEY,
  +            UploadService.REPOSITORY_DEFAULT) );
  +
  +        component = upload;
  +        setInit(true);
       }
   
  +    public Object getComponent()
  +    {
  +        return component;
  +    }
  +
  +
       /**
  -     * <p> Retrieves file name from <code>Content-disposition</code> header.
  -     *
  -     * @param headers The HTTP request headers.
  -     * @return A the file name for the current <code>encapsulation</code>.
  +     * Used to determine whether the parseRequest method should be
  +     * called automatically.  
  +     * 
  +     * @deprecated This is left over from coupling with
  +     * ParameterParser.  ParameterParser (and any other use of the
  +     * service) should determine for itself whether to call the
  +     * parseRequest method and not ask the service.
        */
  -    protected String getFileName(Map headers)
  +    public boolean getAutomatic() 
       {
  -        String fileName = null;
  -        String cd = getHeader(headers, CONTENT_DISPOSITION);
  -        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;
  +        return automatic;
       }
  +    
  +    /**
  +     * The maximum allowed upload size
  +     */
  +    public int getSizeMax() 
  +    {
  +        return ((FileUpload)getComponent()).getSizeMax();
  +    }
  +    
   
       /**
  -     * <p> Retrieves field name from <code>Content-disposition</code> header.
  -     *
  -     * @param headers The HTTP request headers.
  -     * @return The field name for the current <code>encapsulation</code>.
  +     * The threshold beyond which files are written directly to disk.
        */
  -    protected String getFieldName(Map headers)
  +    public int getSizeThreshold()
       {
  -        String fieldName = null;
  -        String cd = getHeader(headers, CONTENT_DISPOSITION);
  -        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;
  +        return ((FileUpload)getComponent()).getSizeThreshold();
       }
   
       /**
  -     * <p> Creates a new instance of {@link
  -     * org.apache.fulcrum.upload.FileItem}.
  -     *
  -     * @param path The path for the FileItem.
  -     * @param headers The HTTP request headers.
  -     * @param requestSize The size of the request.
  -     * @return A newly created <code>FileItem</code>.
  +     * The location used to temporarily store files that are larger
  +     * than the size threshold.
        */
  -    protected FileItem createItem( String path,
  -                                   Map headers,
  -                                   int requestSize )
  +    public String getRepository()
       {
  -        return DefaultFileItem.newInstance(path,
  -                                     getFileName(headers),
  -                                     getHeader(headers, CONTENT_TYPE),
  -                                     requestSize);
  +        return ((FileUpload)getComponent()).getRepositoryPath();
       }
   
       /**
  -     * <p> Parses the <code>header-part</code> and returns as key/value
  -     * pairs.
  -     *
  -     * <p> If there are multiple headers of the same names, the name
  -     * will map to a comma-separated list containing the values.
  +     * <p>Parses a <a href="http://rf.cx/rfc1867.html">RFC 1867</a>
  +     * compliant <code>multipart/form-data</code> stream.</p>
        *
  -     * @param headerPart The <code>header-part</code> of the current
  -     * <code>encapsulation</code>.
  -     * @return The parsed HTTP request headers.
  +     * @param req The servlet request to be parsed.
  +     * @param path The location where the files should be stored.
  +     * @exception ServiceException Problems reading/parsing the
  +     * request or storing the uploaded file(s).
        */
  -    protected Map parseHeaders( String headerPart )
  +    public ArrayList parseRequest(HttpServletRequest req, String path)
  +            throws ServiceException
       {
  -        Map headers = new HashMap();
  -        char buffer[] = new char[MAX_HEADER_SIZE];
  -        boolean done = false;
  -        int j = 0;
  -        int i;
  -        String header, headerName, headerValue;
           try
           {
  -            while (!done)
  -            {
  -                i=0;
  -                // Copy a single line of characters into the buffer,
  -                // omitting trailing CRLF.
  -                while (i<2 || buffer[i-2] != '\r' || buffer[i-1] != '\n')
  -                {
  -                    buffer[i++] = headerPart.charAt(j++);
  -                }
  -                header = new String(buffer, 0, i-2);
  -                if (header.equals(""))
  -                {
  -                    done = true;
  -                }
  -                else
  -                {
  -                    if (header.indexOf(':') == -1)
  -                    {
  -                        // This header line is malformed, skip it.
  -                        continue;
  -                    }
  -                    headerName = header.substring(0, header.indexOf(':'))
  -                        .trim().toLowerCase();
  -                    headerValue =
  -                        header.substring(header.indexOf(':') + 1).trim();
  -                    if (getHeader(headers, headerName) != null)
  -                    {
  -                        // More that one heder of that name exists,
  -                        // append to the list.
  -                        headers.put(headerName,
  -                                    getHeader(headers, headerName) + ',' +
  -                                    headerValue);
  -                    }
  -                    else
  -                    {
  -                        headers.put(headerName, headerValue);
  -                    }
  -                }
  -            }
  +            return (ArrayList)
  +                ((FileUpload)getComponent()).parseRequest(req, path);
           }
  -        catch(IndexOutOfBoundsException e)
  +        catch (FileUploadException e)
           {
  -            // Headers were malformed. continue with all that was
  -            // parsed.
  +            throw new ServiceException(e);
           }
  -        return headers;
  -    }
  -
  -    /**
  -     * <p> Returns a header with specified name.
  -     *
  -     * @param headers The HTTP request headers.
  -     * @param name The name of the header to fetch.
  -     * @return The value of specified header, or a comma-separated
  -     * list if there were multiple headers of that name.
  -     */
  -    protected final String getHeader( Map headers, String name )
  -    {
  -        return (String)headers.get(name.toLowerCase());
       }
   }
  
  
  
  1.7       +15 -2     jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/upload/UploadService.java
  
  Index: UploadService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/upload/UploadService.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- UploadService.java	24 Nov 2001 22:59:03 -0000	1.6
  +++ UploadService.java	24 Mar 2002 21:45:11 -0000	1.7
  @@ -68,7 +68,7 @@
    *
    * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
    * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
  - * @version $Id: UploadService.java,v 1.6 2001/11/24 22:59:03 dlr Exp $
  + * @version $Id: UploadService.java,v 1.7 2002/03/24 21:45:11 jmcnally Exp $
    */
   public interface UploadService
       extends Service
  @@ -195,6 +195,19 @@
               throws ServiceException;
   
       /**
  +     * <p> Retrieves the value of <code>automatic</code> property of the
  +     * {@link org.apache.fulcrum.upload.UploadService}.
  +     * Used to determine whether the parseRequest method should be
  +     * called automatically.  
  +     * 
  +     * @deprecated This is left over from coupling with
  +     * ParameterParser.  ParameterParser (and any other use of the
  +     * service) should determine for itself whether to call the
  +     * parseRequest method and not ask the service.
  +     */
  +    public boolean getAutomatic();
  +
  +    /**
        * <p> Retrieves the value of <code>size.max</code> property of the
        * {@link org.apache.fulcrum.upload.UploadService}.
        *
  @@ -218,5 +231,5 @@
        */
       public String getRepository();
   
  -    public String getUniqueId();
  +    public Object getComponent();
   }
  
  
  
  1.4       +2 -2      jakarta-turbine-fulcrum/src/util/org/apache/fulcrum/util/parser/DefaultParameterParser.java
  
  Index: DefaultParameterParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/src/util/org/apache/fulcrum/util/parser/DefaultParameterParser.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultParameterParser.java	31 Aug 2001 08:05:57 -0000	1.3
  +++ DefaultParameterParser.java	24 Mar 2002 21:45:11 -0000	1.4
  @@ -62,8 +62,8 @@
   import javax.servlet.http.HttpServletRequest;
   import org.apache.fulcrum.ServiceException;
   import org.apache.fulcrum.pool.Recyclable;
  -import org.apache.fulcrum.upload.FileItem;
   import org.apache.fulcrum.upload.TurbineUpload;
  +import org.apache.commons.fileupload.FileItem;
   import org.apache.log4j.Category;
   
   /**
  @@ -88,7 +88,7 @@
    * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
    * @author <a href="mailto:jon@clearink.com">Jon S. Stevens</a>
    * @author <a href="mailto:sean@informage.net">Sean Legassick</a>
  - * @version $Id: DefaultParameterParser.java,v 1.3 2001/08/31 08:05:57 jvanzyl Exp $
  + * @version $Id: DefaultParameterParser.java,v 1.4 2002/03/24 21:45:11 jmcnally Exp $
    */
   public class DefaultParameterParser
       extends BaseValueParser
  
  
  
  1.2       +2 -2      jakarta-turbine-fulcrum/src/util/org/apache/fulcrum/util/parser/ParameterParser.java
  
  Index: ParameterParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/src/util/org/apache/fulcrum/util/parser/ParameterParser.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ParameterParser.java	20 Aug 2001 00:15:20 -0000	1.1
  +++ ParameterParser.java	24 Mar 2002 21:45:11 -0000	1.2
  @@ -55,7 +55,7 @@
    */
   
   import javax.servlet.http.HttpServletRequest;
  -import org.apache.fulcrum.upload.FileItem;
  +import org.apache.commons.fileupload.FileItem;
   
   /**
    * ParameterParser is an interface to a utility to handle parsing and
  @@ -79,7 +79,7 @@
    * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
    * @author <a href="mailto:jon@clearink.com">Jon S. Stevens</a>
    * @author <a href="mailto:sean@informage.net">Sean Legassick</a>
  - * @version $Id: ParameterParser.java,v 1.1 2001/08/20 00:15:20 mpoeschl Exp $
  + * @version $Id: ParameterParser.java,v 1.2 2002/03/24 21:45:11 jmcnally Exp $
    */
   public interface ParameterParser
       extends ValueParser
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>