Clover coverage report - Code Coverage for tapestry release 4.0-beta-2
Coverage timestamp: Sat Jul 9 2005 22:02:17 EDT
file stats: LOC: 97   Methods: 5
NCLOC: 48   Classes: 1
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
Upload.java 100% 100% 100% 100%
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   
 15    package org.apache.tapestry.form;
 16   
 17    import org.apache.tapestry.IForm;
 18    import org.apache.tapestry.IMarkupWriter;
 19    import org.apache.tapestry.IRequestCycle;
 20    import org.apache.tapestry.multipart.MultipartDecoder;
 21    import org.apache.tapestry.request.IUploadFile;
 22    import org.apache.tapestry.valid.ValidationStrings;
 23    import org.apache.tapestry.valid.ValidatorException;
 24   
 25    /**
 26    * Form element used to upload files. [ <a
 27    * href="../../../../../ComponentReference/Upload.html">Component Reference </a>] As of 4.0, the
 28    * Upload field can indicate that it is required.
 29    *
 30    * @author Howard Lewis Ship
 31    * @author Paul Ferraro
 32    * @since 1.0.8
 33    */
 34   
 35    public abstract class Upload extends AbstractRequirableField
 36    {
 37    /**
 38    * @see org.apache.tapestry.form.validator.AbstractRequirableField#bind(org.apache.tapestry.IRequestCycle)
 39    */
 40  3 public void bind(IMarkupWriter writer, IRequestCycle cycle) throws ValidatorException
 41    {
 42  3 setFile(getUploadFile());
 43    }
 44   
 45    /**
 46    * @see org.apache.tapestry.AbstractComponent#finishLoad()
 47    */
 48  1 protected void finishLoad()
 49    {
 50  1 setRequiredMessage(ValidationStrings.getMessagePattern(
 51    ValidationStrings.REQUIRED_FILE_FIELD,
 52    getPage().getLocale()));
 53    }
 54   
 55  6 private IUploadFile getUploadFile()
 56    {
 57  6 return getDecoder().getFileUpload(getName());
 58    }
 59   
 60  3 public String getSubmittedValue(IRequestCycle cycle)
 61    {
 62  3 return getUploadFile().getFilePath();
 63    }
 64   
 65  2 protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 66    {
 67  2 super.renderFormComponent(writer, cycle);
 68   
 69    // Force the form to use the correct encoding type for file uploads.
 70  2 IForm form = getForm();
 71   
 72  2 form.setEncodingType("multipart/form-data");
 73   
 74  2 renderDelegatePrefix(writer, cycle);
 75   
 76  2 writer.beginEmpty("input");
 77  2 writer.attribute("type", "file");
 78  2 writer.attribute("name", getName());
 79   
 80  2 if (isDisabled())
 81    {
 82  1 writer.attribute("disabled", "disabled");
 83    }
 84   
 85  2 form.getDelegate().writeAttributes(writer, cycle, this, null);
 86   
 87  2 renderIdAttribute(writer, cycle);
 88   
 89  2 renderDelegateAttributes(writer, cycle);
 90   
 91  2 renderDelegateSuffix(writer, cycle);
 92    }
 93   
 94    public abstract void setFile(IUploadFile file);
 95   
 96    public abstract MultipartDecoder getDecoder();
 97    }