FormUtils.java
5.61 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.service.renderer;
import com.adobe.xfa.AppModel;
import com.adobe.xfa.Attribute;
import com.adobe.xfa.Element;
import com.adobe.xfa.Model;
import com.adobe.xfa.Node;
import com.adobe.xfa.XFA;
import com.adobe.xfa.XMLMultiSelectNode;
import com.adobe.xfa.content.ExDataValue;
import com.adobe.xfa.form.FormField;
import com.adobe.xfa.layout.Layout;
import com.adobe.xfa.layout.LayoutNode;
import com.adobe.xfa.ut.ExFull;
import com.adobe.xfa.ut.ResId;
import com.adobe.xfa.ut.StringHolder;
import com.adobe.xfa.ut.StringUtils;
import java.util.StringTokenizer;
public class FormUtils {
public static LayerType getLayer(Element oFormNode) {
if (oFormNode != null) {
LayerType eLayer = FormUtils.getExplicitLayer(oFormNode);
if (eLayer != LayerType.ePrintAndView) {
return eLayer;
}
Element oParent = oFormNode.getXFAParent();
if (oParent == null) {
return LayerType.ePrintAndView;
}
return FormUtils.getLayer(oParent);
}
return LayerType.ePrintAndView;
}
public static LayerType getLayer(Layout oLayout, Element oFormNode) {
LayoutNode oLayoutNode = FormUtils.findRootXFALayoutNodeForFormNode(oLayout, oFormNode);
Element oFNode = oLayoutNode.getFormNode();
return FormUtils.getLayer(oFNode);
}
static LayerType getExplicitLayer(Element oFormNode) {
if (oFormNode != null) {
if (!oFormNode.isPropertySpecified(XFA.RELEVANTTAG, true, 0)) {
return LayerType.ePrintAndView;
}
Attribute oRelevantAttr = oFormNode.getAttribute(XFA.RELEVANTTAG);
String sRelevant = oRelevantAttr.getAttrValue();
StringTokenizer sToker = new StringTokenizer(sRelevant);
while (sToker.hasMoreTokens()) {
String sLayer = sToker.nextToken();
if (sLayer.equals("-print")) {
return LayerType.eViewOnly;
}
if (!sLayer.equals("print") && !sLayer.equals("+print")) continue;
Model oModel = oFormNode.getModel();
AppModel oAppModel = (AppModel)oModel.getXFAParent();
if (oAppModel != null && oAppModel.getLegacySetting(AppModel.XFA_LEGACY_PLUSPRINT)) {
return LayerType.ePrintAndView;
}
return LayerType.ePrintOnly;
}
}
return LayerType.ePrintAndView;
}
public static LayoutNode findRootXFALayoutNodeForFormNode(Layout oLayout, Element oFormField) {
throw new ExFull(ResId.UNSUPPORTED_OPERATION, "getToolTipText");
}
public static String getToolTipText(LayoutNode layoutNode) {
throw new ExFull(ResId.UNSUPPORTED_OPERATION, "getToolTipText");
}
static int getDisplayCode(LayoutNode oLayoutNode, FormField oFormField) {
LayerType elayer = FormUtils.getLayer(oLayoutNode.getFormNode());
int oPresence = oFormField.getEnum(XFA.PRESENCETAG);
int nDisplay = oPresence == 1076494337 ? 1 : (elayer == LayerType.eViewOnly ? 2 : (elayer == LayerType.ePrintOnly ? 3 : 0));
return nDisplay;
}
public static int getDisplayCode(Layout oLayout, FormField oFormField) {
LayoutNode oLayoutNode = FormUtils.findRootXFALayoutNodeForFormNode(oLayout, oFormField);
return FormUtils.getDisplayCode(oLayoutNode, oFormField);
}
public static void setDisplayCode(FormField oFormField, int nDisplay) {
if (nDisplay == 0) {
oFormField.setAttribute(1076494336, XFA.PRESENCETAG);
oFormField.setProperty((Object)"", XFA.RELEVANTTAG);
} else if (nDisplay == 1) {
oFormField.setAttribute(1076494337, XFA.PRESENCETAG);
oFormField.setProperty((Object)"", XFA.RELEVANTTAG);
} else if (nDisplay == 2) {
oFormField.setAttribute(1076494336, XFA.PRESENCETAG);
oFormField.setProperty((Object)"-print", XFA.RELEVANTTAG);
} else {
oFormField.setAttribute(1076494337, XFA.PRESENCETAG);
oFormField.setProperty((Object)"+print", XFA.RELEVANTTAG);
}
}
public static boolean getRichTextField(FormField oField, StringHolder sMarkup) {
Element oValueNode;
if (oField != null && (oValueNode = oField.getElement(XFA.VALUETAG, 0)) != null) {
Node oContentNode = oValueNode.getOneOfChild();
if (oContentNode == null) {
return false;
}
if (oContentNode instanceof ExDataValue) {
ExDataValue oExData = (ExDataValue)oContentNode;
Node aNode = oExData.getOneOfChild();
if (oExData.getAttribute(XFA.CONTENTTYPETAG).toString().equals("text/plain")) {
return false;
}
if (aNode instanceof XMLMultiSelectNode) {
return false;
}
if (sMarkup != null) {
String sTemp = ((ExDataValue)oContentNode).getValue(true, false, false);
if (sTemp.indexOf(10) >= 0) {
sTemp = sTemp.replace("\n", "");
}
sMarkup.value = StringUtils.toXML(sTemp, StringUtils.ToXMLType.XMLTEXT, "", '\r', '\r', "<&>'\"");
}
return true;
}
}
return false;
}
private FormUtils() {
}
public static enum LayerType {
ePrintAndView,
ePrintOnly,
eViewOnly,
eNotSet;
private LayerType() {
}
}
}