FormManifest.java
15.2 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.form;
import com.adobe.xfa.AppModel;
import com.adobe.xfa.Element;
import com.adobe.xfa.EnumAttr;
import com.adobe.xfa.Manifest;
import com.adobe.xfa.Model;
import com.adobe.xfa.Node;
import com.adobe.xfa.NodeList;
import com.adobe.xfa.NodeListFilter;
import com.adobe.xfa.Obj;
import com.adobe.xfa.ProtoableNode;
import com.adobe.xfa.XFA;
import com.adobe.xfa.data.DataNode;
import com.adobe.xfa.form.FormDataListener;
import com.adobe.xfa.form.FormExclGroup;
import com.adobe.xfa.form.FormField;
import com.adobe.xfa.form.FormSubform;
import com.adobe.xfa.template.TemplateModel;
import com.adobe.xfa.template.containers.ExclGroup;
import com.adobe.xfa.template.containers.Field;
import com.adobe.xfa.ut.ExFull;
import com.adobe.xfa.ut.MsgFormatPos;
import com.adobe.xfa.ut.Peer;
import com.adobe.xfa.ut.ResId;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class FormManifest
extends Manifest {
protected static final IteratorAction<Boolean> validateFormNode = new IteratorAction<Boolean>(){
@Override
public Boolean action(Node item, Boolean data) {
Boolean validateResult = data;
assert (validateResult != null);
if (validateResult != null) {
if (item instanceof FormSubform) {
FormSubform formSubform = (FormSubform)item;
if (validateResult.booleanValue()) {
validateResult = formSubform.execValidate();
} else {
formSubform.execValidate();
}
} else if (item instanceof FormField) {
FormField formField = (FormField)item;
if (validateResult.booleanValue()) {
validateResult = formField.execValidate();
} else {
formField.execValidate();
}
} else if (item instanceof FormExclGroup) {
FormExclGroup exclGroup = (FormExclGroup)item;
if (validateResult.booleanValue()) {
validateResult = exclGroup.execValidate();
} else {
exclGroup.execValidate();
}
}
}
return validateResult;
}
};
protected static final IteratorAction<?> calculateFormNode = new IteratorAction<Object>(){
@Override
public Object action(Node item, Object data) {
if (item instanceof FormSubform) {
((FormSubform)item).execEvent("calculate");
} else if (item instanceof FormField) {
((FormField)item).execEvent("calculate");
} else if (item instanceof FormExclGroup) {
((FormExclGroup)item).execEvent("calculate");
}
return null;
}
};
protected static final IteratorAction<?> initializeFormNode = new IteratorAction<Object>(){
@Override
public Object action(Node item, Object data) {
if (item instanceof FormSubform) {
((FormSubform)item).execEvent("initialize");
} else if (item instanceof FormField) {
((FormField)item).execEvent("initialize");
} else if (item instanceof FormExclGroup) {
((FormExclGroup)item).execEvent("initialize");
}
return null;
}
};
protected static final IteratorAction<List<String>> populateFieldName = new IteratorAction<List<String>>(){
@Override
public List<String> action(Node item, List<String> aExcludedFields) {
TemplateModel template = TemplateModel.getTemplateModel(item.getModel().getAppModel(), false);
assert (template != null);
if (template != null) {
assert (aExcludedFields != null);
if (aExcludedFields != null) {
assert (FormManifest.isTemplateField(item) || FormManifest.isTemplateExclGroup(item));
if (FormManifest.isTemplateField(item) || FormManifest.isTemplateExclGroup(item)) {
String sSOMExpression = item.getSOMExpression(template, false);
assert (sSOMExpression.length() > 0);
if (sSOMExpression.length() > 0) {
aExcludedFields.add(sSOMExpression);
}
}
}
}
return null;
}
};
FormManifest(Element parent, Node prevSibling) {
super(parent, prevSibling);
}
@Override
public boolean doExecValidate() {
Boolean bValidateResult = Boolean.TRUE;
Element parent = this.getXFAParent();
assert (parent != null);
if (parent != null) {
if (parent.getClassTag() == XFA.SIGNATURETAG) {
bValidateResult = this.processPDFSignatureManifest(validateFormNode, bValidateResult);
} else if (parent.getClassTag() == XFA.SIGNDATATAG) {
bValidateResult = this.processXMLSignatureManifest(validateFormNode, bValidateResult);
} else {
throw new ExFull(ResId.InvalidManifestException);
}
}
return bValidateResult;
}
@Override
public void doExecCalculate() {
Element parent = this.getXFAParent();
assert (parent != null);
if (parent != null) {
if (parent.getClassTag() == XFA.SIGNATURETAG) {
this.processPDFSignatureManifest(calculateFormNode, null);
} else if (parent.getClassTag() == XFA.SIGNDATATAG) {
this.processXMLSignatureManifest(calculateFormNode, null);
} else {
throw new ExFull(ResId.InvalidManifestException);
}
}
}
@Override
public void doExecInitialize() {
Element parent = this.getXFAParent();
assert (parent != null);
if (parent != null) {
if (parent.getClassTag() == XFA.SIGNATURETAG) {
this.processPDFSignatureManifest(initializeFormNode, null);
} else if (parent.getClassTag() == XFA.SIGNDATATAG) {
this.processXMLSignatureManifest(initializeFormNode, null);
} else {
throw new ExFull(ResId.InvalidManifestException);
}
}
}
protected <T> T processPDFSignatureManifest(IteratorAction<T> iteratorAction, T data) {
int eAction = this.getEnum(XFA.ACTIONTAG);
if (eAction == 7077888) {
return this.templateNodesToFormNodesInclude(iteratorAction, data);
}
if (eAction == 7077889) {
return this.templateNodesToFormNodesExclude(iteratorAction, data);
}
if (eAction == 7077890) {
return this.templateNodesToFormNodesAll(iteratorAction, data);
}
throw new ExFull(ResId.InvalidManifestException);
}
protected <T> T templateNodesToFormNodesInclude(IteratorAction<T> iteratorAction, T data) {
NodeList referencedNodes = this.doEvaluate();
assert (referencedNodes != null);
if (referencedNodes == null) {
return null;
}
int nNumReferencedNodes = referencedNodes.length();
for (int nReferencedNodeIndex = 0; nReferencedNodeIndex < nNumReferencedNodes; ++nReferencedNodeIndex) {
Obj referencedNode = referencedNodes.item(nReferencedNodeIndex);
assert (referencedNode instanceof Node);
if (!(referencedNode instanceof Node)) continue;
List<Node> expandedNodes = this.expandResolvedNode((Node)referencedNode);
int nNumExpandedNodes = expandedNodes.size();
for (int nExpandedNodeIndex = 0; nExpandedNodeIndex < nNumExpandedNodes; ++nExpandedNodeIndex) {
Node expandedNode = expandedNodes.get(nExpandedNodeIndex);
data = this.templateNodeToFormNodes(iteratorAction, data, expandedNode);
}
}
return data;
}
protected <T> T templateNodesToFormNodesExclude(IteratorAction<T> iteratorAction, T data) {
TemplateModel template = TemplateModel.getTemplateModel(this.getAppModel(), false);
assert (template != null);
if (template != null) {
ArrayList<String> aExcludedFields = new ArrayList<String>();
this.templateNodeToTemplateNodes(populateFieldName, aExcludedFields);
ManifestExclusionFilter filter = new ManifestExclusionFilter(aExcludedFields);
List<Node> nodeList = filter.filterNodes(template);
int nLength = nodeList.size();
for (int nIndex = 0; nIndex < nLength; ++nIndex) {
Node node = nodeList.get(nIndex);
data = this.templateNodeToFormNodes(iteratorAction, data, node);
}
}
return data;
}
protected <T> T templateNodesToFormNodesAll(IteratorAction<T> iteratorAction, T data) {
TemplateModel template = TemplateModel.getTemplateModel(this.getAppModel(), false);
assert (template != null);
if (template != null) {
ManifestExclusionFilter filter = new ManifestExclusionFilter(null);
List<Node> nodeList = filter.filterNodes(template);
int nLength = nodeList.size();
for (int nIndex = 0; nIndex < nLength; ++nIndex) {
Node node = nodeList.get(nIndex);
data = this.templateNodeToFormNodes(iteratorAction, data, node);
}
}
return data;
}
protected <T> T templateNodeToTemplateNodes(IteratorAction<T> iteratorAction, T data) {
NodeList referencedNodes = this.doEvaluate();
assert (referencedNodes != null);
if (referencedNodes == null) {
return data;
}
int nNumReferencedNodes = referencedNodes.length();
for (int nReferencedNodeIndex = 0; nReferencedNodeIndex < nNumReferencedNodes; ++nReferencedNodeIndex) {
Obj referencedNode = referencedNodes.item(nReferencedNodeIndex);
assert (referencedNode instanceof Node);
if (!(referencedNode instanceof Node)) continue;
List<Node> expandedNodes = this.expandResolvedNode((Node)referencedNode);
int nNumExpandedNodes = expandedNodes.size();
for (int nExpandedNodeIndex = 0; nExpandedNodeIndex < nNumExpandedNodes; ++nExpandedNodeIndex) {
Node expandedNode = expandedNodes.get(nExpandedNodeIndex);
data = iteratorAction.action(expandedNode, data);
}
}
return data;
}
protected <T> T templateNodeToFormNodes(IteratorAction<T> iteratorAction, T data, Node templateNode) {
assert (templateNode != null && (FormManifest.isTemplateField(templateNode) || FormManifest.isTemplateExclGroup(templateNode)));
ProtoableNode protoable = (ProtoableNode)templateNode;
int nProtoedIndex = 0;
ProtoableNode protoed = protoable.getProtoed(nProtoedIndex);
while (protoed != null) {
if (protoed.getModel() != null && (protoed instanceof FormField || protoed instanceof FormExclGroup)) {
data = iteratorAction.action(protoed, data);
}
protoed = protoable.getProtoed(++nProtoedIndex);
}
return data;
}
protected List<Node> expandResolvedNode(Node item) {
if (FormManifest.isTemplateField(item) || FormManifest.isTemplateExclGroup(item)) {
return Collections.singletonList(item);
}
if (item instanceof Element) {
ManifestExclusionFilter filter = new ManifestExclusionFilter(null);
return filter.filterNodes(item, 0);
}
return Collections.emptyList();
}
protected static boolean isTemplateField(Node node) {
return node instanceof Field && !(node instanceof FormField);
}
protected static boolean isTemplateExclGroup(Node node) {
return node instanceof ExclGroup && !(node instanceof FormExclGroup);
}
protected <T> T processXMLSignatureManifest(IteratorAction<T> iteratorAction, T data) {
int eAction = this.getEnum(XFA.ACTIONTAG);
if (eAction == 7077888) {
return this.dataNodesToFormNodesInclude(iteratorAction, data);
}
if (eAction == 7077889 || eAction == 7077890) {
MsgFormatPos msg = new MsgFormatPos(ResId.UnsupportedOperationException);
String sOpp = "action=\"" + EnumAttr.getString(eAction) + '\"';
msg.format(sOpp);
msg.format("manifest");
throw new ExFull(msg);
}
throw new ExFull(ResId.InvalidManifestException);
}
protected <T> T dataNodesToFormNodesInclude(IteratorAction<T> iteratorAction, T data) {
NodeList referencedNodes = this.doEvaluate();
assert (referencedNodes != null);
if (referencedNodes == null) {
return data;
}
int nNumReferencedNodes = referencedNodes.length();
for (int nReferencedNodeIndex = 0; nReferencedNodeIndex < nNumReferencedNodes; ++nReferencedNodeIndex) {
Obj referencedNode = referencedNodes.item(nReferencedNodeIndex);
assert (referencedNode instanceof Node);
if (!(referencedNode instanceof Node)) continue;
data = this.dataNodeToFormNodes(iteratorAction, data, (Node)referencedNode);
}
return data;
}
protected <T> T dataNodeToFormNodes(IteratorAction<T> iteratorAction, T data, Node dataNode) {
assert (dataNode instanceof DataNode);
if (dataNode instanceof DataNode) {
int nPeerIndex = 0;
Peer peer = dataNode.getPeer(nPeerIndex);
while (peer != null) {
Element formNode;
if (peer instanceof FormDataListener && (formNode = ((FormDataListener)peer).getFormNode()) != null) {
data = iteratorAction.action(formNode, data);
}
peer = dataNode.getPeer(++nPeerIndex);
}
}
return data;
}
protected static class ManifestExclusionFilter
extends NodeListFilter {
private final List<String> mExcludedFields;
private Node mLastExclGroup;
public ManifestExclusionFilter(List<String> excludedFields) {
this.mExcludedFields = excludedFields;
}
@Override
public boolean accept(Node node) {
assert (node != null);
if (node != null && (FormManifest.isTemplateField(node) || FormManifest.isTemplateExclGroup(node))) {
this.mLastExclGroup = null;
if (FormManifest.isTemplateField(node)) {
if (node.getXFAParent() == this.mLastExclGroup) {
return false;
}
} else {
this.mLastExclGroup = node;
}
if (this.mExcludedFields == null) {
return true;
}
String sSOMExpression = node.getSOMExpression(node.getModel(), false);
return !this.mExcludedFields.contains(sSOMExpression);
}
return false;
}
}
protected static interface IteratorAction<T> {
public T action(Node var1, T var2);
}
}