DoRElementUtils.java
3.78 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.xfa.Attribute
* com.adobe.xfa.Element
* com.adobe.xfa.Node
* com.adobe.xfa.StringAttr
* com.adobe.xfa.XFA
* com.adobe.xfa.template.formatting.Occur
* org.apache.commons.lang3.StringUtils
*/
package com.adobe.aemds.guide.addon.dor.elements;
import com.adobe.xfa.Attribute;
import com.adobe.xfa.Element;
import com.adobe.xfa.Node;
import com.adobe.xfa.StringAttr;
import com.adobe.xfa.XFA;
import com.adobe.xfa.template.formatting.Occur;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
public class DoRElementUtils {
public static boolean isRepeatable(Element element) {
Occur occur = (Occur)element.resolveNode("#occur");
if (occur == null) {
return false;
}
String min = occur.getAttribute(XFA.MINTAG).getAttrValue();
String max = occur.getAttribute(XFA.MAXTAG).getAttrValue();
if (min == null || max == null) {
return false;
}
if (min.equals("1") && max.equals("1")) {
return false;
}
return true;
}
public static boolean isRepeatable(Properties properties) {
if (properties.containsKey("minOccur") && properties.containsKey("maxOccur")) {
String min = properties.getProperty("minOccur");
String max = properties.getProperty("maxOccur");
if (!(min == null || max == null || min.isEmpty() || max.isEmpty() || min.equals("1") && max.equals("1"))) {
return true;
}
}
return false;
}
public static String getColumnWidthFromParent(Element xfaElement) {
int index = xfaElement.getIndex(true);
String width = null;
Element parent = xfaElement.getXFAParent();
Element table = parent.getXFAParent();
String[] widths = table.getAttribute(XFA.COLUMNWIDTHSTAG).getAttrValue().split(" ");
if (index < widths.length) {
width = widths[index];
}
return width;
}
public static void adaptToTableCell(Element element, String width) {
StringAttr attribute = new StringAttr("hAlign", "center");
element.setAttribute((Attribute)attribute, XFA.HALIGNTAG);
Element caption = (Element)element.resolveNode("#caption");
if (caption != null) {
caption.removeAttr(null, "reserve");
}
element.removeAttr(null, "w");
if (width != null) {
element.setAttribute((Attribute)new StringAttr("maxW", width), XFA.MAXWTAG);
}
}
public static Node locateChildByName(Node parent, String childName, int nThChild) {
if (childName == null || parent == null) {
return null;
}
int nFound = 0;
for (Node child = parent.getFirstXMLChild(); child != null; child = child.getNextXMLSibling()) {
if (!childName.equals(child.getName())) continue;
if (nFound == nThChild) {
return child;
}
++nFound;
}
return null;
}
public static boolean isTableHeaderRow(Element element) {
Element assist;
if (DoRElementUtils.isTableRow(element) && (assist = (Element)element.resolveNode("assist")) != null && assist.getAttribute(XFA.ROLETAG) != null && StringUtils.equals((CharSequence)assist.getAttribute(XFA.ROLETAG).getAttrValue(), (CharSequence)"TH")) {
return true;
}
return false;
}
public static boolean isTableRow(Element element) {
if (element != null && element.getAttribute(XFA.LAYOUTTAG) != null && element.getAttribute(XFA.LAYOUTTAG).getAttrValue() != null && element.getAttribute(XFA.LAYOUTTAG).getAttrValue().equals("row")) {
return true;
}
return false;
}
}