DurboInput.java
10.1 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.NamespaceException
* javax.jcr.RepositoryException
* javax.jcr.Value
* javax.jcr.ValueFactory
*/
package com.day.durbo;
import com.day.durbo.DurboConstants;
import com.day.durbo.DurboNamespaceResolver;
import com.day.durbo.DurboValue;
import com.day.durbo.impl.DurboInputStream;
import com.day.durbo.io.RegionFileInputStream;
import java.io.EOFException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.jcr.NamespaceException;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
public class DurboInput
implements DurboConstants,
DurboNamespaceResolver {
public static final int PROPERTY_TYPE_UNDEFINED = 0;
public static final int PROPERTY_TYPE_STRING = 1;
public static final int PROPERTY_TYPE_BINARY = 2;
public static final int PROPERTY_TYPE_LONG = 3;
public static final int PROPERTY_TYPE_DOUBLE = 4;
public static final int PROPERTY_TYPE_DATE = 5;
public static final int PROPERTY_TYPE_BOOLEAN = 6;
public static final int PROPERTY_TYPE_NAME = 7;
public static final int PROPERTY_TYPE_PATH = 8;
public static final int PROPERTY_TYPE_REFERENCE = 9;
private DurboInputStream in;
private double version = 1.0;
private String encoding = "";
private String contentType = "";
private Map<String, String> namespaceByPrefix = new HashMap<String, String>();
private Map<String, String> namespaceByURI = new HashMap<String, String>();
public DurboInput(File file) throws IOException {
this(new RegionFileInputStream(file));
}
public DurboInput(InputStream inputStream) throws IOException {
this.in = new DurboInputStream(inputStream);
this.namespaceByPrefix.put("", "");
this.namespaceByURI.put("", "");
Element elem = this.read();
if (elem == null) {
throw new IOException("Protocol Header expected.");
}
if (!"DurboSer".equals(elem.name())) {
throw new IOException("Wrong Protocol Header Property: " + elem.name());
}
this.version = ((Property)elem).getValues()[0].getDouble();
if (this.version > 2.1) {
throw new IOException("Wrong Protocol Version: " + elem.getString());
}
if (this.version >= 2.0) {
elem = this.read();
if (!"ContentType".equals(elem.name())) {
throw new IOException("Wrong protocol. ContentType expected.");
}
this.contentType = ((Property)elem).getValues()[0].getString();
elem = this.read();
if (!"Encoding".equals(elem.name())) {
throw new IOException("Wrong protocol. Encoding expected.");
}
this.encoding = ((Property)elem).getValues()[0].getString();
if (this.encoding.equals("zip")) {
this.in.enableDecompression();
}
}
}
public String getEncoding() {
return this.encoding;
}
public String getContentType() {
return this.contentType;
}
public double getVersion() {
return this.version;
}
public Element read() throws IOException {
int type = this.in.readType();
if (type == -1) {
return null;
}
if ((type & 16) > 0) {
String name = this.in.readString();
boolean isMulti = (type & 64) > 0;
DurboValue[] values = isMulti ? new DurboValue[this.in.readInt()] : new DurboValue[1];
type &= 15;
block4 : for (int i = 0; i < values.length; ++i) {
switch (type) {
case 1:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12: {
values[i] = new DurboValue(type, this.in.readBinary());
continue block4;
}
default: {
if (this.version >= 2.0) {
throw new IOException("unsupported type: " + type);
}
type = 2;
}
case 2: {
values[i] = this.in.readBinaryValue();
}
}
}
return new Property(name, type, isMulti, values);
}
if (type == 32) {
return new Node(this.in.readString());
}
if (type == 47) {
return new Node();
}
if (type == 33) {
String prefix = this.in.readString();
String uri = this.in.readString();
this.namespaceByPrefix.put(prefix, uri);
this.namespaceByURI.put(uri, prefix);
return this.read();
}
throw new IOException("Unknown element type: " + type);
}
public void skipNode() throws IOException {
Element elem;
while ((elem = this.read()) != null) {
if (elem.isNodeStart()) {
this.skipNode();
continue;
}
if (!elem.isNodeEnd()) continue;
return;
}
throw new EOFException("Unexpected end of input");
}
public String getURI(String prefix) {
return this.namespaceByPrefix.get(prefix);
}
public String getPrefix(String uri) throws NamespaceException {
return this.namespaceByURI.get(uri);
}
public String[] getPrefixes() {
return this.namespaceByPrefix.keySet().toArray(new String[this.namespaceByPrefix.size()]);
}
public String[] getURIs() {
return this.namespaceByURI.keySet().toArray(new String[this.namespaceByURI.size()]);
}
public abstract class Element {
private final String localName;
private final String prefix;
private Element(String name) {
if (name == null) {
this.localName = null;
this.prefix = null;
} else {
int pos = name.indexOf(58);
if (pos > 0) {
this.prefix = name.substring(0, pos);
this.localName = name.substring(pos + 1);
} else {
this.prefix = null;
this.localName = name;
}
}
}
public String name() {
return this.prefix == null ? this.localName : this.prefix + ":" + this.localName;
}
public String prefix() {
return this.prefix;
}
public String uri() {
return this.prefix == null ? null : DurboInput.this.getURI(this.prefix);
}
public String localName() {
return this.localName;
}
public abstract boolean isProperty();
public abstract boolean isNodeStart();
public abstract boolean isNodeEnd();
public abstract String getString();
public String toString() {
if (this.isProperty()) {
return "Property(" + this.name() + ")";
}
if (this.isNodeStart()) {
return "NodeStart(" + this.name() + ")";
}
return "NodeEnd()";
}
public abstract boolean wasBinary();
public abstract boolean wasString();
public abstract long size();
}
public class Node
extends Element {
private final boolean isStart;
public Node(String name) {
this(name, true);
}
public Node() {
this(null, false);
}
public Node(String name, boolean isNodeStart) {
super(name);
this.isStart = isNodeStart;
}
public boolean isProperty() {
return false;
}
public boolean isNodeStart() {
return this.isStart;
}
public boolean isNodeEnd() {
return !this.isStart;
}
public String getString() {
return null;
}
public boolean wasBinary() {
return false;
}
public boolean wasString() {
return false;
}
public long size() {
return 0;
}
}
public class Property
extends Element {
private final int type;
private final boolean isMultiple;
private final DurboValue[] values;
public Property(String name, int type, boolean multiple, DurboValue[] values) {
super(name);
this.type = type;
this.isMultiple = multiple;
this.values = values;
}
public int getType() {
return this.type;
}
public boolean isMultiple() {
return this.isMultiple;
}
public DurboValue[] getValues() {
return this.values;
}
public Value[] getJcrValues(ValueFactory factory) throws IOException, RepositoryException {
Value[] ret = new Value[this.values.length];
for (int i = 0; i < ret.length; ++i) {
ret[i] = this.values[i].toJcrValue(factory);
}
return ret;
}
public boolean isProperty() {
return true;
}
public boolean isNodeStart() {
return false;
}
public boolean isNodeEnd() {
return false;
}
public String getString() {
try {
return this.values.length > 0 ? this.values[0].getString() : "";
}
catch (IOException e) {
return null;
}
}
public boolean wasBinary() {
return this.type == 2;
}
public boolean wasString() {
return this.type != 2;
}
public long size() {
return 0;
}
}
}