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.custom.document;
20  
21  import java.io.IOException;
22  
23  import javax.faces.context.FacesContext;
24  
25  import org.apache.myfaces.component.html.util.StreamingAddResource;
26  import org.apache.myfaces.renderkit.html.util.AddResource;
27  import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
28  
29  /**
30   * Document to enclose the document head. If not otherwise possible you can use
31   * state="start|end" to demarkate the document boundaries
32   * 
33   * @JSFRenderer
34   *   renderKitId = "HTML_BASIC"
35   *   family = "javax.faces.Data"
36   *   type = "org.apache.myfaces.DocumentHead"
37   * 
38   * @author Mario Ivankovits (latest modification by $Author: skitching $)
39   * @version $Revision: 673833 $ $Date: 2008-07-03 16:58:05 -0500 (Thu, 03 Jul 2008) $
40   */
41  public class DocumentHeadRenderer extends AbstractDocumentRenderer
42  {
43      public static final String RENDERER_TYPE = "org.apache.myfaces.DocumentHead";
44  
45      protected String getHtmlTag()
46      {
47          return "head";
48      }
49  
50      protected Class getDocumentClass()
51      {
52          return DocumentHead.class;
53      }
54  
55      protected void writeBeforeEnd(FacesContext facesContext) throws IOException
56      {
57          super.writeBeforeEnd(facesContext);
58          
59          AddResource addResource = AddResourceFactory.getInstance(facesContext);
60          if (addResource instanceof StreamingAddResource)
61          {
62              ((StreamingAddResource) addResource).addStyleLoaderHere(facesContext, DocumentHead.class);
63          }
64      }
65  }