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.marshall.*;
022
023/**
024 * DTO for an HTML <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#the-track-element">&lt;track&gt;</a>
025 * element.
026 *
027 * <p>
028 * The track element is used to specify timed text tracks for media elements (audio and video).
029 * It allows you to add subtitles, captions, descriptions, chapters, or metadata to media content,
030 * making it more accessible and user-friendly.
031 *
032 * <h2 class='section'>Examples:</h2>
033 * <p class='bcode w800'>
034 *    <jc>// Subtitles track</jc>
035 *    Track <jv>subtitles</jv> = <jsm>track</jsm>()
036 *       .kind(<js>"subtitles"</js>)
037 *       .src(<js>"/media/subtitles-en.vtt"</js>)
038 *       .srclang(<js>"en"</js>)
039 *       .label(<js>"English"</js>);
040 *
041 *    <jc>// Captions track (for deaf/hard of hearing)</jc>
042 *    Track <jv>captions</jv> = <jsm>track</jsm>()
043 *       .kind(<js>"captions"</js>)
044 *       .src(<js>"/media/captions-en.vtt"</js>)
045 *       .srclang(<js>"en"</js>)
046 *       .label(<js>"English Captions"</js>)
047 *       .default_(<jk>true</jk>);
048 *
049 *    <jc>// Descriptions track (for audio descriptions)</jc>
050 *    Track <jv>descriptions</jv> = <jsm>track</jsm>()
051 *       .kind(<js>"descriptions"</js>)
052 *       .src(<js>"/media/descriptions-en.vtt"</js>)
053 *       .srclang(<js>"en"</js>)
054 *       .label(<js>"English Descriptions"</js>);
055 *
056 *    <jc>// Chapters track</jc>
057 *    Track <jv>chapters</jv> = <jsm>track</jsm>()
058 *       .kind(<js>"chapters"</js>)
059 *       .src(<js>"/media/chapters.vtt"</js>)
060 *       .srclang(<js>"en"</js>)
061 *       .label(<js>"Chapters"</js>);
062 *
063 *    <jc>// Video with multiple tracks</jc>
064 *    Video <jv>video</jv> = <jsm>video</jsm>()
065 *       .src(<js>"/media/movie.mp4"</js>)
066 *       .controls(<jk>true</jk>)
067 *       .children(
068 *          <jsm>track</jsm>(<js>"/media/subtitles-en.vtt"</js>, <js>"subtitles"</js>).srclang(<js>"en"</js>).label(<js>"English"</js>).default_(<jk>true</jk>),
069 *          <jsm>track</jsm>(<js>"/media/subtitles-es.vtt"</js>, <js>"subtitles"</js>).srclang(<js>"es"</js>).label(<js>"Español"</js>),
070 *          <jsm>track</jsm>(<js>"/media/subtitles-fr.vtt"</js>, <js>"subtitles"</js>).srclang(<js>"fr"</js>).label(<js>"Français"</js>)
071 *       );
072 * </p>
073 *
074 * <p>
075 * The following convenience methods are provided for constructing instances of this bean:
076 * <ul class='javatree'>
077 *    <li class='jc'>{@link HtmlBuilder}
078 *    <ul class='javatree'>
079 *       <li class='jm'>{@link HtmlBuilder#track() track()}
080 *    </ul>
081 * </ul>
082 *
083 * <h2 class='section'>See Also:</h2><ul>
084 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a>
085 * </ul>
086 */
087@Marshalled(typeName = "track")
088public class Track extends HtmlElementVoid<Track> {
089
090   /**
091    * Creates an empty {@link Track} element.
092    */
093   public Track() {}
094
095   /**
096    * Creates a {@link Track} element with the specified {@link Track#src(Object)} and {@link Track#kind(String)}
097    * attributes.
098    *
099    * @param src The {@link Track#src(Object)} attribute. Can be <jk>null</jk>, in which case the attribute is stored with a <jk>null</jk> value (not removed).
100    * @param kind The {@link Track#kind(String)} attribute. Can be <jk>null</jk> to unset the attribute.
101    */
102   public Track(Object src, String kind) {
103      src(src).kind(kind);
104   }
105
106   /**
107    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-track-default">default</a>
108    * attribute.
109    *
110    * <p>
111    * Specifies that this track should be enabled by default if no other text track is more suitable.
112    * This is useful for providing fallback captions or subtitles.
113    *
114    * <p>
115    * This attribute uses deminimized values:
116    * <ul>
117    *    <li><jk>false</jk> - Track is not enabled by default (default)</li>
118    *    <li><jk>true</jk> - Track is enabled by default</li>
119    *    <li>Other values - Passed through as-is</li>
120    * </ul>
121    *
122    * @param value Whether this track should be enabled by default. Can be <jk>null</jk> to unset the attribute.
123    * @return This object.
124    */
125   @SuppressWarnings({
126      "java:S100" // Method name uses underscore suffix to avoid Java keyword conflict
127   })
128   public Track default_(Object value) {
129      attr("default", value);
130      return this;
131   }
132
133   /**
134    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-track-kind">kind</a> attribute.
135    *
136    * <p>
137    * Specifies the type of text track. This determines how the track is used by the media element.
138    *
139    * <p>
140    * Possible values:
141    * <ul>
142    *    <li><js>"subtitles"</js> - Subtitles for the deaf and hard-of-hearing</li>
143    *    <li><js>"captions"</js> - Captions for the deaf and hard-of-hearing</li>
144    *    <li><js>"descriptions"</js> - Text descriptions of the video content</li>
145    *    <li><js>"chapters"</js> - Chapter titles for navigation</li>
146    *    <li><js>"metadata"</js> - Metadata for the media</li>
147    * </ul>
148    *
149    * @param value The type of text track. Can be <jk>null</jk> to unset the attribute.
150    * @return This object.
151    */
152   public Track kind(String value) {
153      attr("kind", value);
154      return this;
155   }
156
157   /**
158    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-track-label">label</a> attribute.
159    *
160    * <p>
161    * Specifies a user-visible label for the text track. This label is displayed in the media
162    * player's track selection menu.
163    *
164    * <p>
165    * The label should be descriptive and help users identify the track (e.g., "English Subtitles",
166    * "Spanish Captions").
167    *
168    * @param value The user-visible label for the text track. Can be <jk>null</jk> to unset the attribute.
169    * @return This object.
170    */
171   public Track label(String value) {
172      attr("label", value);
173      return this;
174   }
175
176   /**
177    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-track-src">src</a> attribute.
178    *
179    * <p>
180    * Address of the resource.
181    *
182    * <p>
183    * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
184    * Strings must be valid URIs.
185    *
186    * <p>
187    * URIs defined by {@link UriResolver} can be used for values.
188    *
189    * @param value
190    *    The new value for this attribute.
191    *    Typically a {@link URL} or {@link String}.
192    *    Can be <jk>null</jk>, in which case the attribute is stored with a <jk>null</jk> value (not removed).
193    * @return This object.
194    */
195   public Track src(Object value) {
196      attrUri("src", value);
197      return this;
198   }
199
200   /**
201    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-track-srclang">srclang</a>
202    * attribute.
203    *
204    * <p>
205    * Specifies the language of the text track. This helps browsers and media players
206    * determine which track to use based on the user's language preferences.
207    *
208    * <p>
209    * The value should be a valid language code (e.g., "en", "es", "fr", "de").
210    *
211    * @param value The language code of the text track. Can be <jk>null</jk> to unset the attribute.
212    * @return This object.
213    */
214   public Track srclang(String value) {
215      attr("srclang", value);
216      return this;
217   }
218
219}