Debian Codegraph @

net/sf/saxon/serialize/HTML50Emitter.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.serialize;
9
10 import net.sf.saxon.lib.NamespaceConstant;
11 import net.sf.saxon.om.NodeName;
12 import net.sf.saxon.trans.XPathException;
13
14 import javax.xml.transform.OutputKeys;
15
16 /**
17 * This class generates HTML 5.0 output
18 */
19 public class HTML50Emitter extends HTMLEmitter {
20
21
22 static {
23 setEmptyTag("area");
24 setEmptyTag("base");
25 setEmptyTag("base");
26 setEmptyTag("basefont");
27 setEmptyTag("br");
28 setEmptyTag("col");
29 //setEmptyTag("command"); // bug 3277 (spec bug 30119)
30 setEmptyTag("embed");
31 setEmptyTag("frame");
32 setEmptyTag("hr");
33 setEmptyTag("img");
34 setEmptyTag("input");
35 setEmptyTag("isindex");
36 setEmptyTag("keygen");
37 setEmptyTag("link");
38 setEmptyTag("meta");
39 setEmptyTag("param");
40 setEmptyTag("source");
41 setEmptyTag("track");
42 setEmptyTag("wbr");
43 }
44
45 /**
46 * Constructor
47 */
48
49 public HTML50Emitter() {
50 version = 5;
51 }
52
53 /**
54 * Decide whether an element is "serialized as an HTML element" in the language of the 3.0 specification
55 *
56 * @return true if the element is to be serialized as an HTML element
57 */
58 @Override
59 protected boolean isHTMLElement(NodeName name) {
60 String uri = name.getURI();
61 return uri.equals("") || uri.equals(NamespaceConstant.XHTML);
62 }
63
64 protected void openDocument() throws XPathException {
65 version = 5;
66 String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM);
67 String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC);
68
69 // Treat "" as equivalent to absent. This goes beyond what the spec strictly allows.
70 if ("".equals(systemId)) {
71 systemId = null;
72 }
73 if ("".equals(publicId)) {
74 publicId = null;
75 }
76 super.openDocument();
77 writeDocType(null, "html", systemId, publicId);
78 }
79
80 /**
81 * Output the document type declaration
82 *
83 * @param displayName The element name
84 * @param systemId The DOCTYP system identifier
85 * @param publicId The DOCTYPE public identifier
86 */
87
88 protected void writeDocType(NodeName name, String displayName, String systemId, String publicId) throws XPathException {
89 try {
90 if (systemId == null && publicId == null) {
91 writer.write("<!DOCTYPE HTML>\n");
92 } else {
93 super.writeDocType(name, displayName, systemId, publicId);
94 }
95 } catch (java.io.IOException err) {
96 throw new XPathException(err);
97 }
98
99 }
100
101 protected boolean writeDocTypeWithNullSystemId() {
102 return true;
103 }
104 }