1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.html;
16
17 import java.util.Collection;
18 import java.util.Collections;
19 import java.util.HashSet;
20 import java.util.Map;
21
22 import org.apache.commons.lang3.StringUtils;
23 import org.htmlunit.SgmlPage;
24
25
26
27
28
29
30
31
32
33
34
35 public class HtmlFieldSet extends HtmlElement implements DisabledElement, ValidatableElement, FormFieldWithNameHistory {
36
37
38 public static final String TAG_NAME = "fieldset";
39
40 private final String originalName_;
41 private Collection<String> newNames_ = Collections.emptySet();
42 private String customValidity_;
43
44
45
46
47
48
49
50
51 HtmlFieldSet(final String qualifiedName, final SgmlPage page,
52 final Map<String, DomAttr> attributes) {
53 super(qualifiedName, page, attributes);
54 originalName_ = getAttributeDirect(NAME_ATTRIBUTE);
55 }
56
57
58
59
60 @Override
61 public boolean willValidate() {
62 return false;
63 }
64
65
66
67
68 @Override
69 public void setCustomValidity(final String message) {
70 customValidity_ = message;
71 }
72
73
74
75
76 @Override
77 public boolean isCustomErrorValidityState() {
78 return !StringUtils.isEmpty(customValidity_);
79 }
80
81
82
83
84 @Override
85 public boolean isValid() {
86 return true;
87 }
88
89 @Override
90 public boolean isValidValidityState() {
91 return !isCustomErrorValidityState();
92 }
93
94
95
96
97 @Override
98 protected void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue,
99 final boolean notifyAttributeChangeListeners, final boolean notifyMutationObservers) {
100 final String qualifiedNameLC = StringUtils.toRootLowerCase(qualifiedName);
101 if (NAME_ATTRIBUTE.equals(qualifiedNameLC)) {
102 if (newNames_.isEmpty()) {
103 newNames_ = new HashSet<>();
104 }
105 newNames_.add(attributeValue);
106 }
107 super.setAttributeNS(namespaceURI, qualifiedNameLC, attributeValue, notifyAttributeChangeListeners,
108 notifyMutationObservers);
109 }
110
111
112
113
114 @Override
115 public String getOriginalName() {
116 return originalName_;
117 }
118
119
120
121
122 @Override
123 public Collection<String> getNewNames() {
124 return newNames_;
125 }
126
127
128
129
130 @Override
131 public final String getDisabledAttribute() {
132 return getAttributeDirect(ATTRIBUTE_DISABLED);
133 }
134
135
136
137
138 @Override
139 public final boolean isDisabled() {
140 if (hasAttribute(ATTRIBUTE_DISABLED)) {
141 return true;
142 }
143
144 DomNode node = getParentNode();
145 while (node != null) {
146 if (node instanceof DisabledElement
147 && ((DisabledElement) node).isDisabled()) {
148 return true;
149 }
150 node = node.getParentNode();
151 }
152
153 return false;
154 }
155 }