-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocumentType.java
More file actions
109 lines (99 loc) · 3.42 KB
/
Copy pathDocumentType.java
File metadata and controls
109 lines (99 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package org.jsoup.nodes;
import org.jsoup.internal.StringUtil;
import org.jsoup.helper.Validate;
import org.jsoup.nodes.Document.OutputSettings.Syntax;
import java.io.IOException;
/**
* A {@code <!DOCTYPE>} node.
*/
public class DocumentType extends LeafNode {
// todo needs a bit of a chunky cleanup. this level of detail isn't needed
public static final String PUBLIC_KEY = "PUBLIC";
public static final String SYSTEM_KEY = "SYSTEM";
private static final String NAME = "name";
private static final String PUB_SYS_KEY = "pubSysKey"; // PUBLIC or SYSTEM
private static final String PUBLIC_ID = "publicId";
private static final String SYSTEM_ID = "systemId";
// todo: quirk mode from publicId and systemId
/**
* Create a new doctype element.
* @param name the doctype's name
* @param publicId the doctype's public ID
* @param systemId the doctype's system ID
*/
public DocumentType(String name, String publicId, String systemId) {
Validate.notNull(name);
Validate.notNull(publicId);
Validate.notNull(systemId);
attr(NAME, name);
attr(PUBLIC_ID, publicId);
if (has(PUBLIC_ID)) {
attr(PUB_SYS_KEY, PUBLIC_KEY);
}
attr(SYSTEM_ID, systemId);
}
/**
* Create a new doctype element.
* @param name the doctype's name
* @param publicId the doctype's public ID
* @param systemId the doctype's system ID
* @param baseUri unused
* @deprecated
*/
public DocumentType(String name, String publicId, String systemId, String baseUri) {
attr(NAME, name);
attr(PUBLIC_ID, publicId);
if (has(PUBLIC_ID)) {
attr(PUB_SYS_KEY, PUBLIC_KEY);
}
attr(SYSTEM_ID, systemId);
}
/**
* Create a new doctype element.
* @param name the doctype's name
* @param publicId the doctype's public ID
* @param systemId the doctype's system ID
* @param baseUri unused
* @deprecated
*/
public DocumentType(String name, String pubSysKey, String publicId, String systemId, String baseUri) {
attr(NAME, name);
if (pubSysKey != null) {
attr(PUB_SYS_KEY, pubSysKey);
}
attr(PUBLIC_ID, publicId);
attr(SYSTEM_ID, systemId);
}
public void setPubSysKey(String value) {
if (value != null)
attr(PUB_SYS_KEY, value);
}
@Override
public String nodeName() {
return "#doctype";
}
@Override
void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException {
if (out.syntax() == Syntax.html && !has(PUBLIC_ID) && !has(SYSTEM_ID)) {
// looks like a html5 doctype, go lowercase for aesthetics
accum.append("<!doctype");
} else {
accum.append("<!DOCTYPE");
}
if (has(NAME))
accum.append(" ").append(attr(NAME));
if (has(PUB_SYS_KEY))
accum.append(" ").append(attr(PUB_SYS_KEY));
if (has(PUBLIC_ID))
accum.append(" \"").append(attr(PUBLIC_ID)).append('"');
if (has(SYSTEM_ID))
accum.append(" \"").append(attr(SYSTEM_ID)).append('"');
accum.append('>');
}
@Override
void outerHtmlTail(Appendable accum, int depth, Document.OutputSettings out) {
}
private boolean has(final String attribute) {
return !StringUtil.isBlank(attr(attribute));
}
}