Coverage Report - org.apache.tapestry.portlet.multipart.PortletMultipartDecoderImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
PortletMultipartDecoderImpl
0%
0/14
0%
0/2
2.5
 
 1  
 // Copyright 2006 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  
 package org.apache.tapestry.portlet.multipart;
 15  
 
 16  
 import java.io.File;
 17  
 import java.util.List;
 18  
 import java.util.Map;
 19  
 
 20  
 import javax.portlet.ActionRequest;
 21  
 
 22  
 import org.apache.commons.fileupload.FileItemFactory;
 23  
 import org.apache.commons.fileupload.FileUploadException;
 24  
 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
 25  
 import org.apache.commons.fileupload.portlet.PortletFileUpload;
 26  
 import org.apache.hivemind.ApplicationRuntimeException;
 27  
 import org.apache.tapestry.multipart.AbstractMultipartDecoder;
 28  
 import org.apache.tapestry.multipart.MultipartMessages;
 29  
 
 30  
 /**
 31  
  * @author Raphael Jean
 32  
  */
 33  0
 public class PortletMultipartDecoderImpl extends AbstractMultipartDecoder
 34  
         implements PortletMultipartDecoder
 35  
 {
 36  
 
 37  
     public ActionRequest decode(ActionRequest request)
 38  
     {
 39  0
         _encoding = request.getCharacterEncoding();
 40  
 
 41  0
         PortletFileUpload upload = createFileUpload();
 42  
 
 43  
         try
 44  
         {
 45  0
             List fileItems = upload.parseRequest(request);
 46  
 
 47  0
             processFileItems(fileItems);
 48  
         }
 49  0
         catch (FileUploadException ex)
 50  
         {
 51  0
             throw new ApplicationRuntimeException(MultipartMessages
 52  
                     .unableToDecode(ex), ex);
 53  0
         }
 54  
 
 55  0
         Map parameterMap = buildParameterMap();
 56  
 
 57  0
         return new UploadFormPortletParametersWrapper(request, parameterMap);
 58  
     }
 59  
 
 60  
     private PortletFileUpload createFileUpload()
 61  
     {
 62  0
         FileItemFactory factory = new DiskFileItemFactory(_thresholdSize,
 63  
                 new File(_repositoryPath));
 64  0
         PortletFileUpload upload = new PortletFileUpload(factory);
 65  
 
 66  0
         if (_encoding != null) upload.setHeaderEncoding(_encoding);
 67  
 
 68  0
         return upload;
 69  
     }
 70  
 
 71  
 }