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; |
21 |
| |
22 |
| import org.apache.xindice.core.Collection; |
23 |
| import org.apache.xindice.core.DBException; |
24 |
| import org.apache.xindice.core.Database; |
25 |
| import org.apache.xmlrpc.XmlRpcException; |
26 |
| |
27 |
| import org.xmldb.api.base.ErrorCodes; |
28 |
| import org.xmldb.api.base.XMLDBException; |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| public abstract class RPCDefaultMessage implements RPCMessage { |
38 |
| |
39 |
| public static final String API_NAME = "Xindice XML-RPC"; |
40 |
| public static final String API_VERSION = "0.1"; |
41 |
| |
42 |
| public static final String RESULT = "result"; |
43 |
| public static final String NAME = "name"; |
44 |
| public static final String COLLECTION = "collection"; |
45 |
| public static final String DOCUMENT = "document"; |
46 |
| public static final String COMPRESSED = "compressed"; |
47 |
| public static final String TIMESTAMP = "timestamp"; |
48 |
| public static final String PATTERN = "pattern"; |
49 |
| public static final String MAXKEYSIZE = "maxkeysize"; |
50 |
| public static final String PAGESIZE = "pagesize"; |
51 |
| public static final String TYPE = "type"; |
52 |
| public static final String QUERY = "query"; |
53 |
| public static final String NAMESPACES = "namespaces"; |
54 |
| public static final String CONFIGURATION = "configuration"; |
55 |
| public static final String META = "meta"; |
56 |
| |
57 |
| public static final String MISSING_COLLECTION_PARAM = "Required parameter 'collection' not found."; |
58 |
| public static final String MISSING_NAME_PARAM = "Required parameter 'name' not found."; |
59 |
| public static final String MISSING_DOCUMENT_PARAM = "Required parameter 'document' not found."; |
60 |
| public static final String MISSING_PATTERN_PARAM = "Required parameter 'pattern' not found."; |
61 |
| public static final String MISSING_TYPE_PARAM = "Required parameter 'type' not found."; |
62 |
| public static final String MISSING_QUERY_PARAM = "Required parameter 'query' not found."; |
63 |
| public static final String MISSING_TIMESTAMP_PARAM = "For compressed results a timestamp must be provided."; |
64 |
| public static final String MISSING_CONFIGURATION_PARAM = "You must either provide a document containing the configuration or specify the 'name' and 'patter' parameters."; |
65 |
| public static final String MISSING_META_CONFIGURATION = "Meta information requested but not enabled"; |
66 |
| public static final String MISSING_META_PARAM = "Required parameter 'meta' not found"; |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
| |
72 |
| |
73 |
| |
74 |
| |
75 |
2381
| protected Collection getCollection(String name) throws XmlRpcException, XMLDBException, DBException {
|
76 |
| |
77 |
2381
| while (name.endsWith("/")) {
|
78 |
1
| name = name.substring(0, name.lastIndexOf("/"));
|
79 |
| } |
80 |
| |
81 |
| |
82 |
2381
| if (name.startsWith("/")) {
|
83 |
| |
84 |
2381
| int colIndex = name.indexOf('/', 1);
|
85 |
| |
86 |
| |
87 |
2381
| String dbName = name.substring(1);
|
88 |
2381
| String colName = "/";
|
89 |
| |
90 |
| |
91 |
2381
| if (colIndex != -1) {
|
92 |
2372
| dbName = name.substring(1, colIndex);
|
93 |
| |
94 |
| |
95 |
2372
| colName = name.substring(colIndex + 1);
|
96 |
| } |
97 |
| |
98 |
2381
| Database db = Database.getDatabase(dbName);
|
99 |
2381
| if (db == null) {
|
100 |
1
| throw new XMLDBException(ErrorCodes.NO_SUCH_DATABASE,
|
101 |
| "Database '" + dbName + "' could not be found"); |
102 |
| } |
103 |
| |
104 |
2380
| Collection col = db.getCollection(colName);
|
105 |
2380
| if (col == null) {
|
106 |
1
| throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION,
|
107 |
| "Collection '" + colName + "' could not be found"); |
108 |
| } |
109 |
| |
110 |
2379
| return col;
|
111 |
| } else { |
112 |
0
| throw new XMLDBException(ErrorCodes.INVALID_URI,
|
113 |
| "Collection name must begin with a '/'"); |
114 |
| } |
115 |
| } |
116 |
| } |