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.jsf; 21 22 import java.util.Iterator; 23 import javax.faces.component.UIComponent; 24 import javax.faces.component.UIViewRoot; 25 import javax.faces.view.facelets.FaceletContext; 26 27 /** 28 * This class is used in cases where alternate implementations of h:outputScript and h:outputStylesheet 29 * components are used overriding a tag handler and providing a new tag name, but preserving the componentType 30 * and rendererType. In those components, the relocation hack is done, but it is necessary to provide the 31 * additional code from the implementation. 32 */ 33 public class ComponentRelocatableResourceHandler implements RelocatableResourceHandler 34 { 35 public static final ComponentRelocatableResourceHandler INSTANCE = new ComponentRelocatableResourceHandler(); 36 37 @Override 38 public UIComponent findChildByTagId(FaceletContext ctx, UIComponent parent, 39 String id) 40 { 41 UIComponent c = null; 42 UIViewRoot root = ComponentSupport.getViewRoot(ctx, parent); 43 if (root.getFacetCount() > 0) 44 { 45 Iterator<UIComponent> itr = root.getFacets().values().iterator(); 46 while (itr.hasNext() && c == null) 47 { 48 UIComponent facet = itr.next(); 49 c = ComponentSupport.findChildByTagId(facet, id); 50 } 51 } 52 return c; 53 } 54 55 }