|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| package org.apache.xindice.tools.command; |
|
21 |
| |
|
22 |
| import org.apache.xindice.tools.XMLTools; |
|
23 |
| |
|
24 |
| import org.xmldb.api.DatabaseManager; |
|
25 |
| import org.xmldb.api.base.Collection; |
|
26 |
| import org.xmldb.api.base.Resource; |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| public class DeleteDocument extends Command { |
|
36 |
| |
|
37 |
0
| public boolean execute(XMLTools.Config table) throws Exception {
|
|
38 |
0
| if (table.getString(XMLTools.COLLECTION) == null) {
|
|
39 |
0
| System.out.println("ERROR : Collection and switch required");
|
|
40 |
0
| return false;
|
|
41 |
| } |
|
42 |
| |
|
43 |
0
| if (table.getString(XMLTools.NAME_OF) == null) {
|
|
44 |
0
| System.out.println("ERROR : Document Key and switch required");
|
|
45 |
0
| return false;
|
|
46 |
| } |
|
47 |
| |
|
48 |
0
| Collection col = null;
|
|
49 |
0
| try {
|
|
50 |
| |
|
51 |
0
| String colstring = normalizeCollectionURI(table.getString(XMLTools.COLLECTION),
|
|
52 |
| table.getBoolean(XMLTools.LOCAL)); |
|
53 |
| |
|
54 |
0
| col = DatabaseManager.getCollection(colstring);
|
|
55 |
0
| if (col == null) {
|
|
56 |
0
| System.out.println("ERROR : Collection not found!");
|
|
57 |
0
| return false;
|
|
58 |
| } |
|
59 |
| |
|
60 |
0
| Resource colresource = col.getResource(table.getString(XMLTools.NAME_OF));
|
|
61 |
| |
|
62 |
0
| col.removeResource(colresource);
|
|
63 |
0
| System.out.println("DELETED: " + table.getString(XMLTools.COLLECTION) + "/" + table.getString(XMLTools.NAME_OF));
|
|
64 |
| } finally { |
|
65 |
0
| if (col != null) {
|
|
66 |
0
| col.close();
|
|
67 |
| } |
|
68 |
| } |
|
69 |
| |
|
70 |
0
| return true;
|
|
71 |
| } |
|
72 |
| |
|
73 |
0
| public void usage() {
|
|
74 |
0
| System.out.println("Format: xindice dd -c <context> [-l [-d <path>]] [-v] [parameters...]");
|
|
75 |
0
| System.out.println();
|
|
76 |
0
| System.out.println("Deletes a document/binary resource, referred by the key, from a specific");
|
|
77 |
0
| System.out.println("collection");
|
|
78 |
0
| System.out.println();
|
|
79 |
0
| System.out.println("Command-specific switches:");
|
|
80 |
0
| System.out.println(" -n|--nameOf <name>");
|
|
81 |
0
| System.out.println(" Key of the resource to be deleted");
|
|
82 |
0
| System.out.println();
|
|
83 |
0
| System.out.println("Examples:");
|
|
84 |
0
| System.out.println(" xindice dd -c /db/test -n myxmldocument");
|
|
85 |
0
| System.out.println();
|
|
86 |
| } |
|
87 |
| } |