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.javascript.host.html;
16  
17  import org.htmlunit.Page;
18  import org.htmlunit.html.HtmlElement;
19  import org.htmlunit.html.HtmlRb;
20  import org.htmlunit.html.HtmlRp;
21  import org.htmlunit.html.HtmlRt;
22  import org.htmlunit.html.HtmlRtc;
23  import org.htmlunit.html.HtmlRuby;
24  import org.htmlunit.html.HtmlUnknownElement;
25  import org.htmlunit.javascript.configuration.JsxClass;
26  import org.htmlunit.javascript.configuration.JsxConstructor;
27  import org.htmlunit.xml.XmlPage;
28  
29  /**
30   * The JavaScript object {@code HTMLUnknownElement}.
31   *
32   * @author Ahmed Ashour
33   * @author Ronald Brill
34   *
35   * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLUnknownElement">MDN Documentation</a>
36   */
37  @JsxClass(domClass = HtmlUnknownElement.class)
38  public class HTMLUnknownElement extends HTMLElement {
39  
40      /**
41       * JavaScript constructor.
42       */
43      @Override
44      @JsxConstructor
45      public void jsConstructor() {
46          super.jsConstructor();
47      }
48  
49      /**
50       * Gets the JavaScript property {@code nodeName} for the current node.
51       * @return the node name
52       */
53      @Override
54      public String getNodeName() {
55          final HtmlElement elem = getDomNodeOrDie();
56          final Page page = elem.getPage();
57          if (page instanceof XmlPage) {
58              return elem.getLocalName();
59          }
60          return super.getNodeName();
61      }
62  
63      /**
64       * {@inheritDoc}
65       */
66      @Override
67      public String getClassName() {
68          if (getWindow().getWebWindow() != null) {
69              final HtmlElement element = getDomNodeOrNull();
70              if (element != null) {
71                  final String name = element.getNodeName();
72                  if (HtmlRb.TAG_NAME.equals(name)
73                                  || HtmlRp.TAG_NAME.equals(name)
74                                  || HtmlRt.TAG_NAME.equals(name)
75                                  || HtmlRtc.TAG_NAME.equals(name)
76                                  || HtmlRuby.TAG_NAME.equals(name)) {
77                      return "HTMLElement";
78                  }
79  
80                  if (name.indexOf('-') != -1) {
81                      return "HTMLElement";
82                  }
83              }
84          }
85          return super.getClassName();
86      }
87  
88      /**
89       * {@inheritDoc}
90       */
91      @Override
92      protected boolean isLowerCaseInOuterHtml() {
93          return true;
94      }
95  
96      /**
97       * {@inheritDoc}
98       */
99      @Override
100     protected boolean isEndTagForbidden() {
101         final String nodeName = getNodeName();
102         if ("BGSOUND".equals(nodeName) || "KEYGEN".equals(nodeName)) {
103             return true;
104         }
105         return super.isEndTagForbidden();
106     }
107 }