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