Coverage Report - org.apache.myfaces.view.facelets.tag.ui.LegacyCompositionHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
LegacyCompositionHandler
0%
0/49
0%
0/22
5.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  
 
 20  
 package org.apache.myfaces.view.facelets.tag.ui;
 21  
 
 22  
 import java.io.IOException;
 23  
 import java.util.Collection;
 24  
 import java.util.HashMap;
 25  
 import java.util.Map;
 26  
 import java.util.logging.Level;
 27  
 import java.util.logging.Logger;
 28  
 import javax.el.ELException;
 29  
 import javax.el.VariableMapper;
 30  
 import javax.faces.FacesException;
 31  
 import javax.faces.component.UIComponent;
 32  
 import javax.faces.view.facelets.FaceletContext;
 33  
 import javax.faces.view.facelets.FaceletException;
 34  
 import javax.faces.view.facelets.TagAttribute;
 35  
 import javax.faces.view.facelets.TagConfig;
 36  
 import javax.faces.view.facelets.TagHandler;
 37  
 import org.apache.myfaces.view.facelets.AbstractFaceletContext;
 38  
 import org.apache.myfaces.view.facelets.TemplateClient;
 39  
 import org.apache.myfaces.view.facelets.el.VariableMapperWrapper;
 40  
 import org.apache.myfaces.view.facelets.tag.TagHandlerUtils;
 41  
 
 42  
 /**
 43  
  * NOTE: This implementation is provided for compatibility reasons and
 44  
  * it is considered faulty. It is enabled using
 45  
  * org.apache.myfaces.STRICT_JSF_2_FACELETS_COMPATIBILITY web config param.
 46  
  * Don't use it if EL expression caching is enabled.
 47  
  * 
 48  
  * @author Jacob Hookom
 49  
  * @version $Id: CompositionHandler.java,v 1.14 2008/07/13 19:01:42 rlubke Exp $
 50  
  */
 51  
 //@JSFFaceletTag(name="ui:composition")
 52  
 public final class LegacyCompositionHandler extends TagHandler implements TemplateClient
 53  
 {
 54  
 
 55  
     //private static final Logger log = Logger.getLogger("facelets.tag.ui.composition");
 56  0
     private static final Logger log = Logger.getLogger(CompositionHandler.class.getName());
 57  
 
 58  
     public final static String NAME = "composition";
 59  
 
 60  
     /**
 61  
      * The resolvable URI of the template to use. The content within the composition tag will 
 62  
      * be used in populating the template specified.
 63  
      */
 64  
     //@JSFFaceletAttribute(
 65  
     //        name="template",
 66  
     //        className="javax.el.ValueExpression",
 67  
     //        deferredValueType="java.lang.String")
 68  
     protected final TagAttribute _template;
 69  
 
 70  
     protected final Map<String, DefineHandler> _handlers;
 71  
 
 72  
     protected final LegacyParamHandler[] _params;
 73  
 
 74  
     /**
 75  
      * @param config
 76  
      */
 77  
     public LegacyCompositionHandler(TagConfig config)
 78  
     {
 79  0
         super(config);
 80  0
         _template = getAttribute("template");
 81  0
         if (_template != null)
 82  
         {
 83  0
             _handlers = new HashMap<String, DefineHandler>();
 84  0
             for (DefineHandler handler : TagHandlerUtils.findNextByType(nextHandler, DefineHandler.class))
 85  
             {
 86  0
                 _handlers.put(handler.getName(), handler);
 87  0
                 if (log.isLoggable(Level.FINE))
 88  
                 {
 89  0
                     log.fine(tag + " found Define[" + handler.getName() + "]");
 90  
                 }
 91  0
             }
 92  
 
 93  0
             Collection<LegacyParamHandler> params = TagHandlerUtils.findNextByType(nextHandler, 
 94  
                     LegacyParamHandler.class);
 95  0
             if (!params.isEmpty())
 96  
             {
 97  0
                 int i = 0;
 98  0
                 _params = new LegacyParamHandler[params.size()];
 99  0
                 for (LegacyParamHandler handler : params)
 100  
                 {
 101  0
                     _params[i++] = handler;
 102  0
                 }
 103  0
             }
 104  
             else
 105  
             {
 106  0
                 _params = null;
 107  
             }
 108  0
         }
 109  
         else
 110  
         {
 111  0
             _params = null;
 112  0
             _handlers = null;
 113  
         }
 114  0
     }
 115  
 
 116  
     /*
 117  
      * (non-Javadoc)
 118  
      * 
 119  
      * @see javax.faces.view.facelets.FaceletHandler#apply(javax.faces.view.facelets.FaceletContext,
 120  
      * javax.faces.component.UIComponent)
 121  
      */
 122  
     public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
 123  
             ELException
 124  
     {
 125  0
         if (_template != null)
 126  
         {
 127  0
             VariableMapper orig = ctx.getVariableMapper();
 128  0
             AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
 129  0
             actx.extendClient(this);
 130  0
             if (_params != null)
 131  
             {
 132  0
                 VariableMapper vm = new VariableMapperWrapper(orig);
 133  0
                 ctx.setVariableMapper(vm);
 134  0
                 for (int i = 0; i < _params.length; i++)
 135  
                 {
 136  0
                     _params[i].apply(ctx, parent);
 137  
                 }
 138  
             }
 139  
 
 140  
             try
 141  
             {
 142  0
                 ctx.includeFacelet(parent, _template.getValue(ctx));
 143  
             }
 144  
             finally
 145  
             {
 146  0
                 actx.popExtendedClient(this);
 147  0
                 ctx.setVariableMapper(orig);
 148  0
             }
 149  0
         }
 150  
         else
 151  
         {
 152  0
             this.nextHandler.apply(ctx, parent);
 153  
         }
 154  0
     }
 155  
 
 156  
     public boolean apply(FaceletContext ctx, UIComponent parent, String name) throws IOException, FacesException,
 157  
             FaceletException, ELException
 158  
     {
 159  0
         if (name != null)
 160  
         {
 161  0
             if (_handlers == null)
 162  
             {
 163  0
                 return false;
 164  
             }
 165  
             
 166  0
             DefineHandler handler = _handlers.get(name);
 167  0
             if (handler != null)
 168  
             {
 169  0
                 handler.applyDefinition(ctx, parent);
 170  0
                 return true;
 171  
             }
 172  
             else
 173  
             {
 174  0
                 return false;
 175  
             }
 176  
         }
 177  
         else
 178  
         {
 179  0
             this.nextHandler.apply(ctx, parent);
 180  0
             return true;
 181  
         }
 182  
     }
 183  
 
 184  
 }