001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.dto.html5;
014
015import static org.apache.juneau.xml.annotation.XmlFormat.*;
016
017import java.util.*;
018
019import org.apache.juneau.*;
020import org.apache.juneau.annotation.*;
021import org.apache.juneau.internal.*;
022import org.apache.juneau.xml.annotation.*;
023
024/**
025 * A subclass of HTML elements that contain only other elements, not text.
026 *
027 * <h5 class='section'>See Also:</h5><ul>
028 *    <li class='link'><a class="doclink" href="../../../../../index.html#jd.Html5">Overview &gt; juneau-dto &gt; HTML5</a>
029 * </ul>
030 */
031@FluentSetters
032public class HtmlElementContainer extends HtmlElement {
033
034   private LinkedList<Object> children;
035
036   /**
037    * The children of this element.
038    *
039    * @return The children of this element.
040    */
041   @Xml(format=ELEMENTS)
042   @Beanp(dictionary=HtmlBeanDictionary.class, name="c")
043   public LinkedList<Object> getChildren() {
044      return children;
045   }
046
047   /**
048    * Sets the children for this container.
049    *
050    * @param children The new children for this container.
051    * @return This object.
052    */
053   @Beanp("c")
054   public HtmlElementContainer setChildren(LinkedList<Object> children) {
055      this.children = children;
056      return this;
057   }
058
059   /**
060    * Returns the child node at the specified index.
061    *
062    * @param index The index of the node in the list of children.
063    * @return The child node, or <jk>null</jk> if it doesn't exist.
064    */
065   public Object getChild(int index) {
066      return (children == null || children.size() <= index || index < 0 ? null : children.get(index));
067   }
068
069   /**
070    * Returns the child node at the specified address.
071    *
072    * <p>
073    * Indexes are zero-indexed.
074    *
075    * <p>
076    * For example, calling <c>getChild(1,2,3);</c> will return the 4th child of the 3rd child of the 2nd child.
077    *
078    * @param index The child indexes.
079    * @return The child node, or <jk>null</jk> if it doesn't point to a valid child.
080    */
081   public Object getChild(int...index) {
082      if (index.length == 0)
083         return null;
084      if (index.length == 1)
085         return getChild(index[0]);
086      Object c = this;
087      for (int element : index) {
088         if (c instanceof HtmlElementMixed)
089            c = ((HtmlElementMixed)c).getChild(element);
090         else if (c instanceof HtmlElementContainer)
091            c = ((HtmlElementContainer)c).getChild(element);
092         else
093            return null;
094      }
095      return c;
096   }
097
098   /**
099    * Returns the child node at the specified index.
100    *
101    * @param <T> The class type of the node.
102    * @param type The class type of the node.
103    * @param index The index of the node in the list of children.
104    * @return The child node, or <jk>null</jk> if it doesn't exist.
105    * @throws InvalidDataConversionException If node is not the expected type.
106    */
107   public <T> T getChild(Class<T> type, int index) {
108      return (children == null || children.size() <= index || index < 0
109         ? null
110         : ConverterUtils.toType(children.get(index), type)
111      );
112   }
113
114   /**
115    * Adds one or more child elements to this element.
116    *
117    * @param children The children to add as child elements.
118    * @return This object.
119    */
120   @FluentSetter
121   public HtmlElement children(Object...children) {
122      if (children.length > 0) {
123         if (this.children == null)
124            this.children = new LinkedList<>();
125         for (Object c : children)
126            this.children.add(c);
127      }
128      return this;
129   }
130
131   /**
132    * Adds a child element to this element.
133    *
134    * @param child The child to add as a child element.
135    * @return This object.
136    */
137   @FluentSetter
138   public HtmlElement child(Object child) {
139      if (this.children == null)
140         this.children = new LinkedList<>();
141      this.children.add(child);
142      return this;
143   }
144
145   // <FluentSetters>
146
147   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
148   public HtmlElementContainer _class(String _class) {
149      super._class(_class);
150      return this;
151   }
152
153   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
154   public HtmlElementContainer accesskey(String accesskey) {
155      super.accesskey(accesskey);
156      return this;
157   }
158
159   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
160   public HtmlElementContainer contenteditable(Object contenteditable) {
161      super.contenteditable(contenteditable);
162      return this;
163   }
164
165   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
166   public HtmlElementContainer dir(String dir) {
167      super.dir(dir);
168      return this;
169   }
170
171   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
172   public HtmlElementContainer hidden(Object hidden) {
173      super.hidden(hidden);
174      return this;
175   }
176
177   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
178   public HtmlElementContainer id(String id) {
179      super.id(id);
180      return this;
181   }
182
183   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
184   public HtmlElementContainer lang(String lang) {
185      super.lang(lang);
186      return this;
187   }
188
189   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
190   public HtmlElementContainer onabort(String onabort) {
191      super.onabort(onabort);
192      return this;
193   }
194
195   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
196   public HtmlElementContainer onblur(String onblur) {
197      super.onblur(onblur);
198      return this;
199   }
200
201   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
202   public HtmlElementContainer oncancel(String oncancel) {
203      super.oncancel(oncancel);
204      return this;
205   }
206
207   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
208   public HtmlElementContainer oncanplay(String oncanplay) {
209      super.oncanplay(oncanplay);
210      return this;
211   }
212
213   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
214   public HtmlElementContainer oncanplaythrough(String oncanplaythrough) {
215      super.oncanplaythrough(oncanplaythrough);
216      return this;
217   }
218
219   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
220   public HtmlElementContainer onchange(String onchange) {
221      super.onchange(onchange);
222      return this;
223   }
224
225   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
226   public HtmlElementContainer onclick(String onclick) {
227      super.onclick(onclick);
228      return this;
229   }
230
231   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
232   public HtmlElementContainer oncuechange(String oncuechange) {
233      super.oncuechange(oncuechange);
234      return this;
235   }
236
237   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
238   public HtmlElementContainer ondblclick(String ondblclick) {
239      super.ondblclick(ondblclick);
240      return this;
241   }
242
243   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
244   public HtmlElementContainer ondurationchange(String ondurationchange) {
245      super.ondurationchange(ondurationchange);
246      return this;
247   }
248
249   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
250   public HtmlElementContainer onemptied(String onemptied) {
251      super.onemptied(onemptied);
252      return this;
253   }
254
255   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
256   public HtmlElementContainer onended(String onended) {
257      super.onended(onended);
258      return this;
259   }
260
261   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
262   public HtmlElementContainer onerror(String onerror) {
263      super.onerror(onerror);
264      return this;
265   }
266
267   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
268   public HtmlElementContainer onfocus(String onfocus) {
269      super.onfocus(onfocus);
270      return this;
271   }
272
273   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
274   public HtmlElementContainer oninput(String oninput) {
275      super.oninput(oninput);
276      return this;
277   }
278
279   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
280   public HtmlElementContainer oninvalid(String oninvalid) {
281      super.oninvalid(oninvalid);
282      return this;
283   }
284
285   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
286   public HtmlElementContainer onkeydown(String onkeydown) {
287      super.onkeydown(onkeydown);
288      return this;
289   }
290
291   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
292   public HtmlElementContainer onkeypress(String onkeypress) {
293      super.onkeypress(onkeypress);
294      return this;
295   }
296
297   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
298   public HtmlElementContainer onkeyup(String onkeyup) {
299      super.onkeyup(onkeyup);
300      return this;
301   }
302
303   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
304   public HtmlElementContainer onload(String onload) {
305      super.onload(onload);
306      return this;
307   }
308
309   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
310   public HtmlElementContainer onloadeddata(String onloadeddata) {
311      super.onloadeddata(onloadeddata);
312      return this;
313   }
314
315   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
316   public HtmlElementContainer onloadedmetadata(String onloadedmetadata) {
317      super.onloadedmetadata(onloadedmetadata);
318      return this;
319   }
320
321   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
322   public HtmlElementContainer onloadstart(String onloadstart) {
323      super.onloadstart(onloadstart);
324      return this;
325   }
326
327   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
328   public HtmlElementContainer onmousedown(String onmousedown) {
329      super.onmousedown(onmousedown);
330      return this;
331   }
332
333   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
334   public HtmlElementContainer onmouseenter(String onmouseenter) {
335      super.onmouseenter(onmouseenter);
336      return this;
337   }
338
339   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
340   public HtmlElementContainer onmouseleave(String onmouseleave) {
341      super.onmouseleave(onmouseleave);
342      return this;
343   }
344
345   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
346   public HtmlElementContainer onmousemove(String onmousemove) {
347      super.onmousemove(onmousemove);
348      return this;
349   }
350
351   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
352   public HtmlElementContainer onmouseout(String onmouseout) {
353      super.onmouseout(onmouseout);
354      return this;
355   }
356
357   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
358   public HtmlElementContainer onmouseover(String onmouseover) {
359      super.onmouseover(onmouseover);
360      return this;
361   }
362
363   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
364   public HtmlElementContainer onmouseup(String onmouseup) {
365      super.onmouseup(onmouseup);
366      return this;
367   }
368
369   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
370   public HtmlElementContainer onmousewheel(String onmousewheel) {
371      super.onmousewheel(onmousewheel);
372      return this;
373   }
374
375   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
376   public HtmlElementContainer onpause(String onpause) {
377      super.onpause(onpause);
378      return this;
379   }
380
381   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
382   public HtmlElementContainer onplay(String onplay) {
383      super.onplay(onplay);
384      return this;
385   }
386
387   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
388   public HtmlElementContainer onplaying(String onplaying) {
389      super.onplaying(onplaying);
390      return this;
391   }
392
393   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
394   public HtmlElementContainer onprogress(String onprogress) {
395      super.onprogress(onprogress);
396      return this;
397   }
398
399   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
400   public HtmlElementContainer onratechange(String onratechange) {
401      super.onratechange(onratechange);
402      return this;
403   }
404
405   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
406   public HtmlElementContainer onreset(String onreset) {
407      super.onreset(onreset);
408      return this;
409   }
410
411   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
412   public HtmlElementContainer onresize(String onresize) {
413      super.onresize(onresize);
414      return this;
415   }
416
417   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
418   public HtmlElementContainer onscroll(String onscroll) {
419      super.onscroll(onscroll);
420      return this;
421   }
422
423   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
424   public HtmlElementContainer onseeked(String onseeked) {
425      super.onseeked(onseeked);
426      return this;
427   }
428
429   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
430   public HtmlElementContainer onseeking(String onseeking) {
431      super.onseeking(onseeking);
432      return this;
433   }
434
435   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
436   public HtmlElementContainer onselect(String onselect) {
437      super.onselect(onselect);
438      return this;
439   }
440
441   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
442   public HtmlElementContainer onshow(String onshow) {
443      super.onshow(onshow);
444      return this;
445   }
446
447   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
448   public HtmlElementContainer onstalled(String onstalled) {
449      super.onstalled(onstalled);
450      return this;
451   }
452
453   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
454   public HtmlElementContainer onsubmit(String onsubmit) {
455      super.onsubmit(onsubmit);
456      return this;
457   }
458
459   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
460   public HtmlElementContainer onsuspend(String onsuspend) {
461      super.onsuspend(onsuspend);
462      return this;
463   }
464
465   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
466   public HtmlElementContainer ontimeupdate(String ontimeupdate) {
467      super.ontimeupdate(ontimeupdate);
468      return this;
469   }
470
471   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
472   public HtmlElementContainer ontoggle(String ontoggle) {
473      super.ontoggle(ontoggle);
474      return this;
475   }
476
477   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
478   public HtmlElementContainer onvolumechange(String onvolumechange) {
479      super.onvolumechange(onvolumechange);
480      return this;
481   }
482
483   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
484   public HtmlElementContainer onwaiting(String onwaiting) {
485      super.onwaiting(onwaiting);
486      return this;
487   }
488
489   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
490   public HtmlElementContainer spellcheck(Object spellcheck) {
491      super.spellcheck(spellcheck);
492      return this;
493   }
494
495   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
496   public HtmlElementContainer style(String style) {
497      super.style(style);
498      return this;
499   }
500
501   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
502   public HtmlElementContainer tabindex(Object tabindex) {
503      super.tabindex(tabindex);
504      return this;
505   }
506
507   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
508   public HtmlElementContainer title(String title) {
509      super.title(title);
510      return this;
511   }
512
513   @Override /* GENERATED - org.apache.juneau.dto.html5.HtmlElement */
514   public HtmlElementContainer translate(Object translate) {
515      super.translate(translate);
516      return this;
517   }
518
519   // </FluentSetters>
520}