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 org.htmlunit.html.HtmlTableColumn;
18 import org.htmlunit.html.HtmlTableColumnGroup;
19 import org.htmlunit.javascript.JavaScriptEngine;
20 import org.htmlunit.javascript.configuration.JsxClass;
21 import org.htmlunit.javascript.configuration.JsxConstructor;
22 import org.htmlunit.javascript.configuration.JsxGetter;
23 import org.htmlunit.javascript.configuration.JsxSetter;
24
25 /**
26 * The JavaScript object {@code HTMLTableColElement}.
27 *
28 * @author Daniel Gredler
29 * @author Ahmed Ashour
30 * @author Ronald Brill
31 *
32 * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableColElement">MDN Documentation</a>
33 */
34 @JsxClass(domClass = HtmlTableColumn.class)
35 @JsxClass(domClass = HtmlTableColumnGroup.class)
36 public class HTMLTableColElement extends HTMLElement {
37
38 /** The default value of the "vAlign" property. */
39 private static final String VALIGN_DEFAULT_VALUE = "top";
40
41 /**
42 * JavaScript constructor.
43 */
44 @Override
45 @JsxConstructor
46 public void jsConstructor() {
47 super.jsConstructor();
48 }
49
50 /**
51 * Returns the value of the {@code span} property.
52 * @return the value of the {@code span} property
53 */
54 @JsxGetter
55 public int getSpan() {
56 final String span = getDomNodeOrDie().getAttributeDirect("span");
57 int i;
58 try {
59 i = Integer.parseInt(span);
60 if (i < 1) {
61 i = 1;
62 }
63 }
64 catch (final NumberFormatException e) {
65 i = 1;
66 }
67 return i;
68 }
69
70 /**
71 * Sets the value of the {@code span} property.
72 * @param span the value of the {@code span} property
73 */
74 @JsxSetter
75 public void setSpan(final Object span) {
76 final double d = JavaScriptEngine.toNumber(span);
77 int i = (int) d;
78 if (i < 1) {
79 i = 1;
80 }
81 getDomNodeOrDie().setAttribute("span", Integer.toString(i));
82 }
83
84 /**
85 * Returns the value of the {@code width} property.
86 * @return the value of the {@code width} property
87 */
88 @JsxGetter(propertyName = "width")
89 public String getWidth_js() {
90 return getWidthOrHeight("width", null);
91 }
92
93 /**
94 * Sets the value of the {@code width} property.
95 * @param width the value of the {@code width} property
96 */
97 @JsxSetter(propertyName = "width")
98 public void setWidth_js(final Object width) {
99 final String value = JavaScriptEngine.toString(width);
100 setWidthOrHeight("width", value, false);
101 }
102
103 /**
104 * {@inheritDoc}
105 */
106 @Override
107 protected boolean isEndTagForbidden() {
108 return getDomNodeOrDie() instanceof HtmlTableColumn;
109 }
110
111 /**
112 * Overwritten to throw an exception.
113 * @param value the new value for replacing this node
114 */
115 @Override
116 public void setOuterHTML(final Object value) {
117 throw JavaScriptEngine.reportRuntimeError("outerHTML is read-only for tag '"
118 + getDomNodeOrDie().getNodeName() + "'");
119 }
120
121 /**
122 * Returns the value of the {@code align} property.
123 * @return the value of the {@code align} property
124 */
125 @JsxGetter
126 public String getAlign() {
127 return getAlign(true);
128 }
129
130 /**
131 * Sets the value of the {@code align} property.
132 * @param align the value of the {@code align} property
133 */
134 @JsxSetter
135 public void setAlign(final String align) {
136 setAlign(align, false);
137 }
138
139 /**
140 * Returns the value of the {@code vAlign} property.
141 * @return the value of the {@code vAlign} property
142 */
143 @JsxGetter
144 public String getVAlign() {
145 return getVAlign(getValidVAlignValues(), VALIGN_DEFAULT_VALUE);
146 }
147
148 /**
149 * Sets the value of the {@code vAlign} property.
150 * @param vAlign the value of the {@code vAlign} property
151 */
152 @JsxSetter
153 public void setVAlign(final Object vAlign) {
154 setVAlign(vAlign, getValidVAlignValues());
155 }
156
157 /**
158 * Returns the valid "vAlign" values for this element, depending on the browser being emulated.
159 * @return the valid "vAlign" values for this element, depending on the browser being emulated
160 */
161 private String[] getValidVAlignValues() {
162 return null;
163 }
164
165 /**
166 * Returns the value of the {@code ch} property.
167 * @return the value of the {@code ch} property
168 */
169 @Override
170 @JsxGetter
171 public String getCh() {
172 return super.getCh();
173 }
174
175 /**
176 * Sets the value of the {@code ch} property.
177 * @param ch the value of the {@code ch} property
178 */
179 @Override
180 @JsxSetter
181 public void setCh(final String ch) {
182 super.setCh(ch);
183 }
184
185 /**
186 * Returns the value of the {@code chOff} property.
187 * @return the value of the {@code chOff} property
188 */
189 @Override
190 @JsxGetter
191 public String getChOff() {
192 return super.getChOff();
193 }
194
195 /**
196 * Sets the value of the {@code chOff} property.
197 * @param chOff the value of the {@code chOff} property
198 */
199 @Override
200 @JsxSetter
201 public void setChOff(final String chOff) {
202 super.setChOff(chOff);
203 }
204 }