View Javadoc
1   /*
2    * Copyright (c) 2002-2025 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  @JsxClass(domClass = HtmlUnknownElement.class)
36  public class HTMLUnknownElement extends HTMLElement {
37  
38      /**
39       * JavaScript constructor.
40       */
41      @Override
42      @JsxConstructor
43      public void jsConstructor() {
44          super.jsConstructor();
45      }
46  
47      /**
48       * Gets the JavaScript property {@code nodeName} for the current node.
49       * @return the node name
50       */
51      @Override
52      public String getNodeName() {
53          final HtmlElement elem = getDomNodeOrDie();
54          final Page page = elem.getPage();
55          if (page instanceof XmlPage) {
56              return elem.getLocalName();
57          }
58          return super.getNodeName();
59      }
60  
61      /**
62       * {@inheritDoc}
63       */
64      @Override
65      public String getClassName() {
66          if (getWindow().getWebWindow() != null) {
67              final HtmlElement element = getDomNodeOrNull();
68              if (element != null) {
69                  final String name = element.getNodeName();
70                  if (HtmlRb.TAG_NAME.equals(name)
71                                  || HtmlRp.TAG_NAME.equals(name)
72                                  || HtmlRt.TAG_NAME.equals(name)
73                                  || HtmlRtc.TAG_NAME.equals(name)
74                                  || HtmlRuby.TAG_NAME.equals(name)) {
75                      return "HTMLElement";
76                  }
77  
78                  if (name.indexOf('-') != -1) {
79                      return "HTMLElement";
80                  }
81              }
82          }
83          return super.getClassName();
84      }
85  
86      /**
87       * {@inheritDoc}
88       */
89      @Override
90      protected boolean isLowerCaseInOuterHtml() {
91          return true;
92      }
93  
94      /**
95       * {@inheritDoc}
96       */
97      @Override
98      protected boolean isEndTagForbidden() {
99          final String nodeName = getNodeName();
100         if ("BGSOUND".equals(nodeName) || "KEYGEN".equals(nodeName)) {
101             return true;
102         }
103         return super.isEndTagForbidden();
104     }
105 }