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.HTMLBASE_HREF_DEFAULT_EMPTY;
18  import static com.gargoylesoftware.htmlunit.html.DomElement.ATTRIBUTE_NOT_DEFINED;
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.html.HtmlBase;
24  import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass;
25  import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor;
26  import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter;
27  import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter;
28  
29  /**
30   * The JavaScript object {@code HTMLBaseElement}.
31   *
32   * @author Ahmed Ashour
33   * @author Ronald Brill
34   */
35  @JsxClass(domClass = HtmlBase.class)
36  public class HTMLBaseElement extends HTMLElement {
37  
38      /**
39       * The constructor.
40       */
41      @JsxConstructor({CHROME, FF, EDGE})
42      public HTMLBaseElement() {
43      }
44  
45      /**
46       * Returns the value of the {@code href} property.
47       * @return the value of the {@code href} property
48       */
49      @JsxGetter
50      public String getHref() {
51          final String href = getDomNodeOrDie().getAttribute("href");
52          if (ATTRIBUTE_NOT_DEFINED == href) {
53              if (getBrowserVersion().hasFeature(HTMLBASE_HREF_DEFAULT_EMPTY)) {
54                  return href;
55              }
56              return getWindow().getLocation().getHref();
57          }
58          return href;
59      }
60  
61      /**
62       * Sets the value of the {@code href} property.
63       * @param href the value of the {@code href} property
64       */
65      @JsxSetter
66      public void setHref(final String href) {
67          getDomNodeOrDie().setAttribute("href", href);
68      }
69  
70      /**
71       * Returns the value of the {@code target} property.
72       * @return the value of the {@code target} property
73       */
74      @JsxGetter
75      public String getTarget() {
76          return getDomNodeOrDie().getAttribute("target");
77      }
78  
79      /**
80       * Sets the value of the {@code target} property.
81       * @param target the value of the {@code target} property
82       */
83      @JsxSetter
84      public void setTarget(final String target) {
85          getDomNodeOrDie().setAttribute("target", target);
86      }
87  
88      /**
89       * {@inheritDoc}
90       */
91      @Override
92      protected boolean isEndTagForbidden() {
93          return true;
94      }
95  }