View Javadoc
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 Ahmed Ashour
29   * @author Ronald Brill
30   */
31  @JsxClass(domClass = HtmlTableColumn.class)
32  @JsxClass(domClass = HtmlTableColumnGroup.class)
33  public class HTMLTableColElement extends HTMLTableComponent {
34  
35      /**
36       * JavaScript constructor.
37       */
38      @Override
39      @JsxConstructor
40      public void jsConstructor() {
41          super.jsConstructor();
42      }
43  
44      /**
45       * Returns the value of the {@code span} property.
46       * @return the value of the {@code span} property
47       */
48      @JsxGetter
49      public int getSpan() {
50          final String span = getDomNodeOrDie().getAttributeDirect("span");
51          int i;
52          try {
53              i = Integer.parseInt(span);
54              if (i < 1) {
55                  i = 1;
56              }
57          }
58          catch (final NumberFormatException e) {
59              i = 1;
60          }
61          return i;
62      }
63  
64      /**
65       * Sets the value of the {@code span} property.
66       * @param span the value of the {@code span} property
67       */
68      @JsxSetter
69      public void setSpan(final Object span) {
70          final double d = JavaScriptEngine.toNumber(span);
71          int i = (int) d;
72          if (i < 1) {
73              i = 1;
74          }
75          getDomNodeOrDie().setAttribute("span", Integer.toString(i));
76      }
77  
78      /**
79       * Returns the value of the {@code width} property.
80       * @return the value of the {@code width} property
81       */
82      @JsxGetter(propertyName = "width")
83      public String getWidth_js() {
84          return getWidthOrHeight("width", null);
85      }
86  
87      /**
88       * Sets the value of the {@code width} property.
89       * @param width the value of the {@code width} property
90       */
91      @JsxSetter(propertyName = "width")
92      public void setWidth_js(final Object width) {
93          final String value = JavaScriptEngine.toString(width);
94          setWidthOrHeight("width", value, false);
95      }
96  
97      /**
98       * {@inheritDoc}
99       */
100     @Override
101     protected boolean isEndTagForbidden() {
102         return getDomNodeOrDie() instanceof HtmlTableColumn;
103     }
104 
105     /**
106      * Overwritten to throw an exception.
107      * @param value the new value for replacing this node
108      */
109     @Override
110     public void setOuterHTML(final Object value) {
111         throw JavaScriptEngine.reportRuntimeError("outerHTML is read-only for tag '"
112                             + getDomNodeOrDie().getNodeName() + "'");
113     }
114 }