Schema.java
15.8 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa;
import com.adobe.xfa.*;
import com.adobe.xfa.ut.ExFull;
import com.adobe.xfa.ut.MsgFormat;
import com.adobe.xfa.ut.MsgFormatPos;
import com.adobe.xfa.ut.ResId;
public abstract class Schema {
private static final NodeSchema gNullSchema = new NodeSchema(0, 0, 0, 0);
public static final int XFAAVAILABILITY_ALL = 63;
public static final int XFAAVAILABILITY_CORE = 1;
public static final int XFAAVAILABILITY_DEPRECATED = 0;
public static final int XFAAVAILABILITY_DYNAMIC = 16;
public static final int XFAAVAILABILITY_PLUGIN = 8;
public static final int XFAAVAILABILITY_XFAF = 4;
public static final int XFAAVAILABILITY_XFASUBSET = 2;
public static final int XFAAVAILABILITY_XFADESIGNER = 32;
public static final int XFAVERSION_10 = 10;
public static final int XFAVERSION_21 = 21;
public static final int XFAVERSION_22 = 22;
public static final int XFAVERSION_23 = 23;
public static final int XFAVERSION_24 = 24;
public static final int XFAVERSION_25 = 25;
public static final int XFAVERSION_26 = 26;
public static final int XFAVERSION_27 = 27;
public static final int XFAVERSION_28 = 28;
public static final int XFAVERSION_29 = 29;
public static final int XFAVERSION_30 = 30;
public static final int XFAVERSION_31 = 31;
public static final int XFAVERSION_32 = 32;
public static final int XFAVERSION_33 = 33;
public static final int XFAVERSION_34 = 34;
public static final int XFAVERSION_35 = 35;
public static final int XFAVERSION_36 = 36;
public static final int XFAVERSION_HEAD = 36;
public static final int XFAVERSION_LOCALESETHEAD = 27;
public static final int XFAVERSION_SOURCESETHEAD = 28;
public static final int XFAVERSION_CONNECTIONSETHEAD = 28;
public static final int XFAVERSION_CONFIGURATIONHEAD = 36;
public static final int XFAVERSION_OBS = 10;
private boolean mbInitiated;
private boolean mbSchemaUsesProtos;
private Schema mForeignSchemas;
protected final int mnAttributeMax;
protected final int mnAttributeMin;
protected final int mnElementMax;
protected final int mnElementMin;
private final NodeSchema[] mNodeSchemas = new NodeSchema[XFA.XFA_ELEMENT_COUNT];
private final String mSchemaNS;
public static final NodeSchema nullSchema() {
return gNullSchema;
}
protected Schema(String sNS, int nAttributeMin, int nAttributeMax, int nElementMin, int nElementMax) {
this.mnAttributeMin = nAttributeMin;
this.mnAttributeMax = nAttributeMax;
this.mnElementMin = nElementMin;
this.mnElementMax = nElementMax;
this.mbSchemaUsesProtos = true;
this.mSchemaNS = sNS;
}
public void addForeignSchema(Schema schema) {
assert (this.mForeignSchemas == null || this.mForeignSchemas == schema);
this.mForeignSchemas = schema;
}
static void checkVersion(int eClassTag, Model model, Element parent) {
ChildRelnInfo info;
if (parent != null && model != null && (info = parent.getNodeSchema().getChildRelnInfo(eClassTag)) != null) {
if (!model.validateUsage(info.getVersionIntroduced(), info.getAvailability(), true)) {
MsgFormatPos reason = new MsgFormatPos(ResId.InvalidChildVersionException);
reason.format(XFA.getAtom(eClassTag));
reason.format(parent.getClassAtom());
if (model.validateUsageFailedIsFatal(info.getVersionIntroduced(), info.getAvailability())) {
throw new ExFull(reason);
}
model.addErrorList(new ExFull(reason), 3, parent);
}
int nTargetVer = model.getCurrentVersion();
if (info.getVersionDeprecated() != 0 && info.getVersionDeprecated() <= nTargetVer) {
MsgFormatPos reason = new MsgFormatPos(ResId.DeprecatedChildException);
reason.format(XFA.getAtom(eClassTag));
reason.format(parent.getClassAtom());
if (model.isLoading()) {
model.addXMLLoadErrorContext(parent, new ExFull(reason));
}
}
}
}
public Attribute defaultAttribute(int attrName, int eClassTag) {
AttributeInfo attrInfo;
Schema schema = this.findSchema(eClassTag);
if (schema == null) {
throw new ExFull(ResId.InvalidNodeTypeException, "");
}
if (schema != this) {
return schema.defaultAttribute(attrName, eClassTag);
}
Attribute attr = null;
NodeSchema nodeSchema = this.mNodeSchemas[eClassTag - this.mnElementMin];
if (nodeSchema != null && (attrInfo = nodeSchema.getAttributeInfo(attrName)) != null) {
attr = attrInfo.getDefault();
}
if (attr == null) {
throw new ExFull(ResId.InvalidAttributeException, " (" + XFA.getString(attrName) + ")");
}
return attr;
}
private final int ELEMENT_COUNT() {
return this.mnElementMax - this.mnElementMin + 1;
}
protected Schema findForeignSchema(String aNS, int eTag) {
if (this.mForeignSchemas != null && this.mForeignSchemas.getNS() == aNS) {
return this.mForeignSchemas;
}
return null;
}
private Schema findSchema(int classTag) {
if (this.validTag(classTag)) {
return this;
}
if (this.mForeignSchemas != null && this.mForeignSchemas.validTag(classTag)) {
return this.mForeignSchemas;
}
return null;
}
public String getAtom(int classTag) {
Schema schema = this.findSchema(classTag);
if (schema == null) {
throw new ExFull(new MsgFormat(ResId.InvalidNodeTypeException, ""));
}
if (schema == this) {
return XFA.getAtom(classTag);
}
return schema.getAtom(classTag);
}
public int getAttributeTag(String aNS, String aAttrName) {
if (this.mForeignSchemas != null && aNS == this.mForeignSchemas.getNS()) {
return this.mForeignSchemas.getAttributeTag(aNS, aAttrName);
}
return XFA.getTagImpl(aAttrName, Boolean.FALSE);
}
public int getElementTag(String aNS, String aNodeName) {
if (this.mForeignSchemas != null && aNS == this.mForeignSchemas.getNS()) {
return this.mForeignSchemas.getElementTag(aNS, aNodeName);
}
return XFA.getTagImpl(aNodeName, Boolean.TRUE);
}
protected int getElementTag(Element parent) {
return XFA.INVALID_ELEMENT;
}
public final Element getInstance(int eTag, Model model, Element parent, Node prevSibling, boolean bDoVersionCheck) {
boolean bValidate;
assert (eTag >= 0);
assert (model != null);
Schema schema = this.findSchema(eTag);
if (schema == null) {
throw new ExFull(ResId.InvalidNodeTypeException, "");
}
Element element = null;
if (schema != this) {
return schema.getInstance(eTag, model, parent, prevSibling, bDoVersionCheck);
}
NodeSchema nodeSchema = null;
if (eTag >= this.mnElementMin && eTag <= this.mnElementMax) {
nodeSchema = this.mNodeSchemas[eTag - this.mnElementMin];
}
if (nodeSchema == null) {
String className = this.getAtom(eTag);
throw new ExFull(ResId.InvalidNodeTypeException, className);
}
boolean bl = bValidate = !(schema instanceof AppSchema);
if (parent != null && bValidate) {
ChildRelnInfo info = parent.getNodeSchema().getChildRelnInfo(eTag);
if (info != null) {
if (bDoVersionCheck) {
Schema.checkVersion(eTag, model, parent);
}
} else if (schema.getElementTag(parent) == XFA.INVALID_ELEMENT) {
MsgFormatPos message = new MsgFormatPos(ResId.InvalidChildAppendException, parent.getClassAtom());
message.format(XFA.getAtom(eTag));
throw new ExFull(message);
}
}
String className = this.getAtom(eTag);
if (this.mNodeSchemas[eTag] == null) {
throw new ExFull(ResId.InvalidNodeTypeException, className);
}
element = this.newElement(eTag, parent, prevSibling);
if (element == null) {
if (this.mbSchemaUsesProtos) {
if (eTag == XFA.RICHTEXTNODETAG) {
element = new RichTextNode(parent, prevSibling);
} else if (eTag == XFA.XMLMULTISELECTNODETAG) {
element = new XMLMultiSelectNode(parent, prevSibling);
} else if (eTag == XFA.DSIGDATATAG) {
element = new DSigData(parent, prevSibling);
}
}
if (element == null) {
throw new ExFull(ResId.InvalidNodeTypeException, className);
}
}
element.setLocalName(className);
element.setQName(className);
element.setNS(model);
if (element instanceof XMLMultiSelectNode) {
Element elemParent;
for (elemParent = element.getXMLParent(); elemParent != null && !elemParent.isContainer(); elemParent = elemParent.getXMLParent()) {
}
String name = "items";
if (elemParent != null) {
name = elemParent.getName();
}
element.setLocalName(name);
element.setQName(name);
}
if (element instanceof GenericNode || element instanceof GenericTextContainer) {
element.setClass(className, eTag);
}
if (parent == null) {
element.setModel(model);
element.setDocument(model.getDocument());
}
return element;
}
public final NodeSchema getNodeSchema(int eClassTag) {
Schema schema = this.findSchema(eClassTag);
if (schema == null) {
return gNullSchema;
}
NodeSchema nodeSchema = schema.mNodeSchemas[eClassTag - schema.mnElementMin];
if (nodeSchema != null) {
return nodeSchema;
}
return gNullSchema;
}
public String getNS() {
return this.mSchemaNS;
}
protected int getTextTag() {
return XFA.TEXTNODETAG;
}
protected void importSchema(Schema sourceSchema) {
this.mForeignSchemas = sourceSchema.mForeignSchemas;
int srcCount = sourceSchema.mnElementMax - sourceSchema.mnElementMin;
for (int nPos = 0; nPos < srcCount; ++nPos) {
NodeSchema src = sourceSchema.mNodeSchemas[nPos];
NodeSchema dest = src == null ? null : new NodeSchema(src, this.mnAttributeMin, this.mnAttributeMax, this.mnElementMin, this.mnElementMax);
this.mNodeSchemas[nPos] = dest;
}
this.mbInitiated = true;
}
protected void initSchema() {
if (this.mbInitiated) {
return;
}
this.mbInitiated = true;
if (this.mbSchemaUsesProtos) {
this.mNodeSchemas[XFA.RICHTEXTNODETAG - this.mnElementMin] = new NodeSchema(this.mnAttributeMin, this.mnAttributeMax, this.mnElementMin, this.mnElementMax);
this.mNodeSchemas[XFA.XMLMULTISELECTNODETAG - this.mnElementMin] = new NodeSchema(this.mnAttributeMin, this.mnAttributeMax, this.mnElementMin, this.mnElementMax);
this.mNodeSchemas[XFA.DSIGDATATAG - this.mnElementMin] = new NodeSchema(this.mnAttributeMin, this.mnAttributeMax, this.mnElementMin, this.mnElementMax);
this.putAttribute(XFA.DSIGDATATAG, XFA.IDTAG, null, 10, 63, 0);
}
}
public Attribute newAttribute(int attrName, String value, int eClassTag) {
AttributeInfo attrInfo;
Schema schema = this.findSchema(eClassTag);
if (schema == null) {
throw new ExFull(ResId.InvalidNodeTypeException, "");
}
if (schema != this) {
return schema.newAttribute(attrName, value, eClassTag);
}
Attribute attr = null;
NodeSchema nodeSchema = this.mNodeSchemas[eClassTag - this.mnElementMin];
if (nodeSchema != null && (attrInfo = nodeSchema.getAttributeInfo(attrName)) != null) {
attr = attrInfo.getDefault();
}
if (attr == null) {
throw new ExFull(ResId.InvalidAttributeException, " (" + XFA.getString(attrName) + "=" + value + ")");
}
return attr.newAttribute(value);
}
protected abstract Element newElement(int var1, Element var2, Node var3);
protected void putAttribute(int eParent, EnumValue value, int nVersionIntro, int nAvailability, int nVersionDep) {
this.putAttribute(eParent, value.getAttrTag(), value, nVersionIntro, nAvailability, nVersionDep);
}
protected void putAttribute(int eParent, int eAttr, Attribute defaultValue, int nVersionIntro, int nAvailability, int nVersionDep) {
assert (eAttr >= XFA.XFA_PARTIAL_ELEMENT_COUNT);
NodeSchema nodeSchema = this.mNodeSchemas[eParent - this.mnElementMin];
if (nodeSchema == null) {
this.mNodeSchemas[eParent - this.mnElementMin] = nodeSchema = new NodeSchema(this.mnAttributeMin, this.mnAttributeMax, this.mnElementMin, this.mnElementMax);
}
nodeSchema.addAttr(eAttr, defaultValue == null ? new StringAttr("", "") : defaultValue, nVersionIntro, nVersionDep, nAvailability, 0);
}
protected void putChildAttrs(int eTag) {
this.putAttribute(eTag, XFA.NAMETAG, null, 10, 7, 0);
this.putAttribute(eTag, XFA.IDTAG, null, 10, 7, 0);
this.putAttribute(eTag, XFA.USETAG, null, 10, 3, 0);
this.putAttribute(eTag, XFA.USEHREFTAG, null, 26, 3, 0);
}
protected void putElement(int eParent, int eChild, ChildReln oRelation, int nVersionIntro, int nAvailability, int nVersionDep) {
assert (eChild - this.mnElementMin < this.ELEMENT_COUNT());
NodeSchema nodeSchema = this.mNodeSchemas[eParent - this.mnElementMin];
if (nodeSchema == null) {
this.mNodeSchemas[eParent - this.mnElementMin] = nodeSchema = new NodeSchema(this.mnAttributeMin, this.mnAttributeMax, this.mnElementMin, this.mnElementMax);
}
nodeSchema.addChild(eChild, oRelation, nVersionIntro, nVersionDep, nAvailability, 0);
if (this.mbSchemaUsesProtos) {
NodeSchema protoNodeSchema = this.mNodeSchemas[XFA.PROTOTAG - this.mnElementMin];
if (protoNodeSchema == null) {
this.mNodeSchemas[XFA.PROTOTAG - this.mnElementMin] = protoNodeSchema = new NodeSchema(this.mnAttributeMin, this.mnAttributeMax, this.mnElementMin, this.mnElementMax);
}
if (eChild != XFA.PROTOTAG && eChild != XFA.TEXTNODETAG && eChild != XFA.RICHTEXTNODETAG && eChild != XFA.XMLMULTISELECTNODETAG) {
protoNodeSchema.addChild(eChild, ChildReln.getZeroOrMore(), nVersionIntro, nVersionDep, nAvailability, 0);
}
}
}
public void putForeignElement(int eParent, int eChild, ChildReln relation, Schema foreignSchema, int nVersionIntro, int nAvailability, int nVersionDep) {
assert (foreignSchema.validTag(eChild));
NodeSchema nodeSchema = this.mNodeSchemas[eParent - this.mnElementMin];
if (nodeSchema == null) {
this.mNodeSchemas[eParent - this.mnElementMin] = nodeSchema = new NodeSchema(this.mnAttributeMin, this.mnAttributeMax, this.mnElementMin, this.mnElementMax);
}
nodeSchema.addForeignChild(eChild, relation, nVersionIntro, nVersionDep, nAvailability, 0);
}
protected void putPropAttrs(int eTag) {
this.putAttribute(eTag, XFA.IDTAG, null, 10, 3, 0);
this.putAttribute(eTag, XFA.USETAG, null, 10, 3, 0);
this.putAttribute(eTag, XFA.USEHREFTAG, null, 26, 3, 0);
}
protected final void schemaUsesProtos(boolean bUseProto) {
this.mbSchemaUsesProtos = bUseProto;
}
private boolean validTag(int classTag) {
return classTag >= this.mnElementMin && classTag <= this.mnAttributeMax;
}
}