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.client.xmldb.services.CollectionManager; |
23 |
| import org.apache.xindice.tools.XMLTools; |
24 |
| |
25 |
| import org.xmldb.api.DatabaseManager; |
26 |
| import org.xmldb.api.base.Collection; |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| public class DeleteCollection extends Command { |
36 |
| |
37 |
0
| public boolean execute(XMLTools.Config table) throws Exception {
|
38 |
| |
39 |
| |
40 |
0
| if (table.getString(XMLTools.COLLECTION) == null) {
|
41 |
0
| System.out.println("ERROR : Collection and switch required");
|
42 |
0
| return false;
|
43 |
| } |
44 |
| |
45 |
0
| if (table.getString(XMLTools.NAME_OF) == null) {
|
46 |
0
| System.out.println("ERROR : Name and switch required");
|
47 |
0
| return false;
|
48 |
| } |
49 |
| |
50 |
0
| Collection col = null;
|
51 |
0
| try {
|
52 |
| |
53 |
0
| String colstring = normalizeCollectionURI(table.getString(XMLTools.COLLECTION),
|
54 |
| table.getBoolean(XMLTools.LOCAL)); |
55 |
0
| col = DatabaseManager.getCollection(colstring);
|
56 |
0
| if (col == null) {
|
57 |
0
| System.out.println("ERROR : Collection not found!");
|
58 |
0
| return false;
|
59 |
| } |
60 |
| |
61 |
| |
62 |
0
| CollectionManager colman = (CollectionManager) col.getService("CollectionManager", XMLDBAPIVERSION);
|
63 |
| |
64 |
| |
65 |
0
| colman.dropCollection(table.getString(XMLTools.NAME_OF));
|
66 |
| |
67 |
0
| System.out.println("Deleted: " + table.getString(XMLTools.COLLECTION) + "/" + table.getString(XMLTools.NAME_OF));
|
68 |
| |
69 |
| } finally { |
70 |
0
| if (col != null) {
|
71 |
0
| col.close();
|
72 |
| } |
73 |
| } |
74 |
| |
75 |
0
| return true;
|
76 |
| } |
77 |
| |
78 |
0
| public void usage() {
|
79 |
0
| System.out.println("Format: xindice dc -c <context> [-l [-d <path>]] [-v] [parameters...]");
|
80 |
0
| System.out.println();
|
81 |
0
| System.out.println("Drops a collection from the database or parent collection");
|
82 |
0
| System.out.println();
|
83 |
0
| System.out.println("Command-specific switches:");
|
84 |
0
| System.out.println(" -n|--nameOf <name>");
|
85 |
0
| System.out.println(" Name of the collection to be deleted");
|
86 |
0
| System.out.println();
|
87 |
| } |
88 |
| } |