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.renderkit.html;
20  
21  import java.io.IOException;
22  import java.util.Map;
23  
24  import javax.faces.component.UIComponent;
25  import javax.faces.context.FacesContext;
26  import javax.faces.context.ResponseWriter;
27  import javax.faces.render.Renderer;
28  
29  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFRenderer;
30  
31  /**
32   * Rendered used by h:doctype tag
33   * 
34   * @since 2.1.0
35   * @author Leonardo Uribe
36   *
37   */
38  @JSFRenderer(renderKitId = "HTML_BASIC", family = "javax.faces.Output", type = "javax.faces.Doctype")
39  public class HtmlDoctypeRenderer extends Renderer
40  {
41  
42      @Override
43      public void encodeChildren(FacesContext context, UIComponent component)
44              throws IOException
45      {
46      }
47      
48      @Override
49      public void encodeEnd(FacesContext context, UIComponent component)
50              throws IOException
51      {
52          super.encodeEnd(context, component);
53          
54          ResponseWriter writer = context.getResponseWriter();
55          
56          Map<String, Object> attributes = component.getAttributes();
57          //<!DOCTYPE html PUBLIC
58          // "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
59          writer.write("<!DOCTYPE ");
60          writer.write((String) attributes.get("rootElement"));
61          String publicValue = (String) attributes.get("public"); 
62          if (publicValue != null && publicValue.length() > 0)
63          {
64              writer.write(" PUBLIC \"");
65              writer.write(publicValue);
66              writer.write("\"");
67          }
68          String systemValue = (String) attributes.get("system");
69          if (systemValue != null && systemValue.length() > 0)
70          {
71              writer.write(" \"");
72              writer.write(systemValue);
73              writer.write("\"");
74          }
75          writer.write(">");
76      }
77  }