Debian Codegraph @

net/sf/saxon/serialize/HTML40Emitter.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.SaxonOutputKeys;
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 4.0 output
18 */
19 public class HTML40Emitter extends HTMLEmitter {
20
21 static {
22 setEmptyTag("area");
23 setEmptyTag("base");
24 setEmptyTag("basefont");
25 setEmptyTag("br");
26 setEmptyTag("col");
27 setEmptyTag("embed");
28 setEmptyTag("frame");
29 setEmptyTag("hr");
30 setEmptyTag("img");
31 setEmptyTag("input");
32 setEmptyTag("isindex");
33 setEmptyTag("link");
34 setEmptyTag("meta");
35 setEmptyTag("param");
36 }
37
38
39 /**
40 * Constructor
41 */
42
43 public HTML40Emitter() {
44
45 }
46
47 /**
48 * Decide whether an element is "serialized as an HTML element" in the language of the 3.0 specification
49 *
50 * @return true if the element is to be serialized as an HTML element
51 */
52 @Override
53 protected boolean isHTMLElement(NodeName name) {
54 return name.getURI().equals("");
55 }
56
57 @Override
58 protected void openDocument() throws XPathException {
59
60 String versionProperty = outputProperties.getProperty(SaxonOutputKeys.HTML_VERSION);
61 // Note, we recognize html-version even when running XSLT 2.0.
62 if (versionProperty == null) {
63 versionProperty = outputProperties.getProperty(OutputKeys.VERSION);
64 }
65
66 if (versionProperty != null) {
67 if (versionProperty.equals("4.0") || versionProperty.equals("4.01")) {
68 version = 4;
69 } else {
70 XPathException err = new XPathException("Unsupported HTML version: " + versionProperty);
71 err.setErrorCode("SESU0013");
72 throw err;
73 }
74 }
75 String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM);
76 String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC);
77
78 // Treat "" as equivalent to absent. This goes beyond what the spec strictly allows.
79 if ("".equals(systemId)) {
80 systemId = null;
81 }
82 if ("".equals(publicId)) {
83 publicId = null;
84 }
85
86 super.openDocument();
87 if (systemId != null || publicId != null) {
88 writeDocType(null, "html", systemId, publicId);
89 }
90 }
91
92
93 }