Coverage Report - org.apache.tapestry.form.Upload
 
Classes in this File Line Coverage Branch Coverage Complexity
Upload
0%
0/26
0%
0/6
1.667
 
 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.hivemind.HiveMind;
 18  
 import org.apache.tapestry.IForm;
 19  
 import org.apache.tapestry.IMarkupWriter;
 20  
 import org.apache.tapestry.IRequestCycle;
 21  
 import org.apache.tapestry.multipart.MultipartDecoder;
 22  
 import org.apache.tapestry.request.IUploadFile;
 23  
 import org.apache.tapestry.valid.ValidatorException;
 24  
 
 25  
 /**
 26  
  * Form element used to upload files. [ <a
 27  
  * href="../../../../../components/form/upload.html">Component Reference
 28  
  * </a>]
 29  
  * <p>
 30  
  * As of 4.0, this component can be validated.
 31  
  * 
 32  
  * @author Howard Lewis Ship
 33  
  * @author Paul Ferraro
 34  
  * @since 1.0.8
 35  
  */
 36  
 
 37  0
 public abstract class Upload extends AbstractFormComponent implements ValidatableField
 38  
 {
 39  
     public abstract void setFile(IUploadFile file);
 40  
 
 41  
     /**
 42  
      * @see org.apache.tapestry.form.AbstractFormComponent#renderFormComponent(org.apache.tapestry.IMarkupWriter,
 43  
      *      org.apache.tapestry.IRequestCycle)
 44  
      */
 45  
     protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 46  
     {
 47  
         // Force the form to use the correct encoding type for file uploads.
 48  0
         IForm form = getForm();
 49  
         
 50  0
         form.setEncodingType("multipart/form-data");
 51  
 
 52  0
         renderDelegatePrefix(writer, cycle);
 53  
 
 54  0
         writer.beginEmpty("input");
 55  0
         writer.attribute("type", "file");
 56  0
         writer.attribute("name", getName());
 57  
 
 58  0
         if (isDisabled())
 59  
         {
 60  0
             writer.attribute("disabled", "disabled");
 61  
         }
 62  
 
 63  0
         renderIdAttribute(writer, cycle);
 64  
 
 65  0
         renderDelegateAttributes(writer, cycle);
 66  
 
 67  0
         getValidatableFieldSupport().renderContributions(this, writer, cycle);
 68  
 
 69  0
         renderInformalParameters(writer, cycle);
 70  
 
 71  0
         writer.closeTag();
 72  
 
 73  0
         renderDelegateSuffix(writer, cycle);
 74  0
     }
 75  
 
 76  
     /**
 77  
      * @see org.apache.tapestry.form.AbstractFormComponent#rewindFormComponent(org.apache.tapestry.IMarkupWriter,
 78  
      *      org.apache.tapestry.IRequestCycle)
 79  
      */
 80  
     protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 81  
     {
 82  0
         IUploadFile file = getDecoder().getFileUpload(getName());
 83  
         
 84  0
         if (file != null && HiveMind.isBlank(file.getFileName()))
 85  
         {
 86  0
             file = null;
 87  
         }
 88  
         
 89  
         try
 90  
         {
 91  0
             getValidatableFieldSupport().validate(this, writer, cycle, file);
 92  
             
 93  0
             setFile(file);
 94  
         }
 95  0
         catch (ValidatorException e)
 96  
         {
 97  0
             getForm().getDelegate().record(e);
 98  0
         }
 99  0
     }
 100  
     
 101  
     /**
 102  
      * Injected.
 103  
      */
 104  
     public abstract ValidatableFieldSupport getValidatableFieldSupport();
 105  
 
 106  
     /**
 107  
      * Injected.
 108  
      */
 109  
     public abstract MultipartDecoder getDecoder();
 110  
 
 111  
     /**
 112  
      * @see org.apache.tapestry.form.AbstractFormComponent#isRequired()
 113  
      */
 114  
     public boolean isRequired()
 115  
     {
 116  0
         return getValidatableFieldSupport().isRequired(this);
 117  
     }
 118  
 }