View Javadoc
1   /*
2    * Copyright (c) 2002-2017 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    * http://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 com.gargoylesoftware.htmlunit.javascript.host.html;
16  
17  import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_HTML_HYPHEN_ELEMENT_CLASS_NAME;
18  import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_HTML_RUBY_ELEMENT_CLASS_NAME;
19  import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME;
20  import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE;
21  import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF;
22  
23  import com.gargoylesoftware.htmlunit.Page;
24  import com.gargoylesoftware.htmlunit.html.HtmlElement;
25  import com.gargoylesoftware.htmlunit.html.HtmlRp;
26  import com.gargoylesoftware.htmlunit.html.HtmlRt;
27  import com.gargoylesoftware.htmlunit.html.HtmlRuby;
28  import com.gargoylesoftware.htmlunit.html.HtmlUnknownElement;
29  import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass;
30  import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor;
31  import com.gargoylesoftware.htmlunit.xml.XmlPage;
32  
33  /**
34   * The JavaScript object {@code HTMLUnknownElement}.
35   *
36   * @author Ahmed Ashour
37   * @author Ronald Brill
38   */
39  @JsxClass(domClass = HtmlUnknownElement.class)
40  public class HTMLUnknownElement extends HTMLElement {
41  
42      /**
43       * Creates an instance.
44       */
45      @JsxConstructor({CHROME, FF, EDGE})
46      public HTMLUnknownElement() {
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 (getBrowserVersion().hasFeature(JS_HTML_RUBY_ELEMENT_CLASS_NAME)
73                          && (HtmlRp.TAG_NAME.equals(name)
74                                  || HtmlRt.TAG_NAME.equals(name)
75                                  || HtmlRuby.TAG_NAME.equals(name)
76                                  || "rb".equals(name)
77                                  || "rtc".equals(name))) {
78                      return "HTMLElement";
79                  }
80  
81                  if (name.indexOf('-') != -1
82                      && getBrowserVersion().hasFeature(JS_HTML_HYPHEN_ELEMENT_CLASS_NAME)) {
83                      return "HTMLElement";
84                  }
85              }
86          }
87          return super.getClassName();
88      }
89  
90      /**
91       * {@inheritDoc}
92       */
93      @Override
94      protected boolean isLowerCaseInOuterHtml() {
95          return true;
96      }
97  
98      /**
99       * {@inheritDoc}
100      */
101     @Override
102     protected boolean isEndTagForbidden() {
103         if ("BGSOUND".equals(getNodeName())) {
104             return true;
105         }
106         return super.isEndTagForbidden();
107     }
108 }