1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| package org.apache.xindice.server.rpc.messages; |
21 |
| |
22 |
| import org.apache.commons.logging.Log; |
23 |
| import org.apache.commons.logging.LogFactory; |
24 |
| import org.apache.xindice.core.Collection; |
25 |
| import org.apache.xindice.core.data.Entry; |
26 |
| import org.apache.xindice.server.rpc.RPCDefaultMessage; |
27 |
| import org.apache.xindice.util.SymbolSerializer; |
28 |
| import org.apache.xindice.xml.TextWriter; |
29 |
| import org.apache.xindice.xml.dom.CompressedDocument; |
30 |
| |
31 |
| import org.w3c.dom.Document; |
32 |
| |
33 |
| import java.util.HashMap; |
34 |
| import java.util.Map; |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| public class GetResource extends RPCDefaultMessage { |
41 |
| |
42 |
176
| public Map execute(Map message) throws Exception {
|
43 |
176
| if (!message.containsKey(COLLECTION)) {
|
44 |
0
| throw new Exception(MISSING_COLLECTION_PARAM);
|
45 |
| } |
46 |
| |
47 |
176
| if (!message.containsKey(NAME)) {
|
48 |
0
| throw new Exception(MISSING_NAME_PARAM);
|
49 |
| } |
50 |
| |
51 |
176
| Collection col = getCollection((String) message.get(COLLECTION));
|
52 |
176
| Entry obj = col.getEntry(message.get(NAME));
|
53 |
| |
54 |
176
| Map result = new HashMap(3);
|
55 |
176
| if (obj == null) {
|
56 |
| |
57 |
| |
58 |
171
| } else if (obj.getEntryType() == Entry.BINARY) {
|
59 |
| |
60 |
2
| result.put(RESULT, obj.getValue());
|
61 |
| |
62 |
169
| } else if (message.containsKey(COMPRESSED)) {
|
63 |
| |
64 |
| |
65 |
| |
66 |
169
| CompressedDocument doc = (CompressedDocument) obj.getValue();
|
67 |
169
| if (doc.getDataBytes() != null) {
|
68 |
169
| SymbolSerializer symbolSerializer = new SymbolSerializer(col.getSymbols());
|
69 |
| |
70 |
| |
71 |
169
| long timestamp = 0;
|
72 |
169
| if (message.containsKey(TIMESTAMP)) {
|
73 |
169
| timestamp = Long.parseLong((String) message.get("timestamp"));
|
74 |
| } |
75 |
| |
76 |
169
| result.put(RESULT, symbolSerializer.serialize(doc, timestamp));
|
77 |
| } else { |
78 |
0
| result.put(RESULT, TextWriter.toString(doc));
|
79 |
| } |
80 |
| |
81 |
| } else { |
82 |
| |
83 |
0
| Document doc = (Document) obj.getValue();
|
84 |
0
| result.put(RESULT, TextWriter.toString(doc));
|
85 |
| } |
86 |
| |
87 |
176
| return result;
|
88 |
| } |
89 |
| } |