Coverage Report - org.apache.myfaces.renderkit.html.HtmlFormatRenderer
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlFormatRenderer
0%
0/27
0%
0/8
0
 
 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.renderkit.html;
 20  
 
 21  
 import java.io.IOException;
 22  
 import java.text.MessageFormat;
 23  
 import java.util.ArrayList;
 24  
 import java.util.Iterator;
 25  
 import java.util.List;
 26  
 
 27  
 import javax.faces.component.UIComponent;
 28  
 import javax.faces.component.UIOutput;
 29  
 import javax.faces.component.UIParameter;
 30  
 import javax.faces.component.html.HtmlOutputFormat;
 31  
 import javax.faces.context.FacesContext;
 32  
 
 33  
 import org.apache.commons.logging.Log;
 34  
 import org.apache.commons.logging.LogFactory;
 35  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFRenderer;
 36  
 import org.apache.myfaces.shared_impl.renderkit.JSFAttr;
 37  
 import org.apache.myfaces.shared_impl.renderkit.RendererUtils;
 38  
 import org.apache.myfaces.shared_impl.renderkit.html.HtmlRenderer;
 39  
 import org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase;
 40  
 
 41  
 /**
 42  
  * 
 43  
  * @author Manfred Geiler (latest modification by $Author: lu4242 $)
 44  
  * @author Thomas Spiegl
 45  
  * @version $Revision: 693358 $ $Date: 2008-09-08 22:54:29 -0500 (Mon, 08 Sep 2008) $
 46  
  */
 47  
 @JSFRenderer(
 48  
     renderKitId="HTML_BASIC",
 49  
     family="javax.faces.Output",
 50  
     type="javax.faces.Format")
 51  0
 public class HtmlFormatRenderer
 52  
         extends HtmlRenderer
 53  
 {
 54  0
     private static final Log log = LogFactory.getLog(HtmlFormatRenderer.class);
 55  
 
 56  0
     private static final Object[] EMPTY_ARGS = new Object[0];
 57  
 
 58  
     public void encodeBegin(FacesContext facesContext, UIComponent uiComponent)
 59  
             throws IOException
 60  
     {
 61  0
     }
 62  
 
 63  
     public void encodeChildren(FacesContext facescontext, UIComponent uicomponent)
 64  
             throws IOException
 65  
     {
 66  0
     }
 67  
 
 68  
     public void encodeEnd(FacesContext facesContext, UIComponent component)
 69  
             throws IOException
 70  
     {
 71  0
         RendererUtils.checkParamValidity(facesContext, component, UIOutput.class);
 72  
 
 73  0
         String text = getOutputFormatText(facesContext, component);
 74  
         boolean isEscape;
 75  0
         if (component instanceof HtmlOutputFormat)
 76  
         {
 77  0
             isEscape = ((HtmlOutputFormat)component).isEscape();
 78  
         }
 79  
         else
 80  
         {
 81  0
             isEscape = RendererUtils.getBooleanAttribute(component, JSFAttr.ESCAPE_ATTR, true);
 82  
         }
 83  0
         HtmlTextRendererBase.renderOutputText(facesContext, component, text, isEscape);
 84  0
     }
 85  
 
 86  
     private String getOutputFormatText(FacesContext facesContext,
 87  
                                        UIComponent htmlOutputFormat)
 88  
     {
 89  0
         String pattern = RendererUtils.getStringValue(facesContext, htmlOutputFormat);
 90  
         Object[] args;
 91  0
         if (htmlOutputFormat.getChildCount() == 0)
 92  
         {
 93  0
             args = EMPTY_ARGS;
 94  
         }
 95  
         else
 96  
         {
 97  0
             List argsList = new ArrayList();
 98  0
             for (Iterator it = htmlOutputFormat.getChildren().iterator(); it.hasNext(); )
 99  
             {
 100  0
                 UIComponent child = (UIComponent)it.next();
 101  0
                 if (child instanceof UIParameter)
 102  
                 {
 103  0
                     argsList.add(((UIParameter)child).getValue());
 104  
                 }
 105  0
             }
 106  0
             args = argsList.toArray(new Object[argsList.size()]);
 107  
         }
 108  
 
 109  0
         MessageFormat format = new MessageFormat(pattern, facesContext.getViewRoot().getLocale());
 110  
         try
 111  
         {
 112  0
             return format.format(args);
 113  
         }
 114  0
         catch (Exception e)
 115  
         {
 116  0
             log.error("Error formatting message of component " + htmlOutputFormat.getClientId(facesContext));
 117  0
             return "";
 118  
         }
 119  
     }
 120  
 
 121  
 }