Coverage Report - org.apache.myfaces.shared_impl.renderkit.html.HtmlSecretRendererBase
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlSecretRendererBase
0%
0/34
0%
0/14
2.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 org.apache.myfaces.shared_impl.renderkit.html;
 20  
 
 21  
 import org.apache.myfaces.shared_impl.renderkit.JSFAttr;
 22  
 import org.apache.myfaces.shared_impl.renderkit.RendererUtils;
 23  
 
 24  
 import javax.faces.component.UIComponent;
 25  
 import javax.faces.component.UIInput;
 26  
 import javax.faces.component.UIOutput;
 27  
 import javax.faces.component.html.HtmlInputSecret;
 28  
 import javax.faces.context.FacesContext;
 29  
 import javax.faces.context.ResponseWriter;
 30  
 import javax.faces.convert.ConverterException;
 31  
 import java.io.IOException;
 32  
 
 33  
 
 34  
 /**
 35  
  * see Spec.1.0 EA - JSF.7.6.4 Renderer Types for UIInput Components
 36  
  * @author Manfred Geiler (latest modification by $Author: matzew $)
 37  
  * @author Thomas Spiegl
 38  
  * @author Anton Koinov
 39  
  * @version $Revision: 557350 $ $Date: 2007-07-18 13:19:50 -0500 (Wed, 18 Jul 2007) $
 40  
  */
 41  0
 public class HtmlSecretRendererBase
 42  
         extends HtmlRenderer
 43  
 {
 44  
     private static final String AUTOCOMPLETE_VALUE_OFF = "off";
 45  
 
 46  
     public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
 47  
             throws IOException
 48  
     {
 49  0
         RendererUtils.checkParamValidity(facesContext, uiComponent, UIInput.class);
 50  
 
 51  0
         ResponseWriter writer = facesContext.getResponseWriter();
 52  0
         writer.startElement(HTML.INPUT_ELEM, uiComponent);
 53  0
         writer.writeAttribute(HTML.TYPE_ATTR, org.apache.myfaces.shared_impl.renderkit.html.HTML.INPUT_TYPE_PASSWORD, null);
 54  
 
 55  0
         String clientId = uiComponent.getClientId(facesContext);
 56  
 
 57  0
         HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext);
 58  0
         writer.writeAttribute(HTML.NAME_ATTR, clientId, null);
 59  
 
 60  
         boolean isRedisplay;
 61  0
         if (uiComponent instanceof HtmlInputSecret)
 62  
         {
 63  0
             isRedisplay = ((HtmlInputSecret)uiComponent).isRedisplay();
 64  
         }
 65  
         else
 66  
         {
 67  0
             isRedisplay = org.apache.myfaces.shared_impl.renderkit.RendererUtils.getBooleanAttribute(uiComponent, JSFAttr.REDISPLAY_ATTR, false);
 68  
         }
 69  0
         if (isRedisplay)
 70  
         {
 71  0
             String strValue = RendererUtils.getStringValue(facesContext, uiComponent);
 72  0
             writer.writeAttribute(HTML.VALUE_ATTR, strValue, JSFAttr.VALUE_ATTR);
 73  
         }
 74  
 
 75  0
         HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED);
 76  0
         if (isDisabled(facesContext, uiComponent))
 77  
         {
 78  0
             writer.writeAttribute(HTML.DISABLED_ATTR, Boolean.TRUE, null);
 79  
         }
 80  
 
 81  0
         if (isAutocompleteOff(facesContext, uiComponent))
 82  
         {
 83  0
             writer.writeAttribute(HTML.AUTOCOMPLETE_ATTR, AUTOCOMPLETE_VALUE_OFF, HTML.AUTOCOMPLETE_ATTR);
 84  
         }
 85  
 
 86  0
         writer.endElement(HTML.INPUT_ELEM);
 87  0
     }
 88  
 
 89  
 
 90  
     protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent)
 91  
     {
 92  
         //TODO: overwrite in extended HtmlSecretRenderer and check for enabledOnUserRole
 93  0
         if (uiComponent instanceof HtmlInputSecret)
 94  
         {
 95  0
             return ((HtmlInputSecret)uiComponent).isDisabled();
 96  
         }
 97  
 
 98  0
         return RendererUtils.getBooleanAttribute(uiComponent, HTML.DISABLED_ATTR, false);
 99  
     }
 100  
 
 101  
     /**
 102  
      * If autocomplete is "on" or not set, do not render it
 103  
      */
 104  
     protected boolean isAutocompleteOff(FacesContext facesContext, UIComponent component)
 105  
     {
 106  0
         if (component instanceof HtmlInputSecret)
 107  
         {
 108  0
             String autocomplete = ((HtmlInputSecret)component).getAutocomplete();
 109  0
             if (autocomplete != null)
 110  
             {
 111  0
                 return autocomplete.equals(AUTOCOMPLETE_VALUE_OFF);
 112  
             }
 113  
         }
 114  
 
 115  0
         return false;
 116  
     }
 117  
 
 118  
     public void decode(FacesContext facesContext, UIComponent component)
 119  
     {
 120  0
         org.apache.myfaces.shared_impl.renderkit.RendererUtils.checkParamValidity(facesContext, component, UIInput.class);
 121  0
         HtmlRendererUtils.decodeUIInput(facesContext, component);
 122  0
     }
 123  
 
 124  
     public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue) throws ConverterException
 125  
     {
 126  0
         RendererUtils.checkParamValidity(facesContext, uiComponent, UIOutput.class);
 127  0
         return RendererUtils.getConvertedUIOutputValue(facesContext,
 128  
                                                        (UIOutput)uiComponent,
 129  
                                                        submittedValue);
 130  
     }
 131  
 
 132  
 }