-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParseSettings.java
58 lines (49 loc) · 1.5 KB
/
ParseSettings.java
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
package org.jsoup.parser;
import org.jsoup.nodes.Attributes;
import static org.jsoup.internal.Normalizer.lowerCase;
/**
* Controls parser settings, to optionally preserve tag and/or attribute name case.
*/
public class ParseSettings {
/**
* HTML default settings: both tag and attribute names are lower-cased during parsing.
*/
public static final ParseSettings htmlDefault;
/**
* Preserve both tag and attribute case.
*/
public static final ParseSettings preserveCase;
static {
htmlDefault = new ParseSettings(false, false);
preserveCase = new ParseSettings(true, true);
}
private final boolean preserveTagCase;
private final boolean preserveAttributeCase;
/**
* Define parse settings.
* @param tag preserve tag case?
* @param attribute preserve attribute name case?
*/
public ParseSettings(boolean tag, boolean attribute) {
preserveTagCase = tag;
preserveAttributeCase = attribute;
}
public String normalizeTag(String name) {
name = name.trim();
if (!preserveTagCase)
name = lowerCase(name);
return name;
}
public String normalizeAttribute(String name) {
name = name.trim();
if (!preserveAttributeCase)
name = lowerCase(name);
return name;
}
Attributes normalizeAttributes(Attributes attributes) {
if (!preserveAttributeCase) {
attributes.normalize();
}
return attributes;
}
}