FloatValue.java
4.22 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.content;
import com.adobe.xfa.AppModel;
import com.adobe.xfa.Element;
import com.adobe.xfa.Model;
import com.adobe.xfa.Node;
import com.adobe.xfa.ScriptTable;
import com.adobe.xfa.TextNode;
import com.adobe.xfa.XFA;
import com.adobe.xfa.content.Content;
import com.adobe.xfa.content.FloatScript;
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 org.xml.sax.Attributes;
public final class FloatValue
extends Content {
public FloatValue(Element parent, Node prevSibling) {
super(parent, prevSibling, null, "float", "float", null, XFA.FLOATTAG, "float");
}
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
return super.equals(object) && this.getValue() == ((FloatValue)object).getValue();
}
@Override
public int hashCode() {
long bits = Double.doubleToLongBits(this.getValue());
return super.hashCode() ^ (int)(bits ^ bits >>> 32);
}
@Override
public ScriptTable getScriptTable() {
return FloatScript.getScriptTable();
}
public double getValue() {
double dVal = 0.0;
String sVal = this.getStrValue();
if (!StringUtils.isEmpty(sVal)) {
dVal = Numeric.stringToDouble(sVal, false);
}
return dVal;
}
public void setValue(double newValue, boolean bNotify, boolean bDefault) {
String sNum = Numeric.doubleToString(newValue, 8, false);
super.setStrValue(sNum, true, false);
}
@Override
public void setValue(String sValue, boolean bFromData, boolean bNotify, boolean bDefault) {
if (StringUtils.isEmpty(sValue)) {
this.setStrValue("", true, false);
} else {
double dVal = Numeric.stringToDouble(sValue, true);
boolean bTypeMismatch = Double.isNaN(dVal);
if (bTypeMismatch) {
if (!this.getAppModel().getLegacySetting(AppModel.XFA_LEGACY_V30_SCRIPTING)) {
MsgFormatPos oMessage = new MsgFormatPos(ResId.TypeMismatch);
oMessage.format(this.getSOMExpression());
oMessage.format(sValue);
this.getModel().addErrorList(new ExFull(oMessage), 3, this);
}
if (this.getAppModel().getLegacySetting(AppModel.XFA_LEGACY_V29_SCRIPTING) && !this.getAppModel().getLegacySetting(AppModel.XFA_PATCH_W_2447677)) {
this.setValue(0.0, true, false);
} else if (bFromData) {
this.setStrValue(sValue, true, false);
}
return;
}
this.setValue(dVal, true, false);
}
}
@Override
public String toString() {
return Numeric.doubleToString(this.getValue(), 8, false);
}
@Override
public void appendChild(Node child, boolean bValidate) {
if (child instanceof TextNode) {
TextNode textChild = (TextNode)child;
textChild.setValue(FloatValue.normalizeValue(textChild.getValue()), false, textChild.isDefault(true));
}
super.appendChild(child, bValidate);
}
@Override
public void insertChild(Node child, Node poRefNode, boolean bValidate) {
if (child instanceof TextNode) {
TextNode textChild = (TextNode)child;
textChild.setValue(FloatValue.normalizeValue(textChild.getValue()), false, textChild.isDefault(true));
}
super.insertChild(child, poRefNode, bValidate);
}
private static String formatValue(double dValue) {
return Numeric.doubleToString(dValue, 8, false);
}
private static String normalizeValue(String sValue) {
if (StringUtils.isEmpty(sValue)) {
return "";
}
return FloatValue.formatValue(Numeric.stringToDouble(sValue, false));
}
public boolean valueHasTypeMismatch() {
String sVal = this.getStrValue();
if (StringUtils.isEmpty(sVal)) {
return false;
}
double dVal = Numeric.stringToDouble(sVal, true);
return Double.isNaN(dVal);
}
}