Coverage Report - org.apache.tapestry.multipart.MultipartDecoderImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
MultipartDecoderImpl
0%
0/19
0%
0/2
2
 
 1  
 // Copyright 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry.multipart;
 16  
 
 17  
 import org.apache.commons.fileupload.FileItemFactory;
 18  
 import org.apache.commons.fileupload.FileUploadException;
 19  
 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
 20  
 import org.apache.commons.fileupload.servlet.ServletFileUpload;
 21  
 import org.apache.hivemind.ApplicationRuntimeException;
 22  
 
 23  
 import javax.servlet.http.HttpServletRequest;
 24  
 import java.io.File;
 25  
 import java.util.List;
 26  
 import java.util.Map;
 27  
 
 28  
 /**
 29  
  * Implementation of {@link org.apache.tapestry.multipart.MultipartDecoder} that
 30  
  * is based on <a href="http://jakarta.apache.org/commons/fileupload/">Jakarta
 31  
  * FileUpload </a>.
 32  
  * 
 33  
  * @author Howard M. Lewis Ship
 34  
  * @author Joe Panico
 35  
  * @since 4.0
 36  
  */
 37  0
 public class MultipartDecoderImpl extends AbstractMultipartDecoder implements ServletMultipartDecoder
 38  
 {
 39  
 
 40  
     /* maximum size of file allowed to be uploaded */
 41  0
     protected long _maxSize = 10000000;
 42  
 
 43  
     public HttpServletRequest decode(HttpServletRequest request)
 44  
     {
 45  0
         _encoding = request.getCharacterEncoding();
 46  
         
 47  0
         ServletFileUpload upload = createFileUpload();
 48  
         
 49  
         try
 50  
         {
 51  0
             List fileItems = upload.parseRequest(request);
 52  
             
 53  0
             processFileItems(fileItems);
 54  
         }
 55  0
         catch (FileUploadException ex)
 56  
         {
 57  0
             throw new ApplicationRuntimeException(MultipartMessages.unableToDecode(ex), ex);
 58  0
         }
 59  
         
 60  0
         Map parameterMap = buildParameterMap();
 61  
         
 62  0
         return new UploadFormParametersWrapper(request, parameterMap);
 63  
     }
 64  
 
 65  
     private ServletFileUpload createFileUpload()
 66  
     {
 67  0
         FileItemFactory factory = new DiskFileItemFactory(_thresholdSize, new File(_repositoryPath));
 68  0
         ServletFileUpload upload = new ServletFileUpload(factory);
 69  
         
 70  
         // set maximum file upload size
 71  
 
 72  0
         upload.setSizeMax(_maxSize);
 73  
         
 74  0
         if (_encoding != null)
 75  0
             upload.setHeaderEncoding(_encoding);
 76  
 
 77  0
         return upload;
 78  
     }
 79  
 
 80  
     /**
 81  
      * Sets the maximum size that an uploaded file will be allowed to have.
 82  
      * 
 83  
      * @param maxSize
 84  
      *            The maximum size, in bytes.
 85  
      */
 86  
     public void setMaxSize(long maxSize)
 87  
     {
 88  0
         _maxSize = maxSize;
 89  0
     }
 90  
 }