Clover coverage report - Code Coverage for tapestry release 4.0.2
Coverage timestamp: Thu Apr 13 2006 10:52:06 EDT
file stats: LOC: 85   Methods: 3
NCLOC: 41   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MultipartDecoderImpl.java 50% 86.7% 66.7% 80%
coverage coverage
 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 java.io.File;
 18    import java.util.List;
 19    import java.util.Map;
 20   
 21    import javax.servlet.http.HttpServletRequest;
 22   
 23    import org.apache.commons.fileupload.FileItemFactory;
 24    import org.apache.commons.fileupload.FileUploadException;
 25    import org.apache.commons.fileupload.disk.DiskFileItemFactory;
 26    import org.apache.commons.fileupload.servlet.ServletFileUpload;
 27    import org.apache.hivemind.ApplicationRuntimeException;
 28   
 29    /**
 30    * Implementation of {@link org.apache.tapestry.multipart.MultipartDecoder}that is based on <a
 31    * href="http://jakarta.apache.org/commons/fileupload/">Jakarta FileUpload </a>.
 32    *
 33    * @author Howard M. Lewis Ship
 34    * @author Joe Panico
 35    * @since 4.0
 36    */
 37    public class MultipartDecoderImpl extends AbstractMultipartDecoder implements ServletMultipartDecoder
 38    {
 39    /* maximum size of file allowed to be uploaded */
 40    protected long _maxSize = 10000000;
 41   
 42  5 public HttpServletRequest decode(HttpServletRequest request)
 43    {
 44  5 _encoding = request.getCharacterEncoding();
 45   
 46  5 ServletFileUpload upload = createFileUpload();
 47   
 48  5 try
 49    {
 50  5 List fileItems = upload.parseRequest(request);
 51   
 52  5 processFileItems(fileItems);
 53    }
 54    catch (FileUploadException ex)
 55    {
 56  0 throw new ApplicationRuntimeException(MultipartMessages.unableToDecode(ex), ex);
 57    }
 58   
 59  5 Map parameterMap = buildParameterMap();
 60   
 61  5 return new UploadFormParametersWrapper(request, parameterMap);
 62    }
 63   
 64  5 private ServletFileUpload createFileUpload() {
 65  5 FileItemFactory factory = new DiskFileItemFactory(_thresholdSize, new File(_repositoryPath));
 66  5 ServletFileUpload upload = new ServletFileUpload(factory);
 67   
 68    // set maximum file upload size
 69  5 upload.setSizeMax(_maxSize);
 70   
 71  5 if (_encoding != null)
 72  5 upload.setHeaderEncoding(_encoding);
 73   
 74  5 return upload;
 75    }
 76   
 77    /**
 78    * Sets the maximum size that an uploaded file will be allowed to have.
 79    * @param maxSize The maximum size, in bytes.
 80    */
 81  0 public void setMaxSize(long maxSize)
 82    {
 83  0 _maxSize = maxSize;
 84    }
 85    }