View Javadoc
1   /*
2    * Copyright (c) 2002-2026 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.html;
16  
17  import java.util.Map;
18  
19  import org.htmlunit.SgmlPage;
20  import org.htmlunit.util.StringUtils;
21  
22  /**
23   * Wrapper for the HTML element "fieldset".
24   *
25   * @author Mike Bowler
26   * @author David K. Taylor
27   * @author Christian Sell
28   * @author Ahmed Ashour
29   * @author Frank Danek
30   * @author Ronald Brill
31   * @author Lai Quang Duong
32   */
33  public class HtmlFieldSet extends HtmlElement implements DisabledElement, ValidatableElement {
34  
35      /** The HTML tag represented by this element. */
36      public static final String TAG_NAME = "fieldset";
37  
38      private String customValidity_;
39  
40      /**
41       * Creates an instance of HtmlFieldSet
42       *
43       * @param qualifiedName the qualified name of the element type to instantiate
44       * @param page the HtmlPage that contains this element
45       * @param attributes the initial attributes
46       */
47      HtmlFieldSet(final String qualifiedName, final SgmlPage page,
48              final Map<String, DomAttr> attributes) {
49          super(qualifiedName, page, attributes);
50      }
51  
52      /**
53       * {@inheritDoc}
54       */
55      @Override
56      public boolean willValidate() {
57          return false;
58      }
59  
60      /**
61       * {@inheritDoc}
62       */
63      @Override
64      public void setCustomValidity(final String message) {
65          customValidity_ = message;
66      }
67  
68      /**
69       * {@inheritDoc}
70       */
71      @Override
72      public boolean isCustomErrorValidityState() {
73          return !StringUtils.isEmptyOrNull(customValidity_);
74      }
75  
76      /**
77       * {@inheritDoc}
78       */
79      @Override
80      public boolean isValid() {
81          return true;
82      }
83  
84      @Override
85      public boolean isValidValidityState() {
86          return !isCustomErrorValidityState();
87      }
88  
89      /**
90       * {@inheritDoc}
91       */
92      @Override
93      public final String getDisabledAttribute() {
94          return getAttributeDirect(ATTRIBUTE_DISABLED);
95      }
96  
97      /**
98       * {@inheritDoc}
99       */
100     @Override
101     public final boolean isDisabled() {
102         if (hasAttribute(ATTRIBUTE_DISABLED)) {
103             return true;
104         }
105 
106         DomNode node = getParentNode();
107         while (node != null) {
108             if (node instanceof DisabledElement element
109                     && element.isDisabled()) {
110                 return true;
111             }
112             node = node.getParentNode();
113         }
114 
115         return false;
116     }
117 }