1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.html;
16
17 import static org.htmlunit.BrowserVersionFeatures.JS_TABLE_SPAN_SET_ZERO_IF_INVALID;
18
19 import java.util.Map;
20
21 import org.apache.commons.lang3.StringUtils;
22 import org.htmlunit.SgmlPage;
23
24
25
26
27
28
29
30
31
32
33
34
35
36 public abstract class HtmlTableCell extends HtmlElement {
37
38
39
40
41
42
43
44
45 protected HtmlTableCell(final String qualifiedName, final SgmlPage page,
46 final Map<String, DomAttr> attributes) {
47 super(qualifiedName, page, attributes);
48 }
49
50
51
52
53 public int getColumnSpan() {
54 final String spanString = StringUtils.replaceChars(getAttributeDirect("colspan"), "\r\n\t ", null);
55 if (spanString == null || spanString.isEmpty()) {
56 return 1;
57 }
58 try {
59 final int span = (int) Double.parseDouble(spanString);
60 if (span < 1) {
61 return 1;
62 }
63 if (span > 1_000) {
64 return 1_000;
65 }
66 return span;
67 }
68 catch (final NumberFormatException e) {
69 return 1;
70 }
71 }
72
73
74
75
76 public int getRowSpan() {
77 final String spanString = StringUtils.replaceChars(getAttributeDirect("rowspan"), "\r\n\t ", null);
78 if (spanString == null || spanString.isEmpty()) {
79 return 1;
80 }
81 try {
82 final int span = (int) Double.parseDouble(spanString);
83 if (getPage().getWebClient().getBrowserVersion().hasFeature(JS_TABLE_SPAN_SET_ZERO_IF_INVALID)) {
84 if (span < 0) {
85 return 1;
86 }
87 if (span < 1) {
88 return 0;
89 }
90 }
91 else {
92 if (span < 1) {
93 return 1;
94 }
95 }
96
97 if (span > 65_534) {
98 return 65_534;
99 }
100 return span;
101 }
102 catch (final NumberFormatException e) {
103 return 1;
104 }
105 }
106
107
108
109
110
111 public HtmlTableRow getEnclosingRow() {
112 return (HtmlTableRow) getEnclosingElement("tr");
113 }
114
115
116
117
118 @Override
119 public DisplayStyle getDefaultStyleDisplay() {
120 return DisplayStyle.TABLE_CELL;
121 }
122 }