Clover coverage report - Code Coverage for tapestry release 4.0.3
Coverage timestamp: Fri May 5 2006 21:17:42 CDT
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  9 public IUploadFile getFileUpload(String parameterName) {
 50  9 return (IUploadFile) _uploadParts.get(parameterName);
 51    }
 52   
 53  15 public void cleanup() {
 54  15 Iterator i = _uploadParts.values().iterator();
 55   
 56  15 while (i.hasNext()) {
 57  12 UploadPart part = (UploadPart) i.next();
 58   
 59  12 part.cleanup();
 60    }
 61    }
 62   
 63  15 protected Map buildParameterMap() {
 64  15 Map result = new HashMap();
 65   
 66  15 Iterator i = _valueParts.entrySet().iterator();
 67  15 while (i.hasNext()) {
 68  66 Map.Entry e = (Map.Entry) i.next();
 69   
 70  66 String name = (String) e.getKey();
 71  66 ValuePart part = (ValuePart) e.getValue();
 72   
 73  66 result.put(name, part.getValues());
 74    }
 75   
 76  15 return result;
 77    }
 78   
 79  15 protected void processFileItems(List parts) {
 80  15 if (parts == null)
 81  0 return;
 82   
 83  15 Iterator i = parts.iterator();
 84   
 85  15 while (i.hasNext()) {
 86  81 FileItem item = (FileItem) i.next();
 87   
 88  81 processFileItem(item);
 89    }
 90    }
 91   
 92  81 private void processFileItem(FileItem item) {
 93  81 if (item.isFormField()) {
 94  69 processFormFieldItem(item);
 95  69 return;
 96    }
 97   
 98  12 processUploadFileItem(item);
 99    }
 100   
 101  12 private void processUploadFileItem(FileItem item) {
 102  12 String name = item.getFieldName();
 103   
 104  12 UploadPart part = new UploadPart(item);
 105   
 106  12 _uploadParts.put(name, part);
 107    }
 108   
 109  69 void processFormFieldItem(FileItem item) {
 110  69 String name = item.getFieldName();
 111   
 112  69 String value = extractFileItemValue(item);
 113   
 114  69 ValuePart part = (ValuePart) _valueParts.get(name);
 115   
 116  69 if (part == null)
 117  66 _valueParts.put(name, new ValuePart(value));
 118    else
 119  3 part.add(value);
 120    }
 121   
 122  69 private String extractFileItemValue(FileItem item) {
 123  69 try {
 124  69 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    }