Coverage Report - org.apache.myfaces.view.facelets.tag.ui.InsertHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
InsertHandler
0%
0/21
0%
0/12
3.667
 
 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.ui;
 20  
 
 21  
 import java.io.IOException;
 22  
 
 23  
 import javax.el.ELException;
 24  
 import javax.faces.FacesException;
 25  
 import javax.faces.component.UIComponent;
 26  
 import javax.faces.view.facelets.FaceletContext;
 27  
 import javax.faces.view.facelets.FaceletException;
 28  
 import javax.faces.view.facelets.TagAttribute;
 29  
 import javax.faces.view.facelets.TagAttributeException;
 30  
 import javax.faces.view.facelets.TagConfig;
 31  
 import javax.faces.view.facelets.TagHandler;
 32  
 
 33  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletAttribute;
 34  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
 35  
 import org.apache.myfaces.view.facelets.AbstractFaceletContext;
 36  
 import org.apache.myfaces.view.facelets.TemplateClient;
 37  
 import org.apache.myfaces.view.facelets.tag.ComponentContainerHandler;
 38  
 
 39  
 /**
 40  
  * The insert tag is used within your templates to declare spots of replicable data.
 41  
  * 
 42  
  * @author Jacob Hookom
 43  
  * @version $Id$
 44  
  */
 45  
 @JSFFaceletTag(name="ui:insert")
 46  
 public final class InsertHandler extends TagHandler implements TemplateClient, ComponentContainerHandler
 47  
 {
 48  
 
 49  
     /**
 50  
      * The optional name attribute matches the associated <ui:define/> 
 51  
      * tag in this template's client. If no name is specified, it's expected 
 52  
      * that the whole template client will be inserted.
 53  
      */
 54  
     @JSFFaceletAttribute(
 55  
             className="javax.el.ValueExpression",
 56  
             deferredValueType="java.lang.String",
 57  
             required=true)
 58  
     private final String name;
 59  
 
 60  
     /**
 61  
      * @param config
 62  
      */
 63  
     public InsertHandler(TagConfig config)
 64  
     {
 65  0
         super(config);
 66  0
         TagAttribute attr = this.getAttribute("name");
 67  0
         if (attr != null)
 68  
         {
 69  0
             if (!attr.isLiteral())
 70  
             {
 71  0
                 throw new TagAttributeException(this.tag, attr, "Must be Literal");
 72  
             }
 73  0
             this.name = attr.getValue();
 74  
         }
 75  
         else
 76  
         {
 77  0
             this.name = null;
 78  
         }
 79  0
     }
 80  
 
 81  
     /*
 82  
      * (non-Javadoc)
 83  
      * 
 84  
      * @see javax.faces.view.facelets.FaceletHandler#apply(javax.faces.view.facelets.FaceletContext, javax.faces.component.UIComponent)
 85  
      */
 86  
     public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
 87  
             ELException
 88  
     {
 89  0
         AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
 90  0
         actx.extendClient(this);
 91  0
         boolean found = false;
 92  
         try
 93  
         {
 94  0
             found = actx.includeDefinition(parent, this.name);
 95  
         }
 96  
         finally
 97  
         {
 98  0
             actx.popExtendedClient(this);
 99  0
         }
 100  0
         if (!found)
 101  
         {
 102  0
             this.nextHandler.apply(ctx, parent);
 103  
         }
 104  0
     }
 105  
 
 106  
     public boolean apply(FaceletContext ctx, UIComponent parent, String name) throws IOException, FacesException,
 107  
             FaceletException, ELException
 108  
     {
 109  0
         if (this.name == name || this.name != null && this.name.equals(name))
 110  
         {
 111  0
             this.nextHandler.apply(ctx, parent);
 112  0
             return true;
 113  
         }
 114  0
         return false;
 115  
     }
 116  
 }