-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXmlDeclaration.java
More file actions
96 lines (83 loc) · 2.74 KB
/
Copy pathXmlDeclaration.java
File metadata and controls
96 lines (83 loc) · 2.74 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
package org.jsoup.nodes;
import org.jsoup.internal.StringUtil;
import org.jsoup.helper.Validate;
import java.io.IOException;
/**
* An XML Declaration.
*/
public class XmlDeclaration extends LeafNode {
// todo this impl isn't really right, the data shouldn't be attributes, just a run of text after the name
private final boolean isProcessingInstruction; // <! if true, <? if false, declaration (and last data char should be ?)
/**
* Create a new XML declaration
*
* @param name of declaration
* @param isProcessingInstruction is processing instruction
*/
public XmlDeclaration(String name, boolean isProcessingInstruction) {
Validate.notNull(name);
value = name;
this.isProcessingInstruction = isProcessingInstruction;
}
/**
* Create a new XML declaration
*
* @param name of declaration
* @param baseUri Leaf Nodes don't have base URIs; they inherit from their
* Element
* @param isProcessingInstruction is processing instruction
* @see XmlDeclaration#XmlDeclaration(String, boolean)
* @deprecated
*/
public XmlDeclaration(String name, String baseUri, boolean isProcessingInstruction) {
this(name, isProcessingInstruction);
}
public String nodeName() {
return "#declaration";
}
/**
* Get the name of this declaration.
*
* @return name of this declaration.
*/
public String name() {
return coreValue();
}
/**
* Get the unencoded XML declaration.
*
* @return XML declaration
*/
public String getWholeDeclaration() {
StringBuilder sb = StringUtil.borrowBuilder();
try {
getWholeDeclaration(sb, new Document.OutputSettings());
} catch (IOException e) {
}
return StringUtil.releaseBuilder(sb).trim();
}
private void getWholeDeclaration(Appendable accum, Document.OutputSettings out) throws IOException {
for (Attribute attribute : attributes()) {
if (!attribute.getKey().equals(nodeName())) { // skips coreValue (name)
accum.append(' ');
attribute.html(accum, out);
}
}
}
void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException {
accum
.append("<")
.append(isProcessingInstruction ? "!" : "?")
.append(coreValue());
getWholeDeclaration(accum, out);
accum
.append(isProcessingInstruction ? "!" : "?")
.append(">");
}
void outerHtmlTail(Appendable accum, int depth, Document.OutputSettings out) {
}
@Override
public String toString() {
return outerHtml();
}
}