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-iframe-element"><iframe></a> 025 * element. 026 * 027 * <p> 028 * The iframe element represents a nested browsing context, embedding another HTML page into the 029 * current page. It is commonly used to embed external content such as videos, maps, or other 030 * web applications. The sandbox attribute can be used to restrict the capabilities of the 031 * embedded content for security purposes. 032 * 033 * <h5 class='section'>Examples:</h5> 034 * <p class='bcode w800'> 035 * <jk>import static</jk> org.apache.juneau.bean.html5.HtmlBuilder.*; 036 * 037 * <jc>// Simple iframe embedding external content</jc> 038 * Iframe <jv>iframe1</jv> = <jsm>iframe</jsm>() 039 * .src(<js>"https://example.com/embed"</js>) 040 * .width(<js>"800"</js>) 041 * .height(<js>"600"</js>); 042 * 043 * <jc>// Iframe with sandbox restrictions</jc> 044 * Iframe <jv>iframe2</jv> = <jsm>iframe</jsm>() 045 * .src(<js>"https://example.com/untrusted"</js>) 046 * .sandbox(<js>"allow-scripts allow-same-origin"</js>) 047 * .width(<js>"400"</js>) 048 * .height(<js>"300"</js>); 049 * 050 * <jc>// Iframe with inline content</jc> 051 * Iframe <jv>iframe3</jv> = <jsm>iframe</jsm>() 052 * .srcdoc(<js>"<h1>Inline Content</h1><p>This content is embedded directly.</p>"</js>) 053 * .width(<js>"500"</js>) 054 * .height(<js>"200"</js>); 055 * 056 * <jc>// Iframe with name for targeting</jc> 057 * Iframe <jv>iframe4</jv> = <jsm>iframe</jsm>() 058 * .name(<js>"contentFrame"</js>) 059 * .src(<js>"https://example.com/content"</js>) 060 * .width(<js>"100%"</js>) 061 * .height(<js>"400"</js>); 062 * </p> 063 * 064 * <p> 065 * The following convenience methods are provided for constructing instances of this bean: 066 * <ul class='javatree'> 067 * <li class='jc'>{@link HtmlBuilder} 068 * <ul class='javatree'> 069 * <li class='jm'>{@link HtmlBuilder#iframe() iframe()} 070 * <li class='jm'>{@link HtmlBuilder#iframe(Object...) iframe(Object...)} 071 * </ul> 072 * </ul> 073 * </p> 074 * 075 * <h5 class='section'>See Also:</h5><ul> 076 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a> 077 * </ul> 078 */ 079@Marshalled(typeName = "iframe") 080public class Iframe extends HtmlElementMixed<Iframe> { 081 082 /** 083 * Creates an empty {@link Iframe} element. 084 */ 085 public Iframe() {} 086 087 /** 088 * Creates an {@link Iframe} element with the specified child nodes. 089 * 090 * @param children The child nodes. Must not be <jk>null</jk>. 091 */ 092 public Iframe(Object...children) { 093 children(children); 094 } 095 096 /** 097 * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-dim-height">height</a> 098 * attribute. 099 * 100 * <p> 101 * Vertical dimension. 102 * 103 * @param value 104 * The new value for this attribute. 105 * Typically a {@link Number} or {@link String}. 106 * Can be <jk>null</jk> to unset the attribute. 107 * @return This object. 108 */ 109 public Iframe height(Object value) { 110 attr("height", value); 111 return this; 112 } 113 114 /** 115 * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-iframe-name">name</a> attribute. 116 * 117 * <p> 118 * Specifies the name of the iframe. This name can be used as the target for links 119 * and forms, allowing content to be loaded into the iframe. 120 * 121 * <p> 122 * The name should be unique within the document. 123 * 124 * @param value The name of the iframe for targeting. Can be <jk>null</jk> to unset the attribute. 125 * @return This object. 126 */ 127 public Iframe name(String value) { 128 attr("name", value); 129 return this; 130 } 131 132 /** 133 * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-iframe-sandbox">sandbox</a> 134 * attribute. 135 * 136 * <p> 137 * Specifies security restrictions for the iframe content. Multiple restrictions can be 138 * specified as a space-separated list. 139 * 140 * <p> 141 * Common values: 142 * <ul> 143 * <li><js>"allow-scripts"</js> - Allow JavaScript execution</li> 144 * <li><js>"allow-same-origin"</js> - Allow same-origin requests</li> 145 * <li><js>"allow-forms"</js> - Allow form submission</li> 146 * <li><js>"allow-popups"</js> - Allow popup windows</li> 147 * <li><js>"allow-top-navigation"</js> - Allow navigation of top-level browsing context</li> 148 * </ul> 149 * 150 * @param value Security restrictions for the iframe content. Can be <jk>null</jk> to unset the attribute. 151 * @return This object. 152 */ 153 public Iframe sandbox(String value) { 154 attr("sandbox", value); 155 return this; 156 } 157 158 /** 159 * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-iframe-src">src</a> attribute. 160 * 161 * <p> 162 * Address of the resource. 163 * 164 * <p> 165 * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}. 166 * Strings must be valid URIs. 167 * 168 * <p> 169 * URIs defined by {@link UriResolver} can be used for values. 170 * 171 * @param value 172 * The new value for this attribute. 173 * Typically a {@link URL} or {@link String}. 174 * Can be <jk>null</jk>, in which case the attribute is stored with a <jk>null</jk> value (not removed). 175 * @return This object. 176 */ 177 public Iframe src(Object value) { 178 attrUri("src", value); 179 return this; 180 } 181 182 /** 183 * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-iframe-srcdoc">srcdoc</a> 184 * attribute. 185 * 186 * <p> 187 * Specifies the HTML content to be displayed in the iframe. This content is rendered 188 * directly within the iframe without requiring a separate HTTP request. 189 * 190 * <p> 191 * The content should be valid HTML that will be displayed in the iframe. 192 * 193 * @param value The HTML content to display in the iframe. Can be <jk>null</jk> to unset the attribute. 194 * @return This object. 195 */ 196 public Iframe srcdoc(String value) { 197 attr("srcdoc", value); 198 return this; 199 } 200 201 /** 202 * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-dim-width">width</a> attribute. 203 * 204 * <p> 205 * Horizontal dimension. 206 * 207 * @param value 208 * The new value for this attribute. 209 * Typically a {@link Number} or {@link String}. 210 * Can be <jk>null</jk> to unset the attribute. 211 * @return This object. 212 */ 213 public Iframe width(Object value) { 214 attr("width", value); 215 return this; 216 } 217}