Clover coverage report - Code Coverage for tapestry release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:12:14 EST
file stats: LOC: 131   Methods: 8
NCLOC: 76   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractMultipartDecoder.java 85.7% 94.3% 100% 93%
coverage coverage
 1    // Copyright 2004, 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    package org.apache.tapestry.multipart;
 15   
 16    import java.io.UnsupportedEncodingException;
 17    import java.util.HashMap;
 18    import java.util.Iterator;
 19    import java.util.List;
 20    import java.util.Map;
 21   
 22    import org.apache.commons.fileupload.FileItem;
 23    import org.apache.hivemind.ApplicationRuntimeException;
 24    import org.apache.tapestry.request.IUploadFile;
 25   
 26    /**
 27    *
 28    * @author Raphael Jean
 29    */
 30    public abstract class AbstractMultipartDecoder {
 31   
 32    /**
 33    * Map of UploadPart (which implements IUploadFile), keyed on parameter
 34    * name.
 35    */
 36    protected Map _uploadParts = new HashMap();
 37   
 38    /**
 39    * Map of ValuePart, keyed on parameter name.
 40    */
 41    private Map _valueParts = new HashMap();
 42   
 43    protected int _thresholdSize = 1024;
 44   
 45    protected String _repositoryPath = System.getProperty("java.io.tmpdir");
 46   
 47    protected String _encoding;
 48   
 49  6 public IUploadFile getFileUpload(String parameterName) {
 50  6 return (IUploadFile) _uploadParts.get(parameterName);
 51    }
 52   
 53  10 public void cleanup() {
 54  10 Iterator i = _uploadParts.values().iterator();
 55   
 56  10 while (i.hasNext()) {
 57  8 UploadPart part = (UploadPart) i.next();
 58   
 59  8 part.cleanup();
 60    }
 61    }
 62   
 63  10 protected Map buildParameterMap() {
 64  10 Map result = new HashMap();
 65   
 66  10 Iterator i = _valueParts.entrySet().iterator();
 67  10 while (i.hasNext()) {
 68  44 Map.Entry e = (Map.Entry) i.next();
 69   
 70  44 String name = (String) e.getKey();
 71  44 ValuePart part = (ValuePart) e.getValue();
 72   
 73  44 result.put(name, part.getValues());
 74    }
 75   
 76  10 return result;
 77    }
 78   
 79  10 protected void processFileItems(List parts) {
 80  10 if (parts == null)
 81  0 return;
 82   
 83  10 Iterator i = parts.iterator();
 84   
 85  10 while (i.hasNext()) {
 86  54 FileItem item = (FileItem) i.next();
 87   
 88  54 processFileItem(item);
 89    }
 90    }
 91   
 92  54 private void processFileItem(FileItem item) {
 93  54 if (item.isFormField()) {
 94  46 processFormFieldItem(item);
 95  46 return;
 96    }
 97   
 98  8 processUploadFileItem(item);
 99    }
 100   
 101  8 private void processUploadFileItem(FileItem item) {
 102  8 String name = item.getFieldName();
 103   
 104  8 UploadPart part = new UploadPart(item);
 105   
 106  8 _uploadParts.put(name, part);
 107    }
 108   
 109  46 void processFormFieldItem(FileItem item) {
 110  46 String name = item.getFieldName();
 111   
 112  46 String value = extractFileItemValue(item);
 113   
 114  46 ValuePart part = (ValuePart) _valueParts.get(name);
 115   
 116  46 if (part == null)
 117  44 _valueParts.put(name, new ValuePart(value));
 118    else
 119  2 part.add(value);
 120    }
 121   
 122  46 private String extractFileItemValue(FileItem item) {
 123  46 try {
 124  46 return (_encoding == null) ? item.getString() : item
 125    .getString(_encoding);
 126    } catch (UnsupportedEncodingException ex) {
 127  0 throw new ApplicationRuntimeException(MultipartMessages
 128    .unsupportedEncoding(_encoding, ex), ex);
 129    }
 130    }
 131    }