You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2003/10/29 20:44:21 UTC

cvs commit: cocoon-2.1/src/java/org/apache/cocoon/servlet/multipart MultipartParser.java

vgritsenko    2003/10/29 11:44:21

  Modified:    src/java/org/apache/cocoon/servlet/multipart
                        MultipartParser.java
  Log:
  Add a method allowing to use parser out of servlet environment
  
  Revision  Changes    Path
  1.3       +25 -22    cocoon-2.1/src/java/org/apache/cocoon/servlet/multipart/MultipartParser.java
  
  Index: MultipartParser.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/servlet/multipart/MultipartParser.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MultipartParser.java	7 May 2003 05:09:39 -0000	1.2
  +++ MultipartParser.java	29 Oct 2003 19:44:21 -0000	1.3
  @@ -111,13 +111,12 @@
        * @param maxUploadSize The maximum content length accepted.
        * @param characterEncoding The character encoding to be used.
        */
  -    public MultipartParser(
  -            boolean saveUploadedFilesToDisk, 
  -            File uploadDirectory, 
  -            boolean allowOverwrite, 
  -            boolean silentlyRename, 
  -            int maxUploadSize,
  -            String characterEncoding)
  +    public MultipartParser(boolean saveUploadedFilesToDisk,
  +                           File uploadDirectory,
  +                           boolean allowOverwrite,
  +                           boolean silentlyRename,
  +                           int maxUploadSize,
  +                           String characterEncoding)
       {
           this.saveUploadedFilesToDisk = saveUploadedFilesToDisk;
           this.uploadDirectory = uploadDirectory;
  @@ -127,21 +126,25 @@
           this.characterEncoding = characterEncoding;
       }
   
  -    public Hashtable getParts(HttpServletRequest request) throws IOException, MultipartException {
  -        if (request.getContentLength() > this.maxUploadSize) {
  -             throw new IOException("Content length exceeds maximum upload size");
  -         }
  +    public Hashtable getParts(int contentLength, String contentType, InputStream requestStream)
  +    throws IOException, MultipartException {
  +        if (contentLength > this.maxUploadSize) {
  +            throw new IOException("Content length exceeds maximum upload size");
  +        }
  +
  +        this.parts = new Hashtable();
   
  -         this.parts = new Hashtable();
  +        BufferedInputStream bufferedStream = new BufferedInputStream(requestStream);
  +        PushbackInputStream pushbackStream = new PushbackInputStream(bufferedStream, MAX_BOUNDARY_SIZE);
  +        TokenStream stream = new TokenStream(pushbackStream);
   
  -         InputStream requestStream = request.getInputStream();
  -         BufferedInputStream bufferedStream = new BufferedInputStream(requestStream);
  -         PushbackInputStream pushbackStream = new PushbackInputStream(bufferedStream, MAX_BOUNDARY_SIZE);
  -         TokenStream stream = new TokenStream(pushbackStream);
  -                        
  -         parseMultiPart(stream,getBoundary(request.getContentType()));
  +        parseMultiPart(stream, getBoundary(contentType));
   
  -         return this.parts;    
  +        return this.parts;    
  +    }
  +    
  +    public Hashtable getParts(HttpServletRequest request) throws IOException, MultipartException {
  +        return getParts(request.getContentLength(), request.getContentType(), request.getInputStream());    
       }
       
       /**