ExDataValue.java
10.4 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.content;
import com.adobe.xfa.AppModel;
import com.adobe.xfa.Attribute;
import com.adobe.xfa.Document;
import com.adobe.xfa.Element;
import com.adobe.xfa.Int;
import com.adobe.xfa.Model;
import com.adobe.xfa.Node;
import com.adobe.xfa.RichTextNode;
import com.adobe.xfa.Schema;
import com.adobe.xfa.ScriptTable;
import com.adobe.xfa.StringAttr;
import com.adobe.xfa.TextNode;
import com.adobe.xfa.XFA;
import com.adobe.xfa.XMLMultiSelectNode;
import com.adobe.xfa.content.Content;
import com.adobe.xfa.content.ExDataScript;
import com.adobe.xfa.ut.ExFull;
import com.adobe.xfa.ut.MsgFormatPos;
import com.adobe.xfa.ut.ResId;
import com.adobe.xfa.ut.StringUtils;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import org.xml.sax.Attributes;
public final class ExDataValue
extends Content {
public ExDataValue(Element parent, Node prevSibling) {
super(parent, prevSibling, null, "exData", "exData", null, XFA.EXDATATAG, "exData");
}
@Override
protected boolean childrenAreIndexable() {
return false;
}
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
return super.equals(object) && this.getValue(true, true, true).equals(((ExDataValue)object).getValue(true, true, true));
}
@Override
public int hashCode() {
return super.hashCode() ^ this.getValue(true, true, true).hashCode();
}
@Override
public ScriptTable getScriptTable() {
return ExDataScript.getScriptTable();
}
@Override
public String getStrValue() {
return this.getValue(false, false, true);
}
@Override
public void updateIDValues(String sPrefix, List<String> oldReferenceList) {
Node oNode = this.getOneOfChild(true, false);
if (oNode instanceof RichTextNode) {
((RichTextNode)oNode).updateIDValuesImpl(sPrefix, oldReferenceList);
}
}
public String getValue(boolean bAsFragment, boolean bSuppressPreamble, boolean bLegacyWhitespaceProcessing) {
Int maxLength;
int nMaxLength;
String sValue = "";
if (!this.getIsNull()) {
Node node = this.getOneOfChild();
if (node instanceof RichTextNode) {
RichTextNode richTextValue = (RichTextNode)node;
sValue = richTextValue.getValue(bAsFragment, bSuppressPreamble, bLegacyWhitespaceProcessing);
} else if (node instanceof TextNode) {
TextNode textValue = (TextNode)node;
sValue = textValue.getValue();
} else if (node instanceof XMLMultiSelectNode) {
XMLMultiSelectNode multiSelectValue = (XMLMultiSelectNode)node;
sValue = multiSelectValue.getValue(bAsFragment, bSuppressPreamble);
}
}
Element grandParent = null;
if (this.getXFAParent() != null) {
grandParent = this.getXFAParent().getXFAParent();
}
if (grandParent != null && grandParent.isSameClass(XFA.FIELDTAG) && !bAsFragment && 0 < (nMaxLength = (maxLength = (Int)this.getAttribute(XFA.MAXLENGTHTAG)).getValue()) && nMaxLength < sValue.length()) {
sValue = sValue.substring(0, maxLength.getValue());
}
return sValue;
}
public void getValues(List<String> values) {
if (!this.getIsNull()) {
Node child = this.getOneOfChild(true, false);
if (child instanceof XMLMultiSelectNode) {
((XMLMultiSelectNode)child).getValues(values);
} else {
String sValue = this.getValue(false, false, true);
values.add(sValue);
}
}
}
@Override
public boolean processTextChildrenDuringParse() {
return false;
}
@Override
public void loadXML(InputStream sInFile, boolean bIgnoreAggregatingTag, Element.ReplaceContent eReplaceContent) {
this.removeXmlChildren();
Document doc = this.getOwnerDocument();
Element imported = doc.loadIntoDocument(sInFile);
Element startNode = imported.getFirstXMLChildElement();
if (startNode == null) {
return;
}
if (!bIgnoreAggregatingTag) {
this.setContent(startNode, false);
} else if ((startNode = startNode.getFirstXMLChildElement()) != null) {
this.setContent(startNode, false);
}
}
public void setContent(Node domNode, boolean bDefault) {
this.mbIsNullDetermined = false;
this.removeXsiNilAttribute();
Model model = this.getModel();
Element element = null;
if (domNode instanceof Element) {
element = (Element)domNode;
}
if (element != null && (element.getNS() == "http://www.w3.org/1999/xhtml" || element.getLocalName() == "body" || element.getLocalName() == "xhtml")) {
StringAttr prop = new StringAttr("contentType", "text/html");
this.setAttribute(prop, XFA.CONTENTTYPETAG);
RichTextNode richTextNode = new RichTextNode(null, null);
this.copyDomElementOntoXfa(element, richTextNode);
this.removeXmlChildren();
this.setOneOfChild(richTextNode);
if (!bDefault) {
this.makeNonDefault(false);
}
if (this.getAppModel() != null && this.getAppModel().bumpVersionOnRichTextLoad() && !this.validateUsage(richTextNode.getVersionRequired(), 0, true)) {
MsgFormatPos reason = new MsgFormatPos(ResId.InvalidChildVersionException);
reason.format("");
reason.format(element.getClassAtom());
model.addErrorList(new ExFull(reason), 3, this);
}
this.notifyPeers(2, "", null);
} else if (this.getAttribute(XFA.CONTENTTYPETAG).toString().equals("text/xml")) {
Node newContent = null;
if (element != null) {
XMLMultiSelectNode xmlMultiSelectNode = new XMLMultiSelectNode(null, null);
this.copyDomElementOntoXfa(element, xmlMultiSelectNode);
newContent = xmlMultiSelectNode;
} else if (domNode instanceof TextNode) {
newContent = domNode;
}
this.removeXmlChildren();
this.setOneOfChild(newContent);
if (!bDefault) {
this.makeNonDefault(false);
}
this.notifyPeers(2, "", null);
} else {
if (this.getAttribute(XFA.CONTENTTYPETAG).toString().equals("text/html")) {
StringAttr prop = new StringAttr("contentType", "");
this.setAttribute(prop, XFA.CONTENTTYPETAG);
}
if (domNode instanceof TextNode) {
this.removeXmlChildren();
this.setOneOfChild(domNode);
if (!bDefault) {
this.makeNonDefault(false);
}
this.notifyPeers(2, "", null);
} else {
this.appendChild(domNode, false);
MsgFormatPos format = new MsgFormatPos(ResId.UnsupportedContentWarning);
format.format(this.getClassAtom());
format.format(domNode.getName());
ExFull err = new ExFull(format);
model.addErrorList(err, 3, this);
}
}
}
private void removeXmlChildren() {
Node child = this.getFirstXMLChild();
while (child != null) {
this.removeChild(child);
child = this.getFirstXMLChild();
}
}
private void copyDomElementOntoXfa(Element domNode, Element xfaNode) {
xfaNode.setModel(this.getModel());
xfaNode.setDocument(this.getOwnerDocument());
xfaNode.setDOMProperties(domNode.getNS(), domNode.getLocalName(), domNode.getXMLName(), null);
for (int i = 0; i < domNode.getNumAttrs(); ++i) {
Attribute a = domNode.getAttr(i);
xfaNode.setAttribute(a.getNS(), a.getQName(), a.getLocalName(), a.getAttrValue(), false);
}
Node child = domNode.getFirstXMLChild();
while (child != null) {
Node nextSibling = child.getNextXMLSibling();
xfaNode.appendChild(child);
child = nextSibling;
}
}
public void setValue(List<String> values) {
if (this.getAttribute(XFA.CONTENTTYPETAG).toString().equals("text/xml")) {
Element parent;
if (this.getFirstXFAChild() != null) {
Node child = this.getFirstXFAChild();
if (child instanceof XMLMultiSelectNode) {
((XMLMultiSelectNode)child).setValues(values);
return;
}
while (this.getFirstXMLChild() != null) {
this.getFirstXMLChild().remove();
}
}
Model model = this.getModel();
XMLMultiSelectNode newNode = (XMLMultiSelectNode)model.getSchema().getInstance(XFA.XMLMULTISELECTNODETAG, model, this, null, false);
for (parent = this.getXFAParent(); parent != null && !parent.isContainer(); parent = parent.getXFAParent()) {
}
String aName = "items";
if (parent != null) {
aName = parent.getName();
}
newNode.setLocalName(aName);
newNode.setValues(values);
} else {
String sValue = values.get(0);
this.setValue(sValue);
}
}
public void setValue(String sText) {
String sContent = this.getAttribute(XFA.CONTENTTYPETAG).toString();
if (sContent.equals("text/xml")) {
ArrayList<String> selectionList = new ArrayList<String>();
if (!StringUtils.isEmpty(sText)) {
StringTokenizer tokenizer = new StringTokenizer(sText, "\n");
while (tokenizer.hasMoreTokens()) {
selectionList.add(tokenizer.nextToken());
}
}
this.setValue(selectionList);
} else {
if (StringUtils.isEmpty(sContent) || sContent.equals("text/html")) {
this.setAttribute(new StringAttr("contentType", "text/plain"), XFA.CONTENTTYPETAG);
}
this.setStrValue(sText, true, false);
}
}
@Override
public String toString() {
return this.getValue(false, false, true);
}
}