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"><body></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 * <h5 class='section'>Examples:</h5> 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 * </p> 064 * 065 * <h5 class='section'>See Also:</h5><ul> 066 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a> 067 * </ul> 068 */ 069@Marshalled(typeName = "body") 070public class Body extends HtmlElementMixed<Body> { 071 072 /** 073 * Creates an empty {@link Body} element. 074 */ 075 public Body() {} 076 077 /** 078 * Creates a {@link Body} element with the specified child nodes. 079 * 080 * @param children The child nodes. Must not be <jk>null</jk>. 081 */ 082 public Body(Object...children) { 083 children(children); 084 } 085 086 /** 087 * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-window-onafterprint">onafterprint</a> 088 * attribute. 089 * 090 * <p> 091 * Event handler for when the document has finished printing. 092 * 093 * @param value JavaScript code to execute when the afterprint event occurs. Can be <jk>null</jk> to unset the attribute. 094 * @return This object. 095 */ 096 public Body onafterprint(String value) { 097 attr("onafterprint", value); 098 return this; 099 } 100 101 /** 102 * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-window-onbeforeunload">onbeforeunload</a> 103 * attribute. 104 * 105 * <p> 106 * Event handler for when the document is about to be unloaded (page refresh, navigation, etc.). 107 * 108 * @param value JavaScript code to execute when the beforeunload event occurs. Can be <jk>null</jk> to unset the attribute. 109 * @return This object. 110 */ 111 public Body onbeforeunload(String value) { 112 attr("onbeforeunload", value); 113 return this; 114 } 115 116 /** 117 * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-window-onmessage">onmessage</a> 118 * attribute. 119 * 120 * <p> 121 * Event handler for when a message is received from another window or worker. 122 * 123 * @param value JavaScript code to execute when the message event occurs. Can be <jk>null</jk> to unset the attribute. 124 * @return This object. 125 */ 126 public Body onmessage(String value) { 127 attr("onmessage", value); 128 return this; 129 } 130 131 /** 132 * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-window-ononline">ononline</a> 133 * attribute. 134 * 135 * <p> 136 * Event handler for when the browser has gone online. 137 * 138 * @param value JavaScript code to execute when the online event occurs. Can be <jk>null</jk> to unset the attribute. 139 * @return This object. 140 */ 141 public Body ononline(String value) { 142 attr("ononline", value); 143 return this; 144 } 145 146 /** 147 * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-window-onpageshow">onpageshow</a> 148 * attribute. 149 * 150 * <p> 151 * Event handler for when the page is displayed (including when returning from back/forward cache). 152 * 153 * @param value JavaScript code to execute when the pageshow event occurs. Can be <jk>null</jk> to unset the attribute. 154 * @return This object. 155 */ 156 public Body onpageshow(String value) { 157 attr("onpageshow", value); 158 return this; 159 } 160 161 /** 162 * <a class="doclink" href="https://www.w3.org/TR/html5/webappapis.html#handler-window-onstorage">onstorage</a> 163 * attribute. 164 * 165 * <p> 166 * Event handler for when the storage area (localStorage or sessionStorage) is modified. 167 * 168 * @param value JavaScript code to execute when the storage event occurs. Can be <jk>null</jk> to unset the attribute. 169 * @return This object. 170 */ 171 public Body onstorage(String value) { 172 attr("onstorage", value); 173 return this; 174 } 175 176}