View Javadoc
1   /*
2    * Copyright (c) 2002-2026 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 static org.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_DETECT_WIN_DRIVES_URL_REPLACE;
18  import static org.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_PREFIX_WIN_DRIVES_URL;
19  import static org.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PROTOCOL_COLON_UPPER_CASE_DRIVE_LETTERS;
20  import static org.htmlunit.html.DomElement.ATTRIBUTE_NOT_DEFINED;
21  
22  import java.net.MalformedURLException;
23  import java.net.URL;
24  import java.util.Arrays;
25  import java.util.List;
26  import java.util.Locale;
27  
28  import org.htmlunit.BrowserVersion;
29  import org.htmlunit.HttpHeader;
30  import org.htmlunit.SgmlPage;
31  import org.htmlunit.html.DomElement;
32  import org.htmlunit.html.DomNode;
33  import org.htmlunit.html.HtmlAnchor;
34  import org.htmlunit.html.HtmlElement;
35  import org.htmlunit.html.HtmlPage;
36  import org.htmlunit.javascript.JavaScriptEngine;
37  import org.htmlunit.javascript.configuration.JsxClass;
38  import org.htmlunit.javascript.configuration.JsxConstructor;
39  import org.htmlunit.javascript.configuration.JsxGetter;
40  import org.htmlunit.javascript.configuration.JsxSetter;
41  import org.htmlunit.javascript.host.dom.DOMTokenList;
42  import org.htmlunit.util.StringUtils;
43  import org.htmlunit.util.UrlUtils;
44  
45  /**
46   * The JavaScript object that represents an anchor.
47   *
48   * @author Mike Bowler
49   * @author Alexei Goussev
50   * @author David D. Kilzer
51   * @author Marc Guillemot
52   * @author Chris Erskine
53   * @author Ahmed Ashour
54   * @author Sudhan Moghe
55   * @author Daniel Gredler
56   * @author Ronald Brill
57   * @author Lai Quang Duong
58   *
59   * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement">MDN Documentation</a>
60   */
61  @JsxClass(domClass = HtmlAnchor.class)
62  public class HTMLAnchorElement extends HTMLElement {
63      private static final List<String> REFERRER_POLICIES = Arrays.asList(
64                                          "no-referrer", HttpHeader.ORIGIN_LC, "unsafe-url");
65  
66      /**
67       * JavaScript constructor.
68       */
69      @Override
70      @JsxConstructor
71      public void jsConstructor() {
72          super.jsConstructor();
73      }
74  
75      /**
76       * Sets the {@code href} property.
77       * @param href the {@code href} property value
78       */
79      @JsxSetter
80      public void setHref(final String href) {
81          getDomNodeOrDie().setAttribute("href", href);
82      }
83  
84      /**
85       * Returns the value of this link's {@code href} property.
86       * @return the value of this link's {@code href} property
87       */
88      @JsxGetter
89      public String getHref() {
90          final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie();
91          final String hrefAttr = anchor.getHrefAttribute();
92  
93          if (ATTRIBUTE_NOT_DEFINED == hrefAttr) {
94              return "";
95          }
96  
97          try {
98              return getUrl().toString();
99          }
100         catch (final MalformedURLException e) {
101             return hrefAttr;
102         }
103     }
104 
105     /**
106      * Sets the focus to this element.
107      */
108     @Override
109     public void focus() {
110         final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie();
111         final String hrefAttr = anchor.getHrefAttribute();
112 
113         if (ATTRIBUTE_NOT_DEFINED != hrefAttr) {
114             anchor.focus();
115         }
116     }
117 
118     /**
119      * Sets the {@code name} property.
120      * @param name the {@code name} property value
121      */
122     @JsxSetter
123     @Override
124     public void setName(final String name) {
125         getDomNodeOrDie().setAttribute(DomElement.NAME_ATTRIBUTE, name);
126     }
127 
128     /**
129      * Returns the value of this link's {@code name} property.
130      * @return the value of this link's {@code name} property
131      */
132     @JsxGetter
133     @Override
134     public String getName() {
135         return getDomNodeOrDie().getAttributeDirect(DomElement.NAME_ATTRIBUTE);
136     }
137 
138     /**
139      * Sets the {@code target} property of this link.
140      * @param target the {@code target} property value
141      */
142     @JsxSetter
143     public void setTarget(final String target) {
144         getDomNodeOrDie().setAttribute("target", target);
145     }
146 
147     /**
148      * Returns the value of this link's {@code target} property.
149      * @return the value of this link's {@code target} property
150      */
151     @JsxGetter
152     public String getTarget() {
153         return getDomNodeOrDie().getAttributeDirect("target");
154     }
155 
156     /**
157      * Returns this link's current URL.
158      * @return this link's current URL
159      * @throws MalformedURLException if an error occurs
160      */
161     private URL getUrl() throws MalformedURLException {
162         final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie();
163         return ((HtmlPage) anchor.getPage()).getFullyQualifiedUrl(anchor.getHrefAttribute());
164     }
165 
166     /**
167      * Sets the {@code href} attribute of this link to the specified URL.
168      * @param url the new value of the {@code href} attribute
169      */
170     private void setUrl(final URL url) {
171         getDomNodeOrDie().setAttribute("href", url.toString());
172     }
173 
174     /**
175      * Sets the {@code rel} property.
176      * @param rel the {@code rel} property value
177      */
178     @JsxSetter
179     public void setRel(final String rel) {
180         getDomNodeOrDie().setAttribute("rel", rel);
181     }
182 
183     /**
184      * Returns the value of this link's {@code rel} property.
185      * @return the value of this link's {@code rel} property
186      */
187     @JsxGetter
188     public String getRel() {
189         return ((HtmlAnchor) getDomNodeOrDie()).getRelAttribute();
190     }
191 
192     /**
193      * Returns the value of this link's {@code rev} property.
194      * @return the value of this link's {@code rev} property
195      */
196     @JsxGetter
197     public String getRev() {
198         return ((HtmlAnchor) getDomNodeOrDie()).getRevAttribute();
199     }
200 
201     /**
202      * Sets the {@code rev} property.
203      * @param rel the {@code rev} property value
204      */
205     @JsxSetter
206     public void setRev(final String rel) {
207         getDomNodeOrDie().setAttribute("rev", rel);
208     }
209 
210     /**
211      * Returns the value of this link's {@code referrerPolicy} property.
212      * @return the value of this link's {@code referrerPolicy} property
213      */
214     @JsxGetter
215     public String getReferrerPolicy() {
216         String attrib = getDomNodeOrDie().getAttribute("referrerPolicy");
217         if (StringUtils.isEmptyOrNull(attrib)) {
218             return "";
219         }
220         attrib = attrib.toLowerCase(Locale.ROOT);
221         if (REFERRER_POLICIES.contains(attrib)) {
222             return attrib;
223         }
224         return "";
225     }
226 
227     /**
228      * Sets the {@code referrerPolicy} property.
229      * @param referrerPolicy the {@code referrerPolicy} property value
230      */
231     @JsxSetter
232     public void setReferrerPolicy(final String referrerPolicy) {
233         getDomNodeOrDie().setAttribute("referrerPolicy", referrerPolicy);
234     }
235 
236     /**
237      * Returns the search portion of the link's URL (the portion starting with
238      * '?' and up to but not including any '#').
239      * @return the search portion of the link's URL
240      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/search">MDN Documentation</a>
241      */
242     @JsxGetter
243     public String getSearch() {
244         try {
245             return HTMLHyperlinkElementUtils.getSearch(getUrl());
246         }
247         catch (final MalformedURLException e) {
248             return "";
249         }
250     }
251 
252     /**
253      * Sets the search portion of the link's URL (the portion starting with '?'
254      * and up to but not including any '#').
255      * @param search the new search portion of the link's URL
256      * @throws Exception if an error occurs
257      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/search">MDN Documentation</a>
258      */
259     @JsxSetter
260     public void setSearch(final String search) throws Exception {
261         setUrl(HTMLHyperlinkElementUtils.setSearch(getUrl(), search));
262     }
263 
264     /**
265      * Returns the hash portion of the link's URL (the portion following the '#', including the '#').
266      * @return the hash portion of the link's URL
267      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/hash">MDN Documentation</a>
268      */
269     @JsxGetter
270     public String getHash() {
271         try {
272             return HTMLHyperlinkElementUtils.getHash(getUrl());
273         }
274         catch (final MalformedURLException e) {
275             return "";
276         }
277     }
278 
279     /**
280      * Sets the hash portion of the link's URL (the portion following the '#').
281      * @param hash the new hash portion of the link's URL
282      * @throws Exception if an error occurs
283      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/hash">MDN Documentation</a>
284      */
285     @JsxSetter
286     public void setHash(final String hash) throws Exception {
287         setUrl(HTMLHyperlinkElementUtils.setHash(getUrl(), hash));
288     }
289 
290     /**
291      * Returns the host portion of the link's URL (the '[hostname]:[port]' portion).
292      * @return the host portion of the link's URL
293      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/host">MDN Documentation</a>
294      */
295     @JsxGetter
296     public String getHost() {
297         try {
298             final URL url = getUrl();
299             final int port = url.getPort();
300             final String host = url.getHost();
301 
302             if (port == -1 || HTMLHyperlinkElementUtils.isDefaultPort(url.getProtocol(), port)) {
303                 return host;
304             }
305             return host + ":" + port;
306         }
307         catch (final MalformedURLException e) {
308             return "";
309         }
310     }
311 
312     /**
313      * Sets the host portion of the link's URL (the '[hostname]:[port]' portion).
314      * @param host the new host portion of the link's URL
315      * @throws Exception if an error occurs
316      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/host">MDN Documentation</a>
317      */
318     @JsxSetter
319     public void setHost(final String host) throws Exception {
320         setUrl(HTMLHyperlinkElementUtils.setHost(getUrl(), host));
321     }
322 
323     /**
324      * Returns the hostname portion of the link's URL.
325      * @return the hostname portion of the link's URL
326      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/hostname">MDN Documentation</a>
327      */
328     @JsxGetter
329     public String getHostname() {
330         try {
331             return HTMLHyperlinkElementUtils.getHostname(getUrl());
332         }
333         catch (final MalformedURLException e) {
334             return "";
335         }
336     }
337 
338     /**
339      * Sets the hostname portion of the link's URL.
340      * @param hostname the new hostname portion of the link's URL
341      * @throws Exception if an error occurs
342      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/hostname">MDN Documentation</a>
343      */
344     @JsxSetter
345     public void setHostname(final String hostname) throws Exception {
346         if (org.htmlunit.util.StringUtils.isEmptyOrNull(hostname) || hostname.indexOf(' ') > -1) {
347             return;
348         }
349 
350         final int idx = hostname.indexOf('#');
351         final String host = idx > -1 ? hostname.substring(0, idx) : hostname;
352         if (host.isEmpty()) {
353             return;
354         }
355 
356         try {
357             setUrl(UrlUtils.getUrlWithNewHost(getUrl(), host));
358         }
359         catch (final MalformedURLException  e) {
360             // do nothing
361         }
362     }
363 
364     /**
365      * Returns the pathname portion of the link's URL.
366      * @return the pathname portion of the link's URL
367      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/pathname">MDN Documentation</a>
368      */
369     @JsxGetter
370     public String getPathname() {
371         final BrowserVersion browser = getBrowserVersion();
372         try {
373             if (browser.hasFeature(JS_ANCHOR_PATHNAME_DETECT_WIN_DRIVES_URL_REPLACE)) {
374                 final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie();
375                 String href = anchor.getHrefAttribute();
376                 if (href.length() > 1 && Character.isLetter(href.charAt(0)) && ':' == href.charAt(1)) {
377                     if (browser.hasFeature(JS_ANCHOR_PROTOCOL_COLON_UPPER_CASE_DRIVE_LETTERS)) {
378                         href = org.apache.commons.lang3.StringUtils.capitalize(href);
379                     }
380                     if (browser.hasFeature(JS_ANCHOR_PATHNAME_PREFIX_WIN_DRIVES_URL)) {
381                         href = "/" + href;
382                     }
383                     return href;
384                 }
385             }
386             return getUrl().getPath();
387         }
388         catch (final MalformedURLException e) {
389             final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie();
390             if (anchor.getHrefAttribute().startsWith("http")) {
391                 return "";
392             }
393             return "/";
394         }
395     }
396 
397     /**
398      * Sets the pathname portion of the link's URL.
399      * @param pathname the new pathname portion of the link's URL
400      * @throws Exception if an error occurs
401      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/pathname">MDN Documentation</a>
402      */
403     @JsxSetter
404     public void setPathname(final String pathname) throws Exception {
405         setUrl(HTMLHyperlinkElementUtils.setPathname(getUrl(), pathname));
406     }
407 
408     /**
409      * Returns the port portion of the link's URL.
410      * @return the port portion of the link's URL
411      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/port">MDN Documentation</a>
412      */
413     @JsxGetter
414     public String getPort() {
415         try {
416             final URL url = getUrl();
417             final int port = url.getPort();
418             if (port == -1 || HTMLHyperlinkElementUtils.isDefaultPort(url.getProtocol(), port)) {
419                 return "";
420             }
421             return Integer.toString(port);
422         }
423         catch (final MalformedURLException e) {
424             return "";
425         }
426     }
427 
428     /**
429      * Sets the port portion of the link's URL.
430      * @param port the new port portion of the link's URL
431      * @throws Exception if an error occurs
432      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/port">MDN Documentation</a>
433      */
434     @JsxSetter
435     public void setPort(final String port) throws Exception {
436         final URL url = getUrl();
437         final int newPort = Integer.parseInt(port);
438         if (HTMLHyperlinkElementUtils.isDefaultPort(url.getProtocol(), newPort)) {
439             setUrl(UrlUtils.getUrlWithNewPort(url, -1));
440         }
441         else {
442             setUrl(UrlUtils.getUrlWithNewPort(url, newPort));
443         }
444     }
445 
446     /**
447      * Returns the protocol portion of the link's URL, including the trailing ':'.
448      * @return the protocol portion of the link's URL, including the trailing ':'
449      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/protocol">MDN Documentation</a>
450      */
451     @JsxGetter
452     public String getProtocol() {
453         final BrowserVersion browser = getBrowserVersion();
454         try {
455             if (browser.hasFeature(JS_ANCHOR_PATHNAME_DETECT_WIN_DRIVES_URL_REPLACE)) {
456                 final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie();
457                 final String href = anchor.getHrefAttribute().toLowerCase(Locale.ROOT);
458                 if (href.length() > 1 && Character.isLetter(href.charAt(0)) && ':' == href.charAt(1)) {
459                     return "file:";
460                 }
461             }
462 
463             return getUrl().getProtocol() + ":";
464         }
465         catch (final MalformedURLException e) {
466             final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie();
467             if (anchor.getHrefAttribute().startsWith("http")) {
468                 return ":";
469             }
470             return StringUtils.substringBefore(anchor.getHrefAttribute(), "/");
471         }
472     }
473 
474     /**
475      * Sets the protocol portion of the link's URL.
476      * @param protocol the new protocol portion of the link's URL
477      * @throws Exception if an error occurs
478      * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/protocol">MDN Documentation</a>
479      */
480     @JsxSetter
481     public void setProtocol(final String protocol) throws Exception {
482         final URL result = HTMLHyperlinkElementUtils.setProtocol(getUrl(), protocol);
483         if (result != null) {
484             setUrl(result);
485         }
486     }
487 
488     /**
489      * Called, for instance, for implicit conversion to a string.
490      * @see org.htmlunit.javascript.HtmlUnitScriptable#getDefaultValue(java.lang.Class)
491      * @param hint the type hint
492      * @return the default value
493      */
494     @Override
495     public Object getDefaultValue(final Class<?> hint) {
496         final HtmlElement element = getDomNodeOrNull();
497         if (element == null) {
498             return super.getDefaultValue(null);
499         }
500         return getDefaultValue(element);
501     }
502 
503     static String getDefaultValue(final HtmlElement element) {
504         String href = element.getAttributeDirect("href");
505 
506         if (ATTRIBUTE_NOT_DEFINED == href) {
507             return ""; // for example for named anchors
508         }
509 
510         href = href.trim();
511 
512         final SgmlPage page = element.getPage();
513         if (page == null || !page.isHtmlPage()) {
514             return href;
515         }
516 
517         try {
518             return HtmlAnchor.getTargetUrl(href, (HtmlPage) page).toExternalForm();
519         }
520         catch (final MalformedURLException e) {
521             return href;
522         }
523     }
524 
525     /**
526      * Returns the {@code text} attribute.
527      * @return the {@code text} attribute
528      */
529     @JsxGetter
530     public String getText() {
531         final DomNode htmlElement = getDomNodeOrDie();
532         return htmlElement.asNormalizedText();
533     }
534 
535     /**
536      * Sets the {@code text} attribute.
537      * @param text the {@code text} attribute
538      */
539     @JsxSetter
540     public void setText(final String text) {
541         final DomNode htmlElement = getDomNodeOrDie();
542         htmlElement.setTextContent(text);
543     }
544 
545     /**
546      * Returns the {@code charset} attribute.
547      * @return the {@code charset} attribute
548      */
549     @JsxGetter
550     public String getCharset() {
551         return getDomNodeOrDie().getAttributeDirect("charset");
552     }
553 
554     /**
555      * Sets the {@code charset} attribute.
556      * @param charset the {@code charset} attribute
557      */
558     @JsxSetter
559     public void setCharset(final String charset) {
560         getDomNodeOrDie().setAttribute("charset", charset);
561     }
562 
563     /**
564      * Returns the {@code coords} attribute.
565      * @return the {@code coords} attribute
566      */
567     @JsxGetter
568     public String getCoords() {
569         return getDomNodeOrDie().getAttributeDirect("coords");
570     }
571 
572     /**
573      * Sets the {@code coords} attribute.
574      * @param coords the {@code coords} attribute value
575      */
576     @JsxSetter
577     public void setCoords(final String coords) {
578         getDomNodeOrDie().setAttribute("coords", coords);
579     }
580 
581     /**
582      * Returns the {@code hreflang} attribute.
583      * @return the {@code hreflang} attribute
584      */
585     @JsxGetter
586     public String getHreflang() {
587         return getDomNodeOrDie().getAttributeDirect("hreflang");
588     }
589 
590     /**
591      * Sets the {@code hreflang} attribute.
592      * @param hreflang the {@code hreflang} attribute value
593      */
594     @JsxSetter
595     public void setHreflang(final String hreflang) {
596         getDomNodeOrDie().setAttribute("hreflang", hreflang);
597     }
598 
599     /**
600      * Returns the {@code origin} attribute.
601      * @return the {@code origin} attribute
602      */
603     @JsxGetter
604     public String getOrigin() {
605         if (!getDomNodeOrDie().hasAttribute("href")) {
606             return "";
607         }
608 
609         try {
610             return getUrl().getProtocol() + "://" + getHost();
611         }
612         catch (final Exception e) {
613             return "";
614         }
615     }
616 
617     /**
618      * Returns the {@code username} attribute.
619      * @return the {@code username} attribute
620      */
621     @JsxGetter
622     public String getUsername() {
623         try {
624             return HTMLHyperlinkElementUtils.getUsername(getUrl());
625         }
626         catch (final MalformedURLException e) {
627             return "";
628         }
629     }
630 
631     /**
632      * Sets the {@code username} attribute.
633      * @param username the {@code username} attribute value
634      */
635     @JsxSetter
636     public void setUsername(final String username) {
637         try {
638             final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie();
639             final String href = anchor.getHrefAttribute();
640             if (ATTRIBUTE_NOT_DEFINED == href) {
641                 return;
642             }
643 
644             final URL url = ((HtmlPage) anchor.getPage()).getFullyQualifiedUrl(href);
645             setUrl(UrlUtils.getUrlWithNewUserName(url, username));
646         }
647         catch (final MalformedURLException ignored) {
648             // ignore
649         }
650     }
651 
652     /**
653      * Returns the {@code password} attribute.
654      * @return the {@code password} attribute
655      */
656     @JsxGetter
657     public String getPassword() {
658         try {
659             return HTMLHyperlinkElementUtils.getPassword(getUrl());
660         }
661         catch (final MalformedURLException e) {
662             return "";
663         }
664     }
665 
666     /**
667      * Sets the {@code password} attribute.
668      * @param password the {@code password} attribute value
669      */
670     @JsxSetter
671     public void setPassword(final String password) {
672         try {
673             final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie();
674             final String href = anchor.getHrefAttribute();
675             if (ATTRIBUTE_NOT_DEFINED == href) {
676                 return;
677             }
678 
679             final URL url = ((HtmlPage) anchor.getPage()).getFullyQualifiedUrl(href);
680             setUrl(UrlUtils.getUrlWithNewUserPassword(url, password));
681         }
682         catch (final MalformedURLException ignored) {
683             // ignore
684         }
685     }
686 
687     /**
688      * Returns the {@code download} attribute.
689      * @return the {@code download} attribute
690      */
691     @JsxGetter
692     public String getDownload() {
693         return ((HtmlAnchor) getDomNodeOrDie()).getDownloadAttribute();
694     }
695 
696     /**
697      * Sets the {@code download} attribute.
698      * @param download the {@code download} attribute value
699      */
700     @JsxSetter
701     public void setDownload(final String download) {
702         getDomNodeOrDie().setAttribute("download", download);
703     }
704 
705     /**
706      * Returns the {@code ping} attribute.
707      * @return the {@code ping} attribute
708      */
709     @JsxGetter
710     public String getPing() {
711         return ((HtmlAnchor) getDomNodeOrDie()).getPingAttribute();
712     }
713 
714     /**
715      * Sets the {@code ping} attribute.
716      * @param ping the {@code ping} attribute value
717      */
718     @JsxSetter
719     public void setPing(final String ping) {
720         getDomNodeOrDie().setAttribute("ping", ping);
721     }
722 
723     /**
724      * Returns the {@code shape} attribute.
725      * @return the {@code shape} attribute
726      */
727     @JsxGetter
728     public String getShape() {
729         return getDomNodeOrDie().getAttribute("shape");
730     }
731 
732     /**
733      * Sets the {@code shape} attribute.
734      * @param shape the {@code shape} attribute value
735      */
736     @JsxSetter
737     public void setShape(final String shape) {
738         getDomNodeOrDie().setAttribute("shape", shape);
739     }
740 
741     /**
742      * Returns the {@code type} attribute.
743      * @return the {@code type} attribute
744      */
745     @JsxGetter
746     public String getType() {
747         return getDomNodeOrDie().getAttributeDirect(DomElement.TYPE_ATTRIBUTE);
748     }
749 
750     /**
751      * Sets the {@code type} attribute.
752      * @param type the {@code type} attribute value
753      */
754     @JsxSetter
755     public void setType(final String type) {
756         getDomNodeOrDie().setAttribute(DomElement.TYPE_ATTRIBUTE, type);
757     }
758 
759     /**
760      * Returns the {@code relList} attribute.
761      * @return the {@code relList} attribute
762      */
763     @JsxGetter
764     public DOMTokenList getRelList() {
765         return new DOMTokenList(this, "rel");
766     }
767 
768     /**
769      * Sets the {@code relList} attribute.
770      * @param rel the {@code relList} attribute value
771      */
772     @JsxSetter
773     public void setRelList(final Object rel) {
774         setRel(JavaScriptEngine.toString(rel));
775     }
776 }