Coverage Report - org.apache.myfaces.view.facelets.tag.jsf.core.ViewMetadataHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
ViewMetadataHandler
0%
0/22
0%
0/8
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  
 
 23  
 import javax.faces.component.UIComponent;
 24  
 import javax.faces.component.UIPanel;
 25  
 import javax.faces.component.UIViewRoot;
 26  
 import javax.faces.view.facelets.FaceletContext;
 27  
 import javax.faces.view.facelets.TagConfig;
 28  
 import javax.faces.view.facelets.TagException;
 29  
 import javax.faces.view.facelets.TagHandler;
 30  
 
 31  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
 32  
 import org.apache.myfaces.view.facelets.FaceletCompositionContext;
 33  
 import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
 34  
 
 35  
 /**
 36  
  * Defines the view metadata. It is expected that this tag contains only
 37  
  * one or many f:viewParam tags.
 38  
  * 
 39  
  * @author Leonardo Uribe (latest modification by $Author$)
 40  
  * @version $Revision$ $Date$
 41  
  */
 42  
 @JSFFaceletTag(name="f:metadata")
 43  
 public final class ViewMetadataHandler extends TagHandler
 44  
 {
 45  
 
 46  
     public ViewMetadataHandler(TagConfig config)
 47  
     {
 48  0
         super(config);
 49  0
     }
 50  
 
 51  
     public void apply(FaceletContext ctx, UIComponent parent)
 52  
             throws IOException
 53  
     {
 54  0
         if (parent == null)
 55  
         {
 56  0
             throw new TagException(this.tag, "Parent UIComponent was null");
 57  
         }
 58  0
         if (! (parent instanceof UIViewRoot) )
 59  
         {
 60  0
             throw new TagException(this.tag, "Parent UIComponent "+parent.getId()+" should be instance of UIViewRoot");
 61  
         }
 62  0
         FaceletCompositionContext mctx = FaceletCompositionContext.getCurrentInstance(ctx);
 63  0
         if (mctx.isBuildingViewMetadata())
 64  
         {
 65  0
             UIComponent metadataFacet = parent.getFacet(UIViewRoot.METADATA_FACET_NAME);
 66  0
             if (metadataFacet == null)
 67  
             {
 68  0
                 metadataFacet = ctx.getFacesContext().getApplication().createComponent(
 69  
                         ctx.getFacesContext(), UIPanel.COMPONENT_TYPE, null);
 70  0
                 metadataFacet.setId(UIViewRoot.METADATA_FACET_NAME);
 71  0
                 metadataFacet.getAttributes().put(ComponentSupport.FACET_CREATED_UIPANEL_MARKER, true);
 72  0
                 metadataFacet.getAttributes().put(ComponentSupport.COMPONENT_ADDED_BY_HANDLER_MARKER, Boolean.TRUE);
 73  0
                 parent.getFacets().put(UIViewRoot.METADATA_FACET_NAME, metadataFacet);
 74  
             }
 75  
         }
 76  
 
 77  
         // We have to do nextHandler.apply() in any case, because even if we're not building ViewMetadata
 78  
         // we still need to do it so that the mark/delete components can be applied correctly.
 79  
         // (The only tag that needs to do something special is f:event, because in this case
 80  
         // ComponentHandler.isNew(parent) does not work for UIViewRoot.)
 81  0
         parent.getAttributes().put(FacetHandler.KEY, UIViewRoot.METADATA_FACET_NAME);
 82  0
         mctx.startMetadataSection();
 83  
         try
 84  
         {
 85  0
             this.nextHandler.apply(ctx, parent);
 86  
         }
 87  
         finally
 88  
         {
 89  0
             mctx.endMetadataSection();
 90  0
             parent.getAttributes().remove(FacetHandler.KEY);
 91  0
         }
 92  0
     }
 93  
 }