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