CalculateDispatcher.java
8.75 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.form;
import com.adobe.xfa.AppModel;
import com.adobe.xfa.Arg;
import com.adobe.xfa.Attribute;
import com.adobe.xfa.Element;
import com.adobe.xfa.EventManager;
import com.adobe.xfa.Int;
import com.adobe.xfa.Model;
import com.adobe.xfa.Node;
import com.adobe.xfa.ProtoableNode;
import com.adobe.xfa.ScriptDispatcher;
import com.adobe.xfa.XFA;
import com.adobe.xfa.form.FormDependencyTracker;
import com.adobe.xfa.form.FormExclGroup;
import com.adobe.xfa.form.FormField;
import com.adobe.xfa.form.FormModel;
import com.adobe.xfa.form.FormSubform;
import com.adobe.xfa.template.TemplateModel;
import com.adobe.xfa.template.containers.Container;
import com.adobe.xfa.ut.ExFull;
import com.adobe.xfa.ut.MsgFormatPos;
import com.adobe.xfa.ut.Numeric;
import com.adobe.xfa.ut.ResId;
import com.adobe.xfa.ut.StringUtils;
import java.util.List;
class CalculateDispatcher
extends ScriptDispatcher {
private final int meRunAt;
CalculateDispatcher(Element scriptContextNode, String sEventContext, int nEventID, EventManager eventManager, String sScript, String sContentType, int eRunAt) {
super(scriptContextNode, sEventContext, nEventID, eventManager, sScript, sContentType);
this.meRunAt = eRunAt;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public void dispatch() {
int ePresence;
Container container;
TemplateModel templateModel;
Element node = this.getActionContextNode();
if (node == null) {
return;
}
String sScript = this.getScript();
String sContentType = this.getContentType();
assert (node instanceof FormField || node instanceof FormSubform || node instanceof FormExclGroup);
FormModel formModel = (FormModel)node.getModel();
if (formModel.isActivityExcluded("calculate")) {
return;
}
AppModel appModel = node.getAppModel();
if (appModel != null && (templateModel = TemplateModel.getTemplateModel(appModel, false)) != null && templateModel.getOriginalXFAVersion() >= 30 && node instanceof Container && 1076494339 == (ePresence = (container = (Container)node).getRuntimePresence(0))) {
return;
}
int eModelRunAtSetting = formModel.getRunScripts();
int eRunAt = this.getRunAt();
if (eModelRunAtSetting == 1080754179) {
return;
}
if (eModelRunAtSetting == 1080754177 && eRunAt == 1079836672) {
return;
}
if (eModelRunAtSetting == 1080754176 && eRunAt == 1079836673) {
return;
}
int nNumErrorsBefore = formModel.getErrorList().size();
formModel.removeDependency(node, true);
FormDependencyTracker tracker = new FormDependencyTracker(node, true);
try {
int nNumErrorsOccurred;
Arg returnCode = new Arg();
boolean bCalcEnabled = formModel.getCalculationsEnabled();
if (bCalcEnabled && node instanceof FormField) {
FormField field = (FormField)node;
Element value = field.getElement(XFA.VALUETAG, true, 0, false, false);
if (value != null && value.getEnum(XFA.OVERRIDETAG) == 1074003969 && !node.getAppModel().getLegacySetting(AppModel.XFA_LEGACY_CALCOVERRIDE)) {
return;
}
returnCode = field.evaluate(sScript, sContentType, 1, true);
String sReturnValue = null;
if (8 != returnCode.getArgType() && 1 != returnCode.getArgType()) {
Node pContentNode;
if (2 != returnCode.getArgType()) {
sReturnValue = returnCode.getAsString(false);
}
String sRawValueOld = field.getRawValue();
boolean doContinueSettingNewRawValue = true;
Element pValueNode = field.getElement(XFA.VALUETAG, true, 0, false, false);
if (pValueNode != null && (pContentNode = pValueNode.getOneOfChild()) != null && (pContentNode.isSameClass(XFA.DECIMALTAG) || pContentNode.isSameClass(XFA.FLOATTAG)) && !StringUtils.isEmpty(sReturnValue) && !StringUtils.isEmpty(sRawValueOld)) {
double dReturnValue = Numeric.stringToDouble(sReturnValue, true);
double dRawValueOld = Numeric.stringToDouble(sRawValueOld, true);
if (!(Double.isInfinite(dReturnValue) || Double.isNaN(dReturnValue) || Double.isInfinite(dRawValueOld) || Double.isNaN(dRawValueOld))) {
String sReturnValueNormalized;
String sRawValueOldNormalized;
int fracDigits = 8;
if (pContentNode.isSameClass(XFA.DECIMALTAG)) {
Attribute fracDigitAttr = ((Element)pContentNode).getAttribute(XFA.FRACDIGITSTAG);
fracDigits = ((Int)fracDigitAttr).getValue();
}
boolean bl = doContinueSettingNewRawValue = !(sReturnValueNormalized = Numeric.doubleToStringUsingBigDecimal(dReturnValue, fracDigits, false)).equals(sRawValueOldNormalized = Numeric.doubleToStringUsingBigDecimal(dRawValueOld, fracDigits, false));
}
}
if (doContinueSettingNewRawValue && sReturnValue != null && !sReturnValue.equals(sRawValueOld)) {
field.setRawValue(sReturnValue);
String sRawValueNew = field.getRawValue();
if (!(null == sRawValueNew && null == sRawValueOld || null != sRawValueNew && sRawValueNew.equals(sRawValueOld) || node.checkAncestorPerms())) {
field.setRawValue(sRawValueOld);
MsgFormatPos message = new MsgFormatPos(ResId.PermissionsViolationExceptionMethod);
message.format("calculate");
throw new ExFull(message);
}
}
}
}
if (bCalcEnabled && node instanceof FormExclGroup) {
FormExclGroup exclGroup = (FormExclGroup)node;
for (Node child = exclGroup.getFirstXFAChild(); child != null; child = child.getNextXFASibling()) {
FormField formField;
Element value;
if (!(child instanceof FormField) || (value = (formField = (FormField)child).getElement(XFA.VALUETAG, true, 0, false, false)) == null || value.getEnum(XFA.OVERRIDETAG) != 1074003969 || node.getAppModel().getLegacySetting(AppModel.XFA_LEGACY_CALCOVERRIDE)) continue;
return;
}
returnCode = exclGroup.evaluate(sScript, sContentType, 1, true);
String sReturnValue = "";
if (8 != returnCode.getArgType() && 1 != returnCode.getArgType()) {
if (2 != returnCode.getArgType()) {
sReturnValue = returnCode.getAsString(false);
}
if (sReturnValue != null && !sReturnValue.equals(exclGroup.getRawValue())) {
if (!node.checkAncestorPerms()) {
MsgFormatPos message = new MsgFormatPos(ResId.PermissionsViolationExceptionMethod);
message.format("calculate");
throw new ExFull(message);
}
exclGroup.setRawValue(sReturnValue);
}
}
} else if (bCalcEnabled && node instanceof FormSubform) {
FormSubform subform = (FormSubform)node;
returnCode = subform.evaluate(sScript, sContentType, 1, true);
}
if (8 == returnCode.getArgType() && 0 < (nNumErrorsOccurred = formModel.getErrorList().size() - nNumErrorsBefore) && formModel.queueCalculate((ProtoableNode)node)) {
for (int e = 0; e < nNumErrorsOccurred; ++e) {
formModel.removeLastError();
}
assert (nNumErrorsBefore == formModel.getErrorList().size());
}
}
finally {
tracker.dispose();
}
}
int getRunAt() {
return this.meRunAt;
}
@Override
public void updateFromPeer(Object peerNode, int eventType, String arg1, Object arg2) {
Element node = this.getActionContextNode();
if (node == null) {
return;
}
if (peerNode == node && node instanceof Container && eventType == 1 && arg1.equals("presence")) {
FormModel formModel = (FormModel)node.getModel();
formModel.queueCalculatesAndValidates(node, true);
}
}
}