Coverage Report - org.apache.myfaces.view.facelets.tag.jsf.core.AttributesHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
AttributesHandler
0%
0/15
0%
0/10
4
 
 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.view.facelets.tag.jsf.core;
 20  
 
 21  
 import java.io.IOException;
 22  
 import java.util.Map;
 23  
 import javax.el.ValueExpression;
 24  
 import javax.faces.component.UIComponent;
 25  
 import javax.faces.view.facelets.FaceletContext;
 26  
 import javax.faces.view.facelets.TagAttribute;
 27  
 import javax.faces.view.facelets.TagConfig;
 28  
 import javax.faces.view.facelets.TagException;
 29  
 import javax.faces.view.facelets.TagHandler;
 30  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
 31  
 
 32  
 /**
 33  
  *
 34  
  * @since 2.2
 35  
  * @author Leonardo Uribe
 36  
  */
 37  
 @JSFFaceletTag(
 38  
         name = "f:attributes",
 39  
         bodyContent = "empty")
 40  
 public final class AttributesHandler extends TagHandler 
 41  
 {
 42  
     private final TagAttribute _value;
 43  
     
 44  
     public AttributesHandler(TagConfig config)
 45  
     {
 46  0
         super(config);
 47  0
         _value = getRequiredAttribute("value");
 48  0
     }
 49  
 
 50  
     public void apply(FaceletContext ctx, UIComponent parent) throws IOException
 51  
     {
 52  0
         if (parent == null)
 53  
         {
 54  0
             throw new TagException(this.tag, "Parent UIComponent was null");
 55  
         }
 56  
 
 57  
         // only process if the parent is new to the tree
 58  0
         if (parent.getParent() == null)
 59  
         {
 60  0
             Map<String, Object> map = (Map<String, Object>) _value.getObject(ctx, Map.class);
 61  0
             Map<String, Object> attributesMap = parent.getAttributes();
 62  
             
 63  0
             for (Map.Entry<String, Object> entry : map.entrySet())
 64  
             {
 65  0
                 if (!attributesMap.containsKey(entry.getKey()))
 66  
                 {
 67  0
                     if (entry.getValue() instanceof ValueExpression)
 68  
                     {
 69  0
                         parent.setValueExpression(entry.getKey(), (ValueExpression) entry.getValue());
 70  
                     }
 71  
                     else
 72  
                     {
 73  0
                         attributesMap.put(entry.getKey(), entry.getValue());
 74  
                     }
 75  
                 }
 76  0
             }
 77  
         }
 78  0
     }
 79  
 }