Debian Codegraph @

net/sf/saxon/serialize/XHTML1Emitter.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
13 import java.util.Collections;
14 import java.util.HashSet;
15 import java.util.Set;
16
17
18 /**
19 * XHTMLEmitter is an Emitter that generates XHTML 1 output.
20 * It is the same as XMLEmitter except that it follows the legacy HTML browser
21 * compatibility rules: for example, generating empty elements such as [BR /], and
22 * using [p][/p] for empty paragraphs rather than [p/]
23 */
24
25 public class XHTML1Emitter extends XMLEmitter {
26
27 /**
28 * Table of XHTML tags that have no closing tag
29 */
30
31 static Set<String> emptyTags1 = new HashSet<String>(31);
32
33 private static String[] emptyTagNames1 = {
34 "area", "base", "basefont", "br", "col", "embed", "frame", "hr", "img", "input", "isindex", "link", "meta", "param"
35 // added "embed" in 9.5
36 };
37
38
39 static {
40 Collections.addAll(emptyTags1, emptyTagNames1);
41 }
42
43
44 private boolean isRecognizedHtmlElement(NodeName name) {
45 return name.hasURI(NamespaceConstant.XHTML);
46
47 }
48
49 /**
50 * Close an empty element tag.
51 */
52
53 protected String emptyElementTagCloser(String displayName, /*@NotNull*/ NodeName name) {
54 if (isRecognizedHtmlElement(name) && emptyTags1.contains(name.getLocalPart())) {
55 return " />";
56 } else {
57 return "></" + displayName + '>';
58 }
59 }
60
61
62 }
63