Coverage Report - org.seasar.teeda.core.render.html.HtmlMessagesRenderer
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlMessagesRenderer
100%
33/33
100%
16/16
4.333
 
 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  
 import java.util.Iterator;
 20  
 
 21  
 import javax.faces.application.FacesMessage;
 22  
 import javax.faces.component.UIComponent;
 23  
 import javax.faces.component.html.HtmlMessages;
 24  
 import javax.faces.context.FacesContext;
 25  
 import javax.faces.context.ResponseWriter;
 26  
 
 27  
 import org.seasar.teeda.core.JsfConstants;
 28  
 import org.seasar.teeda.core.util.RendererUtil;
 29  
 
 30  
 /**
 31  
  * @author manhole
 32  
  */
 33  55
 public class HtmlMessagesRenderer extends AbstractHtmlMessagesRenderer {
 34  
 
 35  
     public static final String COMPONENT_FAMILY = "javax.faces.Messages";
 36  
 
 37  
     public static final String RENDERER_TYPE = "javax.faces.Messages";
 38  
 
 39  
     public void encodeEnd(FacesContext context, UIComponent component)
 40  
             throws IOException {
 41  32
         assertNotNull(context, component);
 42  30
         if (!component.isRendered()) {
 43  1
             return;
 44  
         }
 45  29
         encodeHtmlMessagesEnd(context, (HtmlMessages) component);
 46  29
     }
 47  
 
 48  
     protected void encodeHtmlMessagesEnd(FacesContext context,
 49  
             HtmlMessages htmlMessages) throws IOException {
 50  29
         ResponseWriter writer = context.getResponseWriter();
 51  
         Iterator it;
 52  29
         if (htmlMessages.isGlobalOnly()) {
 53  1
             it = context.getMessages(null);
 54  
         } else {
 55  28
             it = context.getMessages();
 56  
         }
 57  29
         if (!it.hasNext()) {
 58  1
             return;
 59  
         }
 60  28
         final boolean tableLayout = isTableLayout(htmlMessages);
 61  
 
 62  28
         if (tableLayout) {
 63  5
             writer.startElement(JsfConstants.TABLE_ELEM, htmlMessages);
 64  
         } else {
 65  23
             writer.startElement(JsfConstants.UL_ELEM, htmlMessages);
 66  
         }
 67  28
         RendererUtil.renderIdAttributeIfNecessary(writer, htmlMessages,
 68  
                 getIdForRender(context, htmlMessages));
 69  59
         while (it.hasNext()) {
 70  31
             if (tableLayout) {
 71  7
                 writer.startElement(JsfConstants.TR_ELEM, htmlMessages);
 72  7
                 writer.startElement(JsfConstants.TD_ELEM, htmlMessages);
 73  
             } else {
 74  24
                 writer.startElement(JsfConstants.LI_ELEM, htmlMessages);
 75  
             }
 76  31
             FacesMessage facesMassage = (FacesMessage) it.next();
 77  31
             renderOneMessage(context, htmlMessages, facesMassage, null,
 78  
                     htmlMessages.getAttributes());
 79  31
             if (tableLayout) {
 80  7
                 writer.endElement(JsfConstants.TD_ELEM);
 81  7
                 writer.endElement(JsfConstants.TR_ELEM);
 82  
             } else {
 83  24
                 writer.endElement(JsfConstants.LI_ELEM);
 84  
             }
 85  
         }
 86  28
         if (tableLayout) {
 87  5
             writer.endElement(JsfConstants.TABLE_ELEM);
 88  
         } else {
 89  23
             writer.endElement(JsfConstants.UL_ELEM);
 90  
         }
 91  28
     }
 92  
 
 93  
     protected boolean isTableLayout(HtmlMessages htmlMessages) {
 94  28
         return JsfConstants.TABLE_VALUE.equals(htmlMessages.getLayout());
 95  
     }
 96  
 
 97  
 }