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.htmlunit.SgmlPage;
20 import org.htmlunit.util.StringUtils;
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 return Math.min(span, 1_000);
62 }
63 catch (final NumberFormatException e) {
64 return 1;
65 }
66 }
67
68
69
70
71 public int getRowSpan() {
72 final String spanString = StringUtils.replaceChars(getAttributeDirect("rowspan"), "\r\n\t ", null);
73 if (spanString == null || spanString.isEmpty()) {
74 return 1;
75 }
76 try {
77 final int span = (int) Double.parseDouble(spanString);
78 if (span < 0) {
79 return 1;
80 }
81 if (span < 1) {
82 return 0;
83 }
84
85 return Math.min(span, 65_534);
86 }
87 catch (final NumberFormatException e) {
88 return 1;
89 }
90 }
91
92
93
94
95
96 public HtmlTableRow getEnclosingRow() {
97 return (HtmlTableRow) getEnclosingElement("tr");
98 }
99
100
101
102
103 @Override
104 public DisplayStyle getDefaultStyleDisplay() {
105 return DisplayStyle.TABLE_CELL;
106 }
107 }