Coverage Report - org.seasar.teeda.core.render.html.HtmlInputTextRenderer
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlInputTextRenderer
92%
34/37
100%
2/2
1.286
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.teeda.core.render.html;
 17  
 
 18  
 import java.io.IOException;
 19  
 
 20  
 import javax.faces.component.UIComponent;
 21  
 import javax.faces.component.html.HtmlInputText;
 22  
 import javax.faces.context.FacesContext;
 23  
 import javax.faces.context.ResponseWriter;
 24  
 import javax.faces.internal.IgnoreAttribute;
 25  
 
 26  
 import org.seasar.teeda.core.JsfConstants;
 27  
 import org.seasar.teeda.core.render.AbstractInputRenderer;
 28  
 import org.seasar.teeda.core.util.HTMLEncodeUtil;
 29  
 import org.seasar.teeda.core.util.RendererUtil;
 30  
 import org.seasar.teeda.core.util.ValueHolderUtil;
 31  
 
 32  
 /**
 33  
  * @author manhole
 34  
  */
 35  39
 public class HtmlInputTextRenderer extends AbstractInputRenderer {
 36  
 
 37  
     public static final String COMPONENT_FAMILY = "javax.faces.Input";
 38  
 
 39  
     public static final String RENDERER_TYPE = "javax.faces.Text";
 40  
 
 41  39
     private final IgnoreAttribute ignoreComponent = new IgnoreAttribute();
 42  
     {
 43  39
         ignoreComponent.addAttributeName(JsfConstants.ID_ATTR);
 44  39
         ignoreComponent.addAttributeName(JsfConstants.NAME_ATTR);
 45  39
         ignoreComponent.addAttributeName(JsfConstants.TYPE_ATTR);
 46  39
         ignoreComponent.addAttributeName(JsfConstants.VALUE_ATTR);
 47  39
         ignoreComponent.addAttributeName(JsfConstants.STYLE_CLASS_ATTR);
 48  39
         ignoreComponent.addAttributeName(JsfConstants.AUTOCOMPLETE_ATTR);
 49  39
     }
 50  
 
 51  
     public void encodeEnd(FacesContext context, UIComponent component)
 52  
             throws IOException {
 53  12
         assertNotNull(context, component);
 54  10
         if (!component.isRendered()) {
 55  1
             return;
 56  
         }
 57  9
         encodeHtmlInputTextEnd(context, (HtmlInputText) component);
 58  9
     }
 59  
 
 60  
     protected void encodeHtmlInputTextEnd(FacesContext context,
 61  
             HtmlInputText htmlInputText) throws IOException {
 62  9
         ResponseWriter writer = context.getResponseWriter();
 63  9
         writer.startElement(JsfConstants.INPUT_ELEM, htmlInputText);
 64  9
         RendererUtil.renderAttribute(writer, JsfConstants.TYPE_ATTR,
 65  
                 JsfConstants.TEXT_VALUE);
 66  9
         RendererUtil.renderIdAttributeIfNecessary(writer, htmlInputText,
 67  
                 getIdForRender(context, htmlInputText));
 68  9
         RendererUtil.renderAttribute(writer, JsfConstants.NAME_ATTR,
 69  
                 htmlInputText.getClientId(context));
 70  9
         String value = ValueHolderUtil
 71  
                 .getValueForRender(context, htmlInputText);
 72  9
         RendererUtil.renderAttribute(writer, JsfConstants.VALUE_ATTR,
 73  
                 HTMLEncodeUtil.encode(value, true, true));
 74  9
         RendererUtil.renderAttribute(writer, JsfConstants.AUTOCOMPLETE_ATTR,
 75  
                 htmlInputText.getAutocomplete());
 76  9
         renderStyleClass(context, htmlInputText, writer);
 77  9
         renderRemainAttributes(htmlInputText, writer, ignoreComponent);
 78  9
         writer.endElement(JsfConstants.INPUT_ELEM);
 79  9
     }
 80  
 
 81  
     protected void renderStyleClass(FacesContext context,
 82  
             HtmlInputText htmlInputText, ResponseWriter writer)
 83  
             throws IOException {
 84  9
         final String styleClass = htmlInputText.getStyleClass();
 85  9
         RendererUtil.renderAttribute(writer, JsfConstants.STYLE_CLASS_ATTR,
 86  
                 styleClass);
 87  9
     }
 88  
 
 89  
     public void decode(FacesContext context, UIComponent component) {
 90  5
         assertNotNull(context, component);
 91  3
         decodeHtmlInputText(context, (HtmlInputText) component);
 92  3
     }
 93  
 
 94  
     protected void decodeHtmlInputText(FacesContext context,
 95  
             HtmlInputText htmlInputText) {
 96  3
         getDecoder().decode(context, htmlInputText);
 97  3
     }
 98  
 
 99  
     public void addIgnoreAttributeName(final String name) {
 100  0
         ignoreComponent.addAttributeName(name);
 101  0
     }
 102  
 
 103  
     public IgnoreAttribute getIgnoreAttributes() {
 104  0
         return ignoreComponent;
 105  
     }
 106  
 
 107  
 }