1 /*
2 * Copyright (c) 2002-2026 Gargoyle Software Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.htmlunit.javascript.host.html;
16
17 import static org.htmlunit.html.DomElement.ATTRIBUTE_NOT_DEFINED;
18
19 import java.net.MalformedURLException;
20 import java.net.URL;
21
22 import org.htmlunit.html.DomElement;
23 import org.htmlunit.html.HtmlEmbed;
24 import org.htmlunit.html.HtmlPage;
25 import org.htmlunit.javascript.configuration.JsxClass;
26 import org.htmlunit.javascript.configuration.JsxConstructor;
27 import org.htmlunit.javascript.configuration.JsxGetter;
28 import org.htmlunit.javascript.configuration.JsxSetter;
29
30 /**
31 * The JavaScript object {@code HTMLEmbedElement}.
32 *
33 * @author Ahmed Ashour
34 * @author Ronald Brill
35 * @author Lai Quang Duong
36 *
37 * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLEmbedElement">MDN Documentation</a>
38 */
39 @JsxClass(domClass = HtmlEmbed.class)
40 public class HTMLEmbedElement extends HTMLElement {
41
42 /**
43 * JavaScript constructor.
44 */
45 @Override
46 @JsxConstructor
47 public void jsConstructor() {
48 super.jsConstructor();
49 }
50
51 /**
52 * Returns the value of the {@code align} property.
53 * @return the value of the {@code align} property
54 */
55 @JsxGetter
56 public String getAlign() {
57 return getAlign(true);
58 }
59
60 /**
61 * Sets the value of the {@code align} property.
62 * @param align the value of the {@code align} property
63 */
64 @JsxSetter
65 public void setAlign(final String align) {
66 setAlign(align, false);
67 }
68
69 /**
70 * Returns the value of the {@code height} property.
71 * @return the value of the {@code height} property
72 */
73 @JsxGetter(propertyName = "height")
74 public String getHeight_js() {
75 return getDomNodeOrDie().getAttributeDirect("height");
76 }
77
78 /**
79 * Sets the value of the {@code height} property.
80 * @param height the value of the {@code height} property
81 */
82 @JsxSetter(propertyName = "height")
83 public void setHeight_js(final String height) {
84 getDomNodeOrDie().setAttribute("height", height);
85 }
86
87 /**
88 * Returns the value of the {@code width} property.
89 * @return the value of the {@code width} property
90 */
91 @JsxGetter(propertyName = "width")
92 public String getWidth_js() {
93 return getDomNodeOrDie().getAttributeDirect("width");
94 }
95
96 /**
97 * Sets the value of the {@code width} property.
98 * @param width the value of the {@code width} property
99 */
100 @JsxSetter(propertyName = "width")
101 public void setWidth_js(final String width) {
102 getDomNodeOrDie().setAttribute("width", width);
103 }
104
105 /**
106 * Returns the value of the {@code src} property.
107 * @return the value of the {@code src} property
108 */
109 @JsxGetter
110 public String getSrc() {
111 final HtmlEmbed embed = (HtmlEmbed) getDomNodeOrDie();
112 String src = embed.getAttributeDirect("src");
113 if (ATTRIBUTE_NOT_DEFINED == src) {
114 return src;
115 }
116 try {
117 final URL expandedSrc = ((HtmlPage) embed.getPage()).getFullyQualifiedUrl(src);
118 src = expandedSrc.toString();
119 }
120 catch (final MalformedURLException ignored) {
121 // ignore
122 }
123 return src;
124 }
125
126 /**
127 * Sets the value of the {@code src} property.
128 * @param src the value of the {@code src} property
129 */
130 @JsxSetter
131 public void setSrc(final String src) {
132 getDomNodeOrDie().setAttribute("src", src);
133 }
134
135 /**
136 * Returns the value of the {@code type} property.
137 * @return the value of the {@code type} property
138 */
139 @JsxGetter
140 public String getType() {
141 return getDomNodeOrDie().getAttributeDirect("type");
142 }
143
144 /**
145 * Sets the value of the {@code type} property.
146 * @param type the value of the {@code type} property
147 */
148 @JsxSetter
149 public void setType(final String type) {
150 getDomNodeOrDie().setAttribute("type", type);
151 }
152
153 /**
154 * {@inheritDoc}
155 */
156 @Override
157 protected boolean isEndTagForbidden() {
158 return true;
159 }
160
161 /**
162 * Returns the {@code name} attribute.
163 * @return the {@code name} attribute
164 */
165 @JsxGetter
166 @Override
167 public String getName() {
168 return getDomNodeOrDie().getAttributeDirect(DomElement.NAME_ATTRIBUTE);
169 }
170
171 /**
172 * Sets the {@code name} attribute.
173 * @param name the {@code name} attribute value
174 */
175 @JsxSetter
176 @Override
177 public void setName(final String name) {
178 getDomNodeOrDie().setAttribute(DomElement.NAME_ATTRIBUTE, name);
179 }
180
181 }