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