Coverage Report - javax.faces.component.html._HtmlInputFile
 
Classes in this File Line Coverage Branch Coverage Complexity
_HtmlInputFile
0%
0/33
0%
0/32
5.8
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package javax.faces.component.html;
 20  
 
 21  
 import javax.faces.component.UIInput;
 22  
 import javax.faces.context.FacesContext;
 23  
 
 24  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
 25  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
 26  
 
 27  
 /**
 28  
  * Renders a HTML input element.
 29  
  *
 30  
  */
 31  
 @JSFComponent
 32  
 (name = "h:inputFile",
 33  
 clazz = "javax.faces.component.html.HtmlInputFile",template=true,
 34  
 tagClass = "org.apache.myfaces.taglib.html.HtmlInputFileTag",
 35  
 defaultRendererType = "javax.faces.File",
 36  
 implementz = "javax.faces.component.behavior.ClientBehaviorHolder",
 37  
 defaultEventName = "valueChange"
 38  
 )
 39  0
 abstract class _HtmlInputFile extends UIInput
 40  
     implements _AccesskeyProperty,
 41  
     _AltProperty, _UniversalProperties, _DisabledReadonlyProperties,
 42  
     _FocusBlurProperties, _ChangeSelectProperties, _EventProperties,
 43  
     _StyleProperties, _TabindexProperty, _LabelProperty, _RoleProperty
 44  
 {
 45  
 
 46  
   static public final String COMPONENT_FAMILY =
 47  
     "javax.faces.Input";
 48  
   static public final String COMPONENT_TYPE =
 49  
     "javax.faces.HtmlInputFile";
 50  
 
 51  
   /**
 52  
    * HTML: The maximum number of characters allowed to be entered.
 53  
    * 
 54  
    * @JSFProperty
 55  
    *   defaultValue = "Integer.MIN_VALUE"
 56  
    */
 57  
   public abstract int getMaxlength();
 58  
 
 59  
   /**
 60  
    * HTML: The initial width of this control, in characters.
 61  
    * 
 62  
    * @JSFProperty
 63  
    *   defaultValue = "Integer.MIN_VALUE"
 64  
    */
 65  
   public abstract int getSize();
 66  
 
 67  
   /**
 68  
    * If the value of this attribute is "off", render "off" as the value of the attribute.
 69  
    * This indicates that the browser should disable its autocomplete feature for this component.
 70  
    * This is useful for components that perform autocompletion and do not want the browser interfering.
 71  
    * If this attribute is not set or the value is "on", render nothing.
 72  
    *
 73  
    * @return  the new autocomplete value
 74  
    */
 75  
   @JSFProperty
 76  
   public abstract String getAutocomplete();
 77  
 
 78  
     protected void validateValue(FacesContext context, Object convertedValue)
 79  
     {
 80  0
         if (!isValid())
 81  
         {
 82  0
             return;
 83  
         }
 84  
 
 85  
         // If our value is empty, check the required property
 86  0
         boolean isEmpty = isEmptyValue(convertedValue); 
 87  
 
 88  0
         if (isRequired() && isEmpty)
 89  
         {
 90  0
             if (getRequiredMessage() != null)
 91  
             {
 92  0
                 String requiredMessage = getRequiredMessage();
 93  0
                 context.addMessage(this.getClientId(context), new javax.faces.application.FacesMessage(
 94  
                         javax.faces.application.FacesMessage.SEVERITY_ERROR,
 95  
                     requiredMessage, requiredMessage));
 96  0
             }
 97  
             else
 98  
             {
 99  0
                 _MessageUtils.addErrorMessage(context, this, REQUIRED_MESSAGE_ID,
 100  
                     new Object[] { _MessageUtils.getLabel(context, this) });
 101  
             }
 102  0
             setValid(false);
 103  0
             return;
 104  
         }
 105  
 
 106  0
         if (!isEmpty)
 107  
         {
 108  0
             super.validateValue(context, convertedValue);
 109  
         }
 110  0
     }
 111  
     
 112  
     private static boolean isEmptyValue(Object value)
 113  
     {
 114  0
         if (value == null)
 115  
         {
 116  0
             return true;
 117  
         }
 118  0
         else if (value instanceof String)
 119  
         {
 120  0
             if ( ((String)value).trim().length() <= 0 )
 121  
             {
 122  0
                 return true;
 123  
             }
 124  
         }
 125  0
         else if (value instanceof java.util.Collection)
 126  
         {
 127  0
             if ( ((java.util.Collection)value).isEmpty())
 128  
             {
 129  0
                 return true;
 130  
             }
 131  
         }
 132  0
         else if (value.getClass().isArray())
 133  
         {
 134  0
             if (java.lang.reflect.Array.getLength(value) <= 0)
 135  
             {
 136  0
                 return true;
 137  
             }
 138  
         }
 139  0
         else if (value instanceof java.util.Map)
 140  
         {
 141  0
             if ( ((java.util.Map)value).isEmpty())
 142  
             {
 143  0
                 return true;
 144  
             }
 145  
         }
 146  0
         else if (value instanceof javax.servlet.http.Part) 
 147  
         {
 148  0
             if (((javax.servlet.http.Part)value).getSize() <= 0) 
 149  
             {
 150  0
                 return true;
 151  
             }
 152  
         }
 153  0
         return false;
 154  
     }
 155  
 
 156  
 }