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">&lt;iframe&gt;</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 * <h2 class='section'>Examples:</h2>
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>"&lt;h1&gt;Inline Content&lt;/h1&gt;&lt;p&gt;This content is embedded directly.&lt;/p&gt;"</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 *
074 * <h2 class='section'>See Also:</h2><ul>
075 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a>
076 * </ul>
077 */
078@Marshalled(typeName = "iframe")
079public class Iframe extends HtmlElementMixed<Iframe> {
080
081   /**
082    * Creates an empty {@link Iframe} element.
083    */
084   public Iframe() {}
085
086   /**
087    * Creates an {@link Iframe} element with the specified child nodes.
088    *
089    * @param children The child nodes. Must not be <jk>null</jk>.
090    */
091   public Iframe(Object...children) {
092      children(children);
093   }
094
095   /**
096    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-dim-height">height</a>
097    * attribute.
098    *
099    * <p>
100    * Vertical dimension.
101    *
102    * @param value
103    *    The new value for this attribute.
104    *    Typically a {@link Number} or {@link String}.
105    *    Can be <jk>null</jk> to unset the attribute.
106    * @return This object.
107    */
108   public Iframe height(Object value) {
109      attr("height", value);
110      return this;
111   }
112
113   /**
114    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-iframe-name">name</a> attribute.
115    *
116    * <p>
117    * Specifies the name of the iframe. This name can be used as the target for links
118    * and forms, allowing content to be loaded into the iframe.
119    *
120    * <p>
121    * The name should be unique within the document.
122    *
123    * @param value The name of the iframe for targeting. Can be <jk>null</jk> to unset the attribute.
124    * @return This object.
125    */
126   public Iframe name(String value) {
127      attr("name", value);
128      return this;
129   }
130
131   /**
132    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-iframe-sandbox">sandbox</a>
133    * attribute.
134    *
135    * <p>
136    * Specifies security restrictions for the iframe content. Multiple restrictions can be
137    * specified as a space-separated list.
138    *
139    * <p>
140    * Common values:
141    * <ul>
142    *    <li><js>"allow-scripts"</js> - Allow JavaScript execution</li>
143    *    <li><js>"allow-same-origin"</js> - Allow same-origin requests</li>
144    *    <li><js>"allow-forms"</js> - Allow form submission</li>
145    *    <li><js>"allow-popups"</js> - Allow popup windows</li>
146    *    <li><js>"allow-top-navigation"</js> - Allow navigation of top-level browsing context</li>
147    * </ul>
148    *
149    * @param value Security restrictions for the iframe content. Can be <jk>null</jk> to unset the attribute.
150    * @return This object.
151    */
152   public Iframe sandbox(String value) {
153      attr("sandbox", value);
154      return this;
155   }
156
157   /**
158    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-iframe-src">src</a> attribute.
159    *
160    * <p>
161    * Address of the resource.
162    *
163    * <p>
164    * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
165    * Strings must be valid URIs.
166    *
167    * <p>
168    * URIs defined by {@link UriResolver} can be used for values.
169    *
170    * @param value
171    *    The new value for this attribute.
172    *    Typically a {@link URL} or {@link String}.
173    *    Can be <jk>null</jk>, in which case the attribute is stored with a <jk>null</jk> value (not removed).
174    * @return This object.
175    */
176   public Iframe src(Object value) {
177      attrUri("src", value);
178      return this;
179   }
180
181   /**
182    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-iframe-srcdoc">srcdoc</a>
183    * attribute.
184    *
185    * <p>
186    * Specifies the HTML content to be displayed in the iframe. This content is rendered
187    * directly within the iframe without requiring a separate HTTP request.
188    *
189    * <p>
190    * The content should be valid HTML that will be displayed in the iframe.
191    *
192    * @param value The HTML content to display in the iframe. Can be <jk>null</jk> to unset the attribute.
193    * @return This object.
194    */
195   public Iframe srcdoc(String value) {
196      attr("srcdoc", value);
197      return this;
198   }
199
200   /**
201    * <a class="doclink" href="https://www.w3.org/TR/html5/embedded-content-0.html#attr-dim-width">width</a> attribute.
202    *
203    * <p>
204    * Horizontal dimension.
205    *
206    * @param value
207    *    The new value for this attribute.
208    *    Typically a {@link Number} or {@link String}.
209    *    Can be <jk>null</jk> to unset the attribute.
210    * @return This object.
211    */
212   public Iframe width(Object value) {
213      attr("width", value);
214      return this;
215   }
216}