DoRTableElement.java
3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemds.guide.addon.dor.AFDoRMapper
* com.adobe.aemds.guide.addon.dor.DoRUtils
* com.adobe.xfa.Attribute
* com.adobe.xfa.Element
* com.adobe.xfa.Node
* com.adobe.xfa.XFA
* org.apache.commons.lang3.StringUtils
*/
package com.adobe.aemds.guide.addon.dor.elements;
import com.adobe.aemds.guide.addon.dor.AFDoRMapper;
import com.adobe.aemds.guide.addon.dor.DoRUtils;
import com.adobe.aemds.guide.addon.dor.elements.DoRPanelElement;
import com.adobe.xfa.Attribute;
import com.adobe.xfa.Element;
import com.adobe.xfa.Node;
import com.adobe.xfa.XFA;
import java.util.Arrays;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
public class DoRTableElement
extends DoRPanelElement {
private String widthValue;
private String widthUnit;
public DoRTableElement(Element xfaElement) throws Exception {
Node bodyRow;
Node headerRow;
Node evenRow;
Node footerRow;
Node oddRow;
super(xfaElement);
String width = xfaElement.getAttribute(XFA.COLUMNWIDTHSTAG).getAttrValue();
this.widthValue = DoRUtils.getValueMatch((String)"\\+?\\d+\\.?\\d*", (String)width);
if (StringUtils.isNotEmpty((CharSequence)this.widthValue)) {
this.widthUnit = width.substring(this.widthValue.length());
}
if ((headerRow = xfaElement.resolveNode(AFDoRMapper.getDoRElement((String)"guideTableHeaderRow"))) != null) {
xfaElement.removeChild(headerRow);
}
if ((evenRow = xfaElement.resolveNode(AFDoRMapper.getDoRElement((String)"guideTableEvenRow"))) != null) {
xfaElement.removeChild(evenRow);
}
if ((oddRow = xfaElement.resolveNode(AFDoRMapper.getDoRElement((String)"guideTableOddRow"))) != null) {
xfaElement.removeChild(oddRow);
}
if ((bodyRow = xfaElement.resolveNode("AF_TABLEBODYROW_XFO")) != null) {
xfaElement.removeChild(bodyRow);
}
if ((footerRow = xfaElement.resolveNode("AF_TABLEFOOTERROW_XFO")) != null) {
xfaElement.removeChild(footerRow);
}
this.xPathExprs.put("columnWidth", "@columnWidths");
}
@Override
public void applyProperties(Properties properties) throws Exception {
if (this.widthValue != null) {
Object[] colWidths;
int columns = Integer.parseInt(properties.get("columns").toString());
String colWidthProp = properties.get("columnWidth").toString();
if (colWidthProp.isEmpty()) {
colWidths = new String[columns];
Arrays.fill(colWidths, "1");
} else {
colWidths = colWidthProp.split(",");
}
double widthSum = 0.0;
for (Object colWidth : colWidths) {
widthSum += Double.parseDouble((String)colWidth);
}
int colIndex = 0;
for (Object colWidth2 : colWidths) {
colWidths[colIndex++] = "" + Double.parseDouble((String)colWidth2) / widthSum * Double.parseDouble(this.widthValue) + this.widthUnit;
}
properties.put("columnWidth", StringUtils.join((Object[])colWidths, (String)" "));
}
super.applyProperties(properties);
}
}