View Javadoc

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.html;
20  
21  import java.util.Iterator;
22  
23  import javax.faces.component.UIComponent;
24  import javax.faces.component.UIViewRoot;
25  import javax.faces.view.facelets.ComponentConfig;
26  import javax.faces.view.facelets.FaceletContext;
27  
28  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
29  import org.apache.myfaces.view.facelets.FaceletCompositionContext;
30  import org.apache.myfaces.view.facelets.el.CompositeComponentELUtils;
31  import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
32  import org.apache.myfaces.view.facelets.tag.jsf.RelocatableResourceHandler;
33  
34  /**
35   * 
36   * @since 2.0
37   * @author Leonardo Uribe (latest modification by $Author$)
38   * @version $Revision$ $Date$
39   */
40  @JSFFaceletTag(
41          name = "h:outputStylesheet",
42          componentClass = "org.apache.myfaces.view.facelets.tag.jsf.html._HtmlOutputStylesheet")
43  public class HtmlOutputStylesheetHandler extends HtmlComponentHandler implements RelocatableResourceHandler
44  {
45  
46      public HtmlOutputStylesheetHandler(ComponentConfig config)
47      {
48          super(config);
49      }
50  
51      public UIComponent findChildByTagId(FaceletContext ctx, UIComponent parent,
52              String id)
53      {
54          UIComponent c = null;
55          UIViewRoot root = ComponentSupport.getViewRoot(ctx, parent);
56          if (root.getFacetCount() > 0)
57          {
58              Iterator<UIComponent> itr = root.getFacets().values().iterator();
59              while (itr.hasNext() && c == null)
60              {
61                  UIComponent facet = itr.next();
62                  c = ComponentSupport.findChildByTagId(facet, id);
63              }
64          }
65          return c;
66      }
67  
68      @Override
69      public void onComponentCreated(FaceletContext ctx, UIComponent c,
70              UIComponent parent)
71      {
72          UIComponent parentCompositeComponent
73                  = FaceletCompositionContext.getCurrentInstance(ctx).getCompositeComponentFromStack();
74          if (parentCompositeComponent != null)
75          {
76              c.getAttributes().put(CompositeComponentELUtils.LOCATION_KEY,
77                      parentCompositeComponent.getAttributes().get(CompositeComponentELUtils.LOCATION_KEY));
78          }
79      }
80  
81  }