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 * <h5 class='section'>Examples:</h5>
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 * </p>
083 *
084 * <h5 class='section'>See Also:</h5><ul>
085 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a>
086 * </ul>
087 */
088@Marshalled(typeName = "track")
089public class Track extends HtmlElementVoid<Track> {
090
091   /**
092    * Creates an empty {@link Track} element.
093    */
094   public Track() {}
095
096   /**
097    * Creates a {@link Track} element with the specified {@link Track#src(Object)} and {@link Track#kind(String)}
098    * attributes.
099    *
100    * @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).
101    * @param kind The {@link Track#kind(String)} attribute. Can be <jk>null</jk> to unset the attribute.
102    */
103   public Track(Object src, String kind) {
104      src(src).kind(kind);
105   }
106
107   /**
108    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-track-default">default</a>
109    * attribute.
110    *
111    * <p>
112    * Specifies that this track should be enabled by default if no other text track is more suitable.
113    * This is useful for providing fallback captions or subtitles.
114    *
115    * <p>
116    * This attribute uses deminimized values:
117    * <ul>
118    *    <li><jk>false</jk> - Track is not enabled by default (default)</li>
119    *    <li><jk>true</jk> - Track is enabled by default</li>
120    *    <li>Other values - Passed through as-is</li>
121    * </ul>
122    *
123    * @param value Whether this track should be enabled by default. Can be <jk>null</jk> to unset the attribute.
124    * @return This object.
125    */
126   @SuppressWarnings({
127      "java:S100" // Method name uses underscore suffix to avoid Java keyword conflict
128   })
129   public Track default_(Object value) {
130      attr("default", value);
131      return this;
132   }
133
134   /**
135    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-track-kind">kind</a> attribute.
136    *
137    * <p>
138    * Specifies the type of text track. This determines how the track is used by the media element.
139    *
140    * <p>
141    * Possible values:
142    * <ul>
143    *    <li><js>"subtitles"</js> - Subtitles for the deaf and hard-of-hearing</li>
144    *    <li><js>"captions"</js> - Captions for the deaf and hard-of-hearing</li>
145    *    <li><js>"descriptions"</js> - Text descriptions of the video content</li>
146    *    <li><js>"chapters"</js> - Chapter titles for navigation</li>
147    *    <li><js>"metadata"</js> - Metadata for the media</li>
148    * </ul>
149    *
150    * @param value The type of text track. Can be <jk>null</jk> to unset the attribute.
151    * @return This object.
152    */
153   public Track kind(String value) {
154      attr("kind", value);
155      return this;
156   }
157
158   /**
159    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-track-label">label</a> attribute.
160    *
161    * <p>
162    * Specifies a user-visible label for the text track. This label is displayed in the media
163    * player's track selection menu.
164    *
165    * <p>
166    * The label should be descriptive and help users identify the track (e.g., "English Subtitles",
167    * "Spanish Captions").
168    *
169    * @param value The user-visible label for the text track. Can be <jk>null</jk> to unset the attribute.
170    * @return This object.
171    */
172   public Track label(String value) {
173      attr("label", value);
174      return this;
175   }
176
177   /**
178    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-track-src">src</a> attribute.
179    *
180    * <p>
181    * Address of the resource.
182    *
183    * <p>
184    * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
185    * Strings must be valid URIs.
186    *
187    * <p>
188    * URIs defined by {@link UriResolver} can be used for values.
189    *
190    * @param value
191    *    The new value for this attribute.
192    *    Typically a {@link URL} or {@link String}.
193    *    Can be <jk>null</jk>, in which case the attribute is stored with a <jk>null</jk> value (not removed).
194    * @return This object.
195    */
196   public Track src(Object value) {
197      attrUri("src", value);
198      return this;
199   }
200
201   /**
202    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-track-srclang">srclang</a>
203    * attribute.
204    *
205    * <p>
206    * Specifies the language of the text track. This helps browsers and media players
207    * determine which track to use based on the user's language preferences.
208    *
209    * <p>
210    * The value should be a valid language code (e.g., "en", "es", "fr", "de").
211    *
212    * @param value The language code of the text track. Can be <jk>null</jk> to unset the attribute.
213    * @return This object.
214    */
215   public Track srclang(String value) {
216      attr("srclang", value);
217      return this;
218   }
219
220}