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 org.apache.juneau.marshall.*;
020
021/**
022 * DTO for an HTML <a class="doclink" href="https://www.w3.org/TR/html5/sections.html#the-body-element">&lt;body&gt;</a>
023 * element.
024 *
025 * <p>
026 * The body element represents the content of an HTML document. It contains all the visible content
027 * of the page, including text, images, links, forms, and other elements. The body element is
028 * typically the direct child of the html element and contains all the main content of the document.
029 *
030 * <h2 class='section'>Examples:</h2>
031 * <p class='bcode w800'>
032 *    <jc>// Simple body with text content</jc>
033 *    Body <jv>body1</jv> = <jsm>body</jsm>().text(<js>"Welcome to our website!"</js>);
034 *
035 *    <jc>// Body with structured content</jc>
036 *    Body <jv>body2</jv> = <jsm>body</jsm>()
037 *       .children(
038 *          <jsm>header</jsm>().children(
039 *             <jsm>h1</jsm>().text(<js>"Page Title"</js>)
040 *          ),
041 *          <jsm>main</jsm>().children(
042 *             <jsm>p</jsm>().text(<js>"Main content goes here."</js>)
043 *          ),
044 *          <jsm>footer</jsm>().text(<js>"Copyright 2024"</js>)
045 *       );
046 *
047 *    <jc>// Body with event handlers</jc>
048 *    Body <jv>body3</jv> = <jsm>body</jsm>()
049 *       .onload(<js>"initializePage()"</js>)
050 *       .onbeforeunload(<js>"return confirm('Are you sure you want to leave?')"</js>)
051 *       .text(<js>"Page content"</js>);
052 * </p>
053 *
054 * <p>
055 * The following convenience methods are provided for constructing instances of this bean:
056 * <ul class='javatree'>
057 *    <li class='jc'>{@link HtmlBuilder}
058 *    <ul class='javatree'>
059 *       <li class='jm'>{@link HtmlBuilder#body() body()}
060 *       <li class='jm'>{@link HtmlBuilder#body(Object...) body(Object...)}
061 *    </ul>
062 * </ul>
063 *
064 * <h2 class='section'>See Also:</h2><ul>
065 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a>
066 * </ul>
067 */
068@Marshalled(typeName = "body")
069public class Body extends HtmlElementMixed<Body> {
070
071   /**
072    * Creates an empty {@link Body} element.
073    */
074   public Body() {}
075
076   /**
077    * Creates a {@link Body} element with the specified child nodes.
078    *
079    * @param children The child nodes. Must not be <jk>null</jk>.
080    */
081   public Body(Object...children) {
082      children(children);
083   }
084
085   /**
086    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-window-onafterprint">onafterprint</a>
087    * attribute.
088    *
089    * <p>
090    * Event handler for when the document has finished printing.
091    *
092    * @param value JavaScript code to execute when the afterprint event occurs. Can be <jk>null</jk> to unset the attribute.
093    * @return This object.
094    */
095   public Body onafterprint(String value) {
096      attr("onafterprint", value);
097      return this;
098   }
099
100   /**
101    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-window-onbeforeunload">onbeforeunload</a>
102    * attribute.
103    *
104    * <p>
105    * Event handler for when the document is about to be unloaded (page refresh, navigation, etc.).
106    *
107    * @param value JavaScript code to execute when the beforeunload event occurs. Can be <jk>null</jk> to unset the attribute.
108    * @return This object.
109    */
110   public Body onbeforeunload(String value) {
111      attr("onbeforeunload", value);
112      return this;
113   }
114
115   /**
116    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-window-onmessage">onmessage</a>
117    * attribute.
118    *
119    * <p>
120    * Event handler for when a message is received from another window or worker.
121    *
122    * @param value JavaScript code to execute when the message event occurs. Can be <jk>null</jk> to unset the attribute.
123    * @return This object.
124    */
125   public Body onmessage(String value) {
126      attr("onmessage", value);
127      return this;
128   }
129
130   /**
131    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-window-ononline">ononline</a>
132    * attribute.
133    *
134    * <p>
135    * Event handler for when the browser has gone online.
136    *
137    * @param value JavaScript code to execute when the online event occurs. Can be <jk>null</jk> to unset the attribute.
138    * @return This object.
139    */
140   public Body ononline(String value) {
141      attr("ononline", value);
142      return this;
143   }
144
145   /**
146    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-window-onpageshow">onpageshow</a>
147    * attribute.
148    *
149    * <p>
150    * Event handler for when the page is displayed (including when returning from back/forward cache).
151    *
152    * @param value JavaScript code to execute when the pageshow event occurs. Can be <jk>null</jk> to unset the attribute.
153    * @return This object.
154    */
155   public Body onpageshow(String value) {
156      attr("onpageshow", value);
157      return this;
158   }
159
160   /**
161    * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-window-onstorage">onstorage</a>
162    * attribute.
163    *
164    * <p>
165    * Event handler for when the storage area (localStorage or sessionStorage) is modified.
166    *
167    * @param value JavaScript code to execute when the storage event occurs. Can be <jk>null</jk> to unset the attribute.
168    * @return This object.
169    */
170   public Body onstorage(String value) {
171      attr("onstorage", value);
172      return this;
173   }
174
175}