001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.bean.html5;
018
019import java.net.*;
020
021import org.apache.juneau.*;
022import org.apache.juneau.annotation.*;
023import org.apache.juneau.internal.*;
024
025/**
026 * DTO for an HTML <a class="doclink" href="https://www.w3.org/TR/html5/document-metadata.html#the-link-element">&lt;link&gt;</a>
027 * element.
028 *
029 * <p>
030 * The link element specifies relationships between the current document and an external resource.
031 * It is most commonly used to link to stylesheets, but can also be used to establish site icons,
032 * prefetch resources, define alternate versions of the document, and more. Link elements are typically
033 * placed in the head section of an HTML document.
034 *
035 * <h5 class='section'>Examples:</h5>
036 * <p class='bcode w800'>
037 *    <jc>// Stylesheet link</jc>
038 *    Link <jv>stylesheet</jv> = <jsm>link</jsm>()
039 *       .rel(<js>"stylesheet"</js>)
040 *       .href(<js>"/css/styles.css"</js>);
041 * 
042 *    <jc>// Favicon link</jc>
043 *    Link <jv>favicon</jv> = <jsm>link</jsm>()
044 *       .rel(<js>"icon"</js>)
045 *       .type(<js>"image/x-icon"</js>)
046 *       .href(<js>"/favicon.ico"</js>);
047 * 
048 *    <jc>// Preload resource</jc>
049 *    Link <jv>preload</jv> = <jsm>link</jsm>()
050 *       .rel(<js>"preload"</js>)
051 *       .href(<js>"/fonts/myfont.woff2"</js>)
052 *       ._as(<js>"font"</js>)
053 *       .type(<js>"font/woff2"</js>)
054 *       .crossorigin(<js>"anonymous"</js>);
055 * 
056 *    <jc>// Alternate language version</jc>
057 *    Link <jv>alternate</jv> = <jsm>link</jsm>()
058 *       .rel(<js>"alternate"</js>)
059 *       .href(<js>"/es/page.html"</js>)
060 *       .hreflang(<js>"es"</js>);
061 * 
062 *    <jc>// Responsive stylesheet with media query</jc>
063 *    Link <jv>print</jv> = <jsm>link</jsm>()
064 *       .rel(<js>"stylesheet"</js>)
065 *       .href(<js>"/css/print.css"</js>)
066 *       .media(<js>"print"</js>);
067 * 
068 *    <jc>// Canonical URL for SEO</jc>
069 *    Link <jv>canonical</jv> = <jsm>link</jsm>()
070 *       .rel(<js>"canonical"</js>)
071 *       .href(<js>"https://example.com/page"</js>);
072 * 
073 *    <jc>// DNS prefetch for performance</jc>
074 *    Link <jv>dnsPrefetch</jv> = <jsm>link</jsm>()
075 *       .rel(<js>"dns-prefetch"</js>)
076 *       .href(<js>"https://cdn.example.com"</js>);
077 * </p>
078 *
079 * <p>
080 * The following convenience methods are provided for constructing instances of this bean:
081 * <ul class='javatree'>
082 *    <li class='jc'>{@link HtmlBuilder}
083 *    <ul class='javatree'>
084 *       <li class='jm'>{@link HtmlBuilder#link() link()}
085 *    </ul>
086 * </ul>
087 * </p>
088 *
089 * <h5 class='section'>See Also:</h5><ul>
090 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a>
091 * </ul>
092 */
093@Bean(typeName="link")
094public class Link extends HtmlElementVoid {
095
096   /**
097    * Creates an empty {@link Link} element.
098    */
099   public Link() {}
100
101   /**
102    * Creates a {@link Link} element with the specified {@link Link#href(Object)} attribute.
103    *
104    * @param href The {@link Link#href(Object)} attribute.
105    */
106   public Link(Object href) {
107      href(href);
108   }
109
110   /**
111    * <a class="doclink" href="https://www.w3.org/TR/html5/document-metadata.html#attr-link-crossorigin">crossorigin</a>
112    * attribute.
113    *
114    * <p>
115    * Specifies how the element handles cross-origin requests for CORS (Cross-Origin Resource Sharing).
116    *
117    * <p>
118    * Possible values:
119    * <ul>
120    *    <li><js>"anonymous"</js> - Cross-origin requests are made without credentials</li>
121    *    <li><js>"use-credentials"</js> - Cross-origin requests include credentials</li>
122    * </ul>
123    *
124    * @param crossorigin How to handle cross-origin requests.
125    * @return This object.
126    */
127   public Link crossorigin(String value) {
128      attr("crossorigin", value);
129      return this;
130   }
131
132   /**
133    * <a class="doclink" href="https://www.w3.org/TR/html5/document-metadata.html#attr-link-href">href</a> attribute.
134    *
135    * <p>
136    * Address of the hyperlink.
137    *
138    * <p>
139    * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
140    * Strings must be valid URIs.
141    *
142    * <p>
143    * URIs defined by {@link UriResolver} can be used for values.
144    *
145    * @param href
146    *    The new value for this attribute.
147    *    Typically a {@link URL} or {@link String}.
148    * @return This object.
149    */
150   public Link href(Object value) {
151      attrUri("href", value);
152      return this;
153   }
154
155   /**
156    * <a class="doclink" href="https://www.w3.org/TR/html5/document-metadata.html#attr-link-hreflang">hreflang</a>
157    * attribute.
158    *
159    * <p>
160    * Specifies the language of the linked resource. Used for SEO and accessibility purposes.
161    *
162    * <p>
163    * Examples:
164    * <ul>
165    *    <li><js>"en"</js> - English</li>
166    *    <li><js>"es"</js> - Spanish</li>
167    *    <li><js>"fr"</js> - French</li>
168    *    <li><js>"de"</js> - German</li>
169    *    <li><js>"zh"</js> - Chinese</li>
170    *    <li><js>"ja"</js> - Japanese</li>
171    * </ul>
172    *
173    * @param hreflang The language code of the linked resource.
174    * @return This object.
175    */
176   public Link hreflang(String value) {
177      attr("hreflang", value);
178      return this;
179   }
180
181   /**
182    * <a class="doclink" href="https://www.w3.org/TR/html5/document-metadata.html#attr-link-media">media</a> attribute.
183    *
184    * <p>
185    * Specifies which media types the linked resource applies to. Used primarily with stylesheets.
186    *
187    * <p>
188    * Common values:
189    * <ul>
190    *    <li><js>"all"</js> - All media types (default)</li>
191    *    <li><js>"screen"</js> - Computer screens</li>
192    *    <li><js>"print"</js> - Printers and print preview</li>
193    *    <li><js>"handheld"</js> - Handheld devices</li>
194    *    <li><js>"projection"</js> - Projectors</li>
195    *    <li><js>"(max-width: 768px)"</js> - Media queries</li>
196    * </ul>
197    *
198    * @param media The media types the linked resource applies to.
199    * @return This object.
200    */
201   public Link media(String value) {
202      attr("media", value);
203      return this;
204   }
205
206   /**
207    * <a class="doclink" href="https://www.w3.org/TR/html5/document-metadata.html#attr-link-rel">rel</a> attribute.
208    *
209    * <p>
210    * Specifies the relationship between the current document and the linked resource.
211    *
212    * <p>
213    * Common values:
214    * <ul>
215    *    <li><js>"stylesheet"</js> - External CSS stylesheet</li>
216    *    <li><js>"icon"</js> - Favicon or site icon</li>
217    *    <li><js>"canonical"</js> - Canonical URL for SEO</li>
218    *    <li><js>"alternate"</js> - Alternative version of the page</li>
219    *    <li><js>"preload"</js> - Resource to preload</li>
220    *    <li><js>"prefetch"</js> - Resource to prefetch</li>
221    *    <li><js>"dns-prefetch"</js> - DNS lookup to prefetch</li>
222    *    <li><js>"next"</js> - Next page in a sequence</li>
223    *    <li><js>"prev"</js> - Previous page in a sequence</li>
224    * </ul>
225    *
226    * @param rel The relationship between the document and linked resource.
227    * @return This object.
228    */
229   public Link rel(String value) {
230      attr("rel", value);
231      return this;
232   }
233
234   /**
235    * <a class="doclink" href="https://www.w3.org/TR/html5/links.html#attr-link-sizes">sizes</a> attribute.
236    *
237    * <p>
238    * Specifies the sizes of icons for different device contexts. Used with <c>rel="icon"</c> or <c>rel="apple-touch-icon"</c>.
239    *
240    * <p>
241    * Common values:
242    * <ul>
243    *    <li><js>"16x16"</js> - Small favicon</li>
244    *    <li><js>"32x32"</js> - Standard favicon</li>
245    *    <li><js>"180x180"</js> - Apple touch icon</li>
246    *    <li><js>"192x192"</js> - Android icon</li>
247    *    <li><js>"512x512"</js> - Large icon</li>
248    *    <li><js>"any"</js> - Any size</li>
249    * </ul>
250    *
251    * @param sizes The sizes of the linked icon resource.
252    * @return This object.
253    */
254   public Link sizes(String value) {
255      attr("sizes", value);
256      return this;
257   }
258
259   /**
260    * <a class="doclink" href="https://www.w3.org/TR/html5/document-metadata.html#attr-link-type">type</a> attribute.
261    *
262    * <p>
263    * Specifies the MIME type of the linked resource. Helps browsers determine how to handle the resource.
264    *
265    * <p>
266    * Common values:
267    * <ul>
268    *    <li><js>"text/css"</js> - CSS stylesheet</li>
269    *    <li><js>"text/javascript"</js> - JavaScript file</li>
270    *    <li><js>"application/json"</js> - JSON data</li>
271    *    <li><js>"image/png"</js> - PNG image</li>
272    *    <li><js>"image/jpeg"</js> - JPEG image</li>
273    *    <li><js>"image/svg+xml"</js> - SVG image</li>
274    *    <li><js>"font/woff2"</js> - Web font</li>
275    * </ul>
276    *
277    * @param type The MIME type of the linked resource.
278    * @return This object.
279    */
280   public Link type(String value) {
281      attr("type", value);
282      return this;
283   }
284
285   //-----------------------------------------------------------------------------------------------------------------
286   // Overridden methods
287   //-----------------------------------------------------------------------------------------------------------------
288   @Override /* Overridden from HtmlElement */
289   public Link _class(String value) {  // NOSONAR - Intentional naming.
290      super._class(value);
291      return this;
292   }
293
294   @Override /* Overridden from HtmlElement */
295   public Link accesskey(String value) {
296      super.accesskey(value);
297      return this;
298   }
299
300   @Override /* Overridden from HtmlElement */
301   public Link contenteditable(Object value) {
302      super.contenteditable(value);
303      return this;
304   }
305
306   @Override /* Overridden from HtmlElement */
307   public Link dir(String value) {
308      super.dir(value);
309      return this;
310   }
311
312   @Override /* Overridden from HtmlElement */
313   public Link hidden(Object value) {
314      super.hidden(value);
315      return this;
316   }
317
318   @Override /* Overridden from HtmlElement */
319   public Link id(String value) {
320      super.id(value);
321      return this;
322   }
323
324   @Override /* Overridden from HtmlElement */
325   public Link lang(String value) {
326      super.lang(value);
327      return this;
328   }
329
330   @Override /* Overridden from HtmlElement */
331   public Link onabort(String value) {
332      super.onabort(value);
333      return this;
334   }
335
336   @Override /* Overridden from HtmlElement */
337   public Link onblur(String value) {
338      super.onblur(value);
339      return this;
340   }
341
342   @Override /* Overridden from HtmlElement */
343   public Link oncancel(String value) {
344      super.oncancel(value);
345      return this;
346   }
347
348   @Override /* Overridden from HtmlElement */
349   public Link oncanplay(String value) {
350      super.oncanplay(value);
351      return this;
352   }
353
354   @Override /* Overridden from HtmlElement */
355   public Link oncanplaythrough(String value) {
356      super.oncanplaythrough(value);
357      return this;
358   }
359
360   @Override /* Overridden from HtmlElement */
361   public Link onchange(String value) {
362      super.onchange(value);
363      return this;
364   }
365
366   @Override /* Overridden from HtmlElement */
367   public Link onclick(String value) {
368      super.onclick(value);
369      return this;
370   }
371
372   @Override /* Overridden from HtmlElement */
373   public Link oncuechange(String value) {
374      super.oncuechange(value);
375      return this;
376   }
377
378   @Override /* Overridden from HtmlElement */
379   public Link ondblclick(String value) {
380      super.ondblclick(value);
381      return this;
382   }
383
384   @Override /* Overridden from HtmlElement */
385   public Link ondurationchange(String value) {
386      super.ondurationchange(value);
387      return this;
388   }
389
390   @Override /* Overridden from HtmlElement */
391   public Link onemptied(String value) {
392      super.onemptied(value);
393      return this;
394   }
395
396   @Override /* Overridden from HtmlElement */
397   public Link onended(String value) {
398      super.onended(value);
399      return this;
400   }
401
402   @Override /* Overridden from HtmlElement */
403   public Link onerror(String value) {
404      super.onerror(value);
405      return this;
406   }
407
408   @Override /* Overridden from HtmlElement */
409   public Link onfocus(String value) {
410      super.onfocus(value);
411      return this;
412   }
413
414   @Override /* Overridden from HtmlElement */
415   public Link oninput(String value) {
416      super.oninput(value);
417      return this;
418   }
419
420   @Override /* Overridden from HtmlElement */
421   public Link oninvalid(String value) {
422      super.oninvalid(value);
423      return this;
424   }
425
426   @Override /* Overridden from HtmlElement */
427   public Link onkeydown(String value) {
428      super.onkeydown(value);
429      return this;
430   }
431
432   @Override /* Overridden from HtmlElement */
433   public Link onkeypress(String value) {
434      super.onkeypress(value);
435      return this;
436   }
437
438   @Override /* Overridden from HtmlElement */
439   public Link onkeyup(String value) {
440      super.onkeyup(value);
441      return this;
442   }
443
444   @Override /* Overridden from HtmlElement */
445   public Link onload(String value) {
446      super.onload(value);
447      return this;
448   }
449
450   @Override /* Overridden from HtmlElement */
451   public Link onloadeddata(String value) {
452      super.onloadeddata(value);
453      return this;
454   }
455
456   @Override /* Overridden from HtmlElement */
457   public Link onloadedmetadata(String value) {
458      super.onloadedmetadata(value);
459      return this;
460   }
461
462   @Override /* Overridden from HtmlElement */
463   public Link onloadstart(String value) {
464      super.onloadstart(value);
465      return this;
466   }
467
468   @Override /* Overridden from HtmlElement */
469   public Link onmousedown(String value) {
470      super.onmousedown(value);
471      return this;
472   }
473
474   @Override /* Overridden from HtmlElement */
475   public Link onmouseenter(String value) {
476      super.onmouseenter(value);
477      return this;
478   }
479
480   @Override /* Overridden from HtmlElement */
481   public Link onmouseleave(String value) {
482      super.onmouseleave(value);
483      return this;
484   }
485
486   @Override /* Overridden from HtmlElement */
487   public Link onmousemove(String value) {
488      super.onmousemove(value);
489      return this;
490   }
491
492   @Override /* Overridden from HtmlElement */
493   public Link onmouseout(String value) {
494      super.onmouseout(value);
495      return this;
496   }
497
498   @Override /* Overridden from HtmlElement */
499   public Link onmouseover(String value) {
500      super.onmouseover(value);
501      return this;
502   }
503
504   @Override /* Overridden from HtmlElement */
505   public Link onmouseup(String value) {
506      super.onmouseup(value);
507      return this;
508   }
509
510   @Override /* Overridden from HtmlElement */
511   public Link onmousewheel(String value) {
512      super.onmousewheel(value);
513      return this;
514   }
515
516   @Override /* Overridden from HtmlElement */
517   public Link onpause(String value) {
518      super.onpause(value);
519      return this;
520   }
521
522   @Override /* Overridden from HtmlElement */
523   public Link onplay(String value) {
524      super.onplay(value);
525      return this;
526   }
527
528   @Override /* Overridden from HtmlElement */
529   public Link onplaying(String value) {
530      super.onplaying(value);
531      return this;
532   }
533
534   @Override /* Overridden from HtmlElement */
535   public Link onprogress(String value) {
536      super.onprogress(value);
537      return this;
538   }
539
540   @Override /* Overridden from HtmlElement */
541   public Link onratechange(String value) {
542      super.onratechange(value);
543      return this;
544   }
545
546   @Override /* Overridden from HtmlElement */
547   public Link onreset(String value) {
548      super.onreset(value);
549      return this;
550   }
551
552   @Override /* Overridden from HtmlElement */
553   public Link onresize(String value) {
554      super.onresize(value);
555      return this;
556   }
557
558   @Override /* Overridden from HtmlElement */
559   public Link onscroll(String value) {
560      super.onscroll(value);
561      return this;
562   }
563
564   @Override /* Overridden from HtmlElement */
565   public Link onseeked(String value) {
566      super.onseeked(value);
567      return this;
568   }
569
570   @Override /* Overridden from HtmlElement */
571   public Link onseeking(String value) {
572      super.onseeking(value);
573      return this;
574   }
575
576   @Override /* Overridden from HtmlElement */
577   public Link onselect(String value) {
578      super.onselect(value);
579      return this;
580   }
581
582   @Override /* Overridden from HtmlElement */
583   public Link onshow(String value) {
584      super.onshow(value);
585      return this;
586   }
587
588   @Override /* Overridden from HtmlElement */
589   public Link onstalled(String value) {
590      super.onstalled(value);
591      return this;
592   }
593
594   @Override /* Overridden from HtmlElement */
595   public Link onsubmit(String value) {
596      super.onsubmit(value);
597      return this;
598   }
599
600   @Override /* Overridden from HtmlElement */
601   public Link onsuspend(String value) {
602      super.onsuspend(value);
603      return this;
604   }
605
606   @Override /* Overridden from HtmlElement */
607   public Link ontimeupdate(String value) {
608      super.ontimeupdate(value);
609      return this;
610   }
611
612   @Override /* Overridden from HtmlElement */
613   public Link ontoggle(String value) {
614      super.ontoggle(value);
615      return this;
616   }
617
618   @Override /* Overridden from HtmlElement */
619   public Link onvolumechange(String value) {
620      super.onvolumechange(value);
621      return this;
622   }
623
624   @Override /* Overridden from HtmlElement */
625   public Link onwaiting(String value) {
626      super.onwaiting(value);
627      return this;
628   }
629
630   @Override /* Overridden from HtmlElement */
631   public Link spellcheck(Object value) {
632      super.spellcheck(value);
633      return this;
634   }
635
636   @Override /* Overridden from HtmlElement */
637   public Link style(String value) {
638      super.style(value);
639      return this;
640   }
641
642   @Override /* Overridden from HtmlElement */
643   public Link tabindex(Object value) {
644      super.tabindex(value);
645      return this;
646   }
647
648   @Override /* Overridden from HtmlElement */
649   public Link title(String value) {
650      super.title(value);
651      return this;
652   }
653
654   @Override /* Overridden from HtmlElement */
655   public Link translate(Object value) {
656      super.translate(value);
657      return this;
658   }
659}