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.HTMLBASEFONT_END_TAG_FORBIDDEN;
18  import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME;
19  import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE;
20  import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF;
21  
22  import java.util.Locale;
23  
24  import com.gargoylesoftware.htmlunit.BrowserVersion;
25  import com.gargoylesoftware.htmlunit.html.DomNode;
26  import com.gargoylesoftware.htmlunit.html.HtmlSpan;
27  import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass;
28  import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor;
29  
30  /**
31   * The JavaScript object {@code HTMLSpanElement}.
32   *
33   * @author Ahmed Ashour
34   * @author Daniel Gredler
35   * @author Ronald Brill
36   */
37  @JsxClass(domClass = HtmlSpan.class)
38  public class HTMLSpanElement extends HTMLElement {
39  
40      private boolean endTagForbidden_;
41  
42      /**
43       * Creates an instance.
44       */
45      @JsxConstructor({CHROME, FF, EDGE})
46      public HTMLSpanElement() {
47      }
48  
49      /**
50       * Sets the DOM node that corresponds to this JavaScript object.
51       * @param domNode the DOM node
52       */
53      @Override
54      public void setDomNode(final DomNode domNode) {
55          super.setDomNode(domNode);
56          final BrowserVersion browser = getBrowserVersion();
57          if (browser.hasFeature(HTMLBASEFONT_END_TAG_FORBIDDEN)) {
58              switch (domNode.getLocalName().toLowerCase(Locale.ROOT)) {
59                  case "basefont":
60                  case "keygen":
61                      endTagForbidden_ = true;
62                      break;
63                  default:
64              }
65          }
66      }
67  
68      /**
69       * Returns the value of the {@code cite} property.
70       * @return the value of the {@code cite} property
71       */
72      public String getCite() {
73          final String cite = getDomNodeOrDie().getAttribute("cite");
74          return cite;
75      }
76  
77      /**
78       * Returns the value of the {@code cite} property.
79       * @param cite the value
80       */
81      public void setCite(final String cite) {
82          getDomNodeOrDie().setAttribute("cite", cite);
83      }
84  
85      /**
86       * Returns the value of the {@code dateTime} property.
87       * @return the value of the {@code dateTime} property
88       */
89      public String getDateTime() {
90          final String dateTime = getDomNodeOrDie().getAttribute("datetime");
91          return dateTime;
92      }
93  
94      /**
95       * Returns the value of the {@code dateTime} property.
96       * @param dateTime the value
97       */
98      public void setDateTime(final String dateTime) {
99          getDomNodeOrDie().setAttribute("datetime", dateTime);
100     }
101 
102     /**
103      * {@inheritDoc}
104      */
105     @Override
106     protected boolean isLowerCaseInOuterHtml() {
107         return super.isLowerCaseInOuterHtml();
108     }
109 
110     /**
111      * Returns whether the end tag is forbidden or not.
112      * @see <a href="http://www.w3.org/TR/html4/index/elements.html">HTML 4 specs</a>
113      * @return whether the end tag is forbidden or not
114      */
115     @Override
116     protected boolean isEndTagForbidden() {
117         return endTagForbidden_;
118     }
119 }