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.HTMLMENUITEM_END_TAG_FORBIDDEN;
18  import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_HTML_HYPHEN_ELEMENT_CLASS_NAME;
19  import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_HTML_RUBY_ELEMENT_CLASS_NAME;
20  import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME;
21  import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE;
22  import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF;
23  
24  import com.gargoylesoftware.htmlunit.Page;
25  import com.gargoylesoftware.htmlunit.html.HtmlElement;
26  import com.gargoylesoftware.htmlunit.html.HtmlRp;
27  import com.gargoylesoftware.htmlunit.html.HtmlRt;
28  import com.gargoylesoftware.htmlunit.html.HtmlRuby;
29  import com.gargoylesoftware.htmlunit.html.HtmlUnknownElement;
30  import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass;
31  import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor;
32  import com.gargoylesoftware.htmlunit.xml.XmlPage;
33  
34  /**
35   * The JavaScript object {@code HTMLUnknownElement}.
36   *
37   * @author Ahmed Ashour
38   * @author Ronald Brill
39   */
40  @JsxClass(domClass = HtmlUnknownElement.class)
41  public class HTMLUnknownElement extends HTMLElement {
42  
43      /**
44       * Creates an instance.
45       */
46      @JsxConstructor({CHROME, FF, EDGE})
47      public HTMLUnknownElement() {
48      }
49  
50      /**
51       * Gets the JavaScript property {@code nodeName} for the current node.
52       * @return the node name
53       */
54      @Override
55      public String getNodeName() {
56          final HtmlElement elem = getDomNodeOrDie();
57          final Page page = elem.getPage();
58          if (page instanceof XmlPage) {
59              return elem.getLocalName();
60          }
61          return super.getNodeName();
62      }
63  
64      /**
65       * {@inheritDoc}
66       */
67      @Override
68      public String getClassName() {
69          if (getWindow().getWebWindow() != null) {
70              final HtmlElement element = getDomNodeOrNull();
71              if (element != null) {
72                  final String name = element.getNodeName();
73                  if (getBrowserVersion().hasFeature(JS_HTML_RUBY_ELEMENT_CLASS_NAME)
74                          && (HtmlRp.TAG_NAME.equals(name)
75                                  || HtmlRt.TAG_NAME.equals(name)
76                                  || HtmlRuby.TAG_NAME.equals(name)
77                                  || "rb".equals(name)
78                                  || "rtc".equals(name))) {
79                      return "HTMLElement";
80                  }
81  
82                  if (name.indexOf('-') != -1
83                      && getBrowserVersion().hasFeature(JS_HTML_HYPHEN_ELEMENT_CLASS_NAME)) {
84                      return "HTMLElement";
85                  }
86              }
87          }
88          return super.getClassName();
89      }
90  
91      /**
92       * {@inheritDoc}
93       */
94      @Override
95      protected boolean isLowerCaseInOuterHtml() {
96          return true;
97      }
98  
99      /**
100      * {@inheritDoc}
101      */
102     @Override
103     protected boolean isEndTagForbidden() {
104         if ("BGSOUND".equals(getNodeName())
105                 || (getBrowserVersion().hasFeature(HTMLMENUITEM_END_TAG_FORBIDDEN)
106                         && "MENUITEM".equals(getNodeName()))) {
107             return true;
108         }
109         return super.isEndTagForbidden();
110     }
111 }