source: trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2Construct.java@ 3649

Last change on this file since 3649 was 3649, checked in by kjdon, 21 years ago

tidy up of services. MGPPGDBMServices replaced with GS2MGPPSearch and GS2MGPPRetrieve. MGGDBMServices replaced with GS2MGSearch and GS2MGRetrieve. GSDL2ClassifierServices replaced with GS2Browse. PerlBuildServices replaced with GS2Construct. ServicesImpl replaced with ServiceRack.

  • Property svn:keywords set to Author Date Id Revision
File size: 22.3 KB
Line 
1/*
2 * GS2Construct.java
3 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19package org.greenstone.gsdl3.service;
20
21import org.greenstone.gsdl3.util.*;
22import org.greenstone.gsdl3.build.*;
23
24import org.w3c.dom.Document;
25import org.w3c.dom.Node;
26import org.w3c.dom.Text;
27import org.w3c.dom.Element;
28import org.w3c.dom.NodeList;
29
30import java.util.Collections;
31import java.util.HashMap;
32import java.util.Map;
33import java.util.List;
34import java.util.ArrayList;
35import java.io.File;
36import java.util.Locale;
37
38/**
39 * A Services class for building collections
40 * provides a wrapper around the old perl scripts
41 *
42 * @author <a href="mailto:[email protected]">Katherine Don</a>
43 * @version $Revision: 3649 $
44 */
45public class GS2Construct
46 extends ServiceRack { //implements ConstructionEventListener {
47
48 // services offered
49 private static final String NEW_SERVICE = "NewCollection";
50 private static final String IMPORT_SERVICE = "ImportCollection";
51 private static final String BUILD_SERVICE = "BuildCollection";
52 private static final String ACTIVATE_SERVICE = "ActivateCollection";
53 private static final String DELETE_SERVICE = "DeleteCollection";
54 private static final String RELOAD_SERVICE = "ReloadCollection";
55
56 // params used
57 private static final String COL_PARAM = "collection";
58 private static final String NEW_COL_NAME_PARAM = "collectionName";
59 private static final String CREATOR_PARAM = "creator";
60 private static final String HANDLE_PARAM = "id";
61
62 //private static final String STATUS_PARAM = "us";
63 // the list of the collections - store between some method calls
64 private String[] collection_list_ = null;
65
66 // set of listeners for nay construciton commands
67 protected Map listeners_ = null;
68
69 public GS2Construct() {
70 listeners_ = Collections.synchronizedMap(new HashMap());
71 }
72
73 /** returns the service list for the subclass */
74 protected Element getServiceList(String lang) {
75 // for now, it is static and there is no lang stuff
76 return short_service_info_;
77 }
78
79 /** returns a specific service description */
80 protected Element getServiceDescription(String service, String lang) {
81 Element descript = (Element)((Element)service_info_map_.get(service)).cloneNode(true);
82 // need to add in collection param list
83 if (!service.equals(NEW_SERVICE)) {
84 Element param_list = (Element) GSXML.getChildByTagName(descript, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
85 Element old_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, COL_PARAM);
86 collection_list_ = getCollectionList();
87 Element param = GSXML.createParameter(doc_, COL_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, null, collection_list_);
88 // put at front of the list
89 param_list.replaceChild(param, old_param);
90 }
91 // for now, create it on the fly - look at caching it later
92 Element display = createServiceDisplay(service, lang);
93 addServiceDisplay(descript, display);
94 return descript;
95
96 }
97
98 /** creates a display element containing all the text strings needed to display the service page, in the language specified */
99 protected Element createServiceDisplay(String service, String lang) {
100 Element display = doc_.createElement(GSXML.DISPLAY_ELEM);
101 display.appendChild(GSXML.createTextElement(doc_, GSXML.DISPLAY_NAME_ELEM, getTextString(service+".name", lang)));
102 display.appendChild(GSXML.createTextElement(doc_, GSXML.DISPLAY_SUBMIT_ELEM, getTextString(service+".submit", lang)));
103
104 Element param;
105 if (service.equals(NEW_SERVICE)) {
106 // have the coll name and creator params
107 param = GSXML.createParameterDisplay(doc_, NEW_COL_NAME_PARAM, getTextString("param."+NEW_COL_NAME_PARAM, lang), null, null);
108 display.appendChild(param);
109 param = GSXML.createParameterDisplay(doc_, CREATOR_PARAM, getTextString("param."+CREATOR_PARAM, lang), null, null);
110 display.appendChild(param);
111 } else {
112 // have just the coll param
113 //use the colleciton list already created - this method is only called directly after getServiceDescription()
114 param = GSXML.createParameterDisplay(doc_, COL_PARAM, getTextString("param."+COL_PARAM, lang), collection_list_, collection_list_);
115 display.appendChild(param);
116 }
117
118 return display;
119
120 }
121
122 /** passes the request Element to the appropriate service function*/
123 protected Element processService(String name, Element request) {
124
125 System.out.println("perl build request = ");
126 System.out.println(converter_.getString(request));
127 String language = request.getAttribute(GSXML.LANG_ATT);
128 String request_type = request.getAttribute(GSXML.TYPE_ATT);
129 boolean get_status_only = false;
130 if (request_type.equals(GSXML.REQUEST_TYPE_STATUS)) {
131 get_status_only = true;
132 }
133 System.out.println("get status only = "+get_status_only);
134 // extract the collection out of here
135 Element param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
136 HashMap params = GSXML.extractParams(param_list);
137 String coll_name = (String)params.get(COL_PARAM);
138
139 String id = (String)params.get(HANDLE_PARAM);
140
141 Element response = doc_.createElement(GSXML.RESPONSE_ELEM);
142 response.setAttribute(GSXML.FROM_ATT, name);
143 Element status=null;
144 if (name.equals(NEW_SERVICE)) {
145 // need to do something different here
146 status = newCollection(coll_name, language, get_status_only);
147 } else if (name.equals(IMPORT_SERVICE)) {
148 status = importCollection(coll_name, language, get_status_only, id);
149 } else if (name.equals(BUILD_SERVICE)) {
150 status = buildCollection(coll_name, language, get_status_only, id);
151 } else if (name.equals(ACTIVATE_SERVICE)) {
152 status = activateCollection(coll_name, language, get_status_only);
153 } else if (name.equals(DELETE_SERVICE)) {
154 status = deleteCollection(coll_name, language, get_status_only);
155 } else if (name.equals(RELOAD_SERVICE)) {
156 status = reloadCollection(coll_name, language, get_status_only);
157 }
158
159 if (status !=null) {
160 response.appendChild(status);
161 return response;
162 } else {
163 System.err.println("error: status is null!");
164 return response;
165 }
166
167 //System.err.println("GS2Construct: should never get here. service type wrong:"+name);
168 //return null;
169
170 }
171
172 /** configure the service module
173 * for now, all services have type=build - need to think about this
174 */
175 public boolean configure(Element info) {
176 System.out.println("configuring GS2Construct");
177
178 Element e = null;
179 // hard code in the services for now
180
181 // set up short_service_info_ - for now just has name and type
182
183 e = doc_.createElement(GSXML.SERVICE_ELEM);
184 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BUILD);
185 e.setAttribute(GSXML.NAME_ATT, NEW_SERVICE);
186 short_service_info_.appendChild(e);
187
188 e = doc_.createElement(GSXML.SERVICE_ELEM);
189 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BUILD);
190 e.setAttribute(GSXML.NAME_ATT, IMPORT_SERVICE);
191 short_service_info_.appendChild(e);
192
193 e = doc_.createElement(GSXML.SERVICE_ELEM);
194 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BUILD);
195 e.setAttribute(GSXML.NAME_ATT, BUILD_SERVICE);
196 short_service_info_.appendChild(e);
197
198 e = doc_.createElement(GSXML.SERVICE_ELEM);
199 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BUILD);
200 e.setAttribute(GSXML.NAME_ATT, ACTIVATE_SERVICE);
201 short_service_info_.appendChild(e);
202
203 e = doc_.createElement(GSXML.SERVICE_ELEM);
204 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BUILD);
205 e.setAttribute(GSXML.NAME_ATT, DELETE_SERVICE);
206 short_service_info_.appendChild(e);
207
208 e = doc_.createElement(GSXML.SERVICE_ELEM);
209 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BUILD);
210 e.setAttribute(GSXML.NAME_ATT, RELOAD_SERVICE);
211 short_service_info_.appendChild(e);
212
213 //e = doc_.createElement(GSXML.SERVICE_ELEM);
214 //e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BUILD);
215 //e.setAttribute(GSXML.NAME_ATT, "AddDocument");
216 //short_service_info_.appendChild(e);
217
218 // set up service_info_map_ - for now, just has the same elements as above
219
220 Element param_list;
221 Element param;
222
223 String lang = Locale.US.toString();
224
225 // should have full details about each service incl params lists etc.
226 e = doc_.createElement(GSXML.SERVICE_ELEM);
227 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BUILD);
228 e.setAttribute(GSXML.NAME_ATT, NEW_SERVICE);
229 param_list = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
230 param = GSXML.createParameter(doc_, NEW_COL_NAME_PARAM, GSXML.PARAM_TYPE_STRING, "", null);
231 param_list.appendChild(param);
232 param = GSXML.createParameter(doc_, CREATOR_PARAM, GSXML.PARAM_TYPE_STRING, "", null);
233 param_list.appendChild(param);
234 e.appendChild(param_list);
235 service_info_map_.put(NEW_SERVICE, e);
236
237 e = doc_.createElement(GSXML.SERVICE_ELEM);
238 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BUILD);
239 e.setAttribute(GSXML.NAME_ATT, IMPORT_SERVICE);
240 param_list = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
241 param = GSXML.createParameter(doc_, COL_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, "", null);
242 param_list.appendChild(param);
243 e.appendChild(param_list);
244 service_info_map_.put(IMPORT_SERVICE, e);
245
246 e = doc_.createElement(GSXML.SERVICE_ELEM);
247 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BUILD);
248 e.setAttribute(GSXML.NAME_ATT, BUILD_SERVICE);
249 param_list = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
250 param = GSXML.createParameter(doc_, COL_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, "", null);
251 param_list.appendChild(param);
252 e.appendChild(param_list);
253 service_info_map_.put(BUILD_SERVICE, e);
254
255 e = doc_.createElement(GSXML.SERVICE_ELEM);
256 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BUILD);
257 e.setAttribute(GSXML.NAME_ATT, ACTIVATE_SERVICE);
258 param_list = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
259 param = GSXML.createParameter(doc_, COL_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, "", null);
260 param_list.appendChild(param);
261 e.appendChild(param_list);
262 service_info_map_.put(ACTIVATE_SERVICE, e);
263
264 e = doc_.createElement(GSXML.SERVICE_ELEM);
265 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BUILD);
266 e.setAttribute(GSXML.NAME_ATT, DELETE_SERVICE);
267 param_list = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
268 param = GSXML.createParameter(doc_, COL_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, "", null);
269 param_list.appendChild(param);
270 e.appendChild(param_list);
271 service_info_map_.put(DELETE_SERVICE, e);
272
273 e = doc_.createElement(GSXML.SERVICE_ELEM);
274 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BUILD);
275 e.setAttribute(GSXML.NAME_ATT, RELOAD_SERVICE);
276 param_list = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
277 param = GSXML.createParameter(doc_, COL_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, "", null);
278 param_list.appendChild(param);
279 e.appendChild(param_list);
280 service_info_map_.put(RELOAD_SERVICE, e);
281
282
283 return true;
284 }
285
286 /** creates a new collection using mkcol.pl */
287 protected Element newCollection(String coll_name, String lang, boolean get_status_only) {
288 Element status = doc_.createElement(GSXML.STATUS_ELEM);
289 Text t;
290 if (get_status_only) {
291 t = doc_.createTextNode("status for create new coll:"+coll_name);
292 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.SUCCESS));
293 } else {
294 t = doc_.createTextNode("trying to start to create new coll:"+coll_name);
295 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ACCEPTED));
296
297 }
298 status.appendChild(t);
299 return status;
300 }
301
302 /** imports a collection using import.pl */
303 protected Element importCollection(String coll_name, String lang, boolean get_status_only, String id) {
304
305 if (get_status_only) {
306
307 Element status = doc_.createElement(GSXML.STATUS_ELEM);
308 GS2PerlListener listener = (GS2PerlListener)listeners_.get(id);
309 if (listener==null) {
310 Text t = doc_.createTextNode("invalid id error");
311 status.appendChild(t);
312 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ERROR));
313 } else {
314 Text t = doc_.createTextNode(listener.getUpdate());
315 status.appendChild(t);
316 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(listener.getStatus()));
317 if (listener.isFinished()) { // remove this listener - its job is done
318 listeners_.remove(id); // not working
319 }
320 }
321 return status;
322 }
323
324 // do the actual import
325 CollectionConstructor constructor = new GS2PerlConstructor("perl_build");
326 constructor.setSiteHome(site_home_);
327 constructor.setCollectionName(coll_name);
328 constructor.setActionType(CollectionConstructor.IMPORT);
329
330 // the listener
331 GS2PerlListener listener = new GS2PerlListener();
332 constructor.addListener(listener);
333 constructor.start();
334
335 id = newID();
336 listeners_.put(id, listener);
337
338 Element status = doc_.createElement(GSXML.STATUS_ELEM);
339 status.setAttribute(GSXML.STATUS_PROCESS_ID_ATT, id);
340 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ACCEPTED));
341 Text t = doc_.createTextNode("starting");
342 status.appendChild(t);
343 return status;
344 }
345 /** builds a collection using buildcol.pl */
346 protected Element buildCollection(String coll_name, String lang, boolean get_status_only, String id) {
347
348 if (get_status_only) {
349
350 Element status = doc_.createElement(GSXML.STATUS_ELEM);
351 GS2PerlListener listener = (GS2PerlListener)listeners_.get(id);
352 if (listener==null) {
353 Text t = doc_.createTextNode("invalid id error");
354 status.appendChild(t);
355 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ERROR));
356 } else {
357 Text t = doc_.createTextNode(listener.getUpdate());
358 status.appendChild(t);
359 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(listener.getStatus()));
360 if (listener.isFinished()) { // remove this listener - its job is done
361 System.out.println("listener is finished, remove it");
362 listeners_.remove(id); // not working
363 }
364 }
365 return status;
366 }
367
368 // do the actual import
369 CollectionConstructor constructor = new GS2PerlConstructor("perl_build");
370 constructor.setSiteHome(site_home_);
371 constructor.setCollectionName(coll_name);
372 constructor.setActionType(CollectionConstructor.BUILD);
373
374 // the listener
375 GS2PerlListener listener = new GS2PerlListener();
376 constructor.addListener(listener);
377 constructor.start();
378
379 id = newID();
380 listeners_.put(id, listener);
381
382 Element status = doc_.createElement(GSXML.STATUS_ELEM);
383 status.setAttribute(GSXML.STATUS_PROCESS_ID_ATT, id);
384 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ACCEPTED));
385 Text t = doc_.createTextNode("starting");
386 status.appendChild(t);
387 return status;
388
389 /*Element status = doc_.createElement(GSXML.STATUS_ELEM);
390 Text t;
391 if (get_status_only) {
392 t = doc_.createTextNode("status for build coll:"+coll_name);
393 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.SUCCESS));
394 } else {
395 t= doc_.createTextNode("trying to build coll:"+coll_name);
396 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ACCEPTED));
397 }
398 status.appendChild(t);
399 return status;*/
400 }
401 protected Element reloadCollection(String coll_name, String lang, boolean get_status_only) {
402 Element status = doc_.createElement(GSXML.STATUS_ELEM);
403 Text t;
404 if (get_status_only) { // this makes no sense for this service
405 t = doc_.createTextNode("no status for reload coll:"+coll_name);
406 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.SUCCESS));
407 } else {
408 Element message = doc_.createElement(GSXML.MESSAGE_ELEM);
409 Element request = doc_.createElement(GSXML.REQUEST_ELEM);
410 request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_CONFIGURE);
411 request.setAttribute(GSXML.TO_ATT, "");
412 message.appendChild(request);
413 Element command = doc_.createElement(GSXML.CONFIGURE_ELEM);
414 command.setAttribute(GSXML.TYPE_ATT, GSXML.COLLECTION_ELEM);
415 command.setAttribute(GSXML.NAME_ATT, coll_name);
416 command.setAttribute(GSXML.ACTION_ATT, GSXML.CONFIG_ACTION_ACTIVATE);
417 request.appendChild(command);
418 Element response = router_.process(message); // at the moment, get no info in response so ignore it
419
420 String[] args={coll_name};
421
422 if (response == null) {
423 t = doc_.createTextNode(getTextString("reload.activate_error", args , lang));
424 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ERROR));
425 status.appendChild(t);
426 return status;
427 }
428
429 // if we got here, we have succeeded!
430 t = doc_.createTextNode(getTextString("reload.success", args, lang));
431 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.SUCCESS));
432 }
433 status.appendChild(t);
434 return status;
435 }
436
437 /** activates a collection by removing index, copying building over
438 * also instructs the MR to activate this new/modified collection
439 * fails if no valid building directory */
440 protected Element activateCollection(String coll_name, String lang, boolean get_status_only) {
441 // the return element
442 Element status = doc_.createElement(GSXML.STATUS_ELEM);
443 Text t;
444 if (get_status_only) { // makes no sense
445 t = doc_.createTextNode("no status for activate coll:"+coll_name);
446 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ACCEPTED));
447 status.appendChild(t);
448 return status;
449 }
450
451 String[] args={coll_name};
452
453 // check that we have buildcfg.xml in the building directory
454 File coll_build_dir = new File(GSFile.collectionBuildDir(site_home_, coll_name));
455 if (!coll_build_dir.exists()) {
456 t = doc_.createTextNode(getTextString("activate.build_dir_error", args, lang));
457 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ERROR));
458 status.appendChild(t);
459 return status;
460 }
461
462 /*
463 File coll_build_file = new File(GSFile.collectionBuildConfigFileBuilding(site_home_, coll_name));
464 if (!coll_build_file.exists()) {
465 t = doc_.createTextNode(getTextString("activate.build_config_error", args, lang));
466 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ERROR));
467 status.appendChild(t);
468 return status;
469 }
470
471
472 File coll_index_dir = new File(GSFile.collectionIndexDir(site_home_, coll_name));
473 if (coll_index_dir.exists()) {
474 // remove it
475 if (!GSFile.deleteFile(coll_index_dir)) {
476 t = doc_.createTextNode(getTextString("activate.rm_index_error", args, lang));
477 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ERROR));
478 status.appendChild(t);
479 return status;
480 }
481 }
482
483 // copy building to index
484 if (!GSFile.moveDirectory(coll_build_dir, coll_index_dir)) {
485 t = doc_.createTextNode(getTextString("activate.rename_building_error", args, lang));
486 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ERROR));
487 status.appendChild(t);
488 return status;
489 }
490 */
491 // now have to tell the message router
492 return reloadCollection(coll_name, lang, get_status_only);
493
494 }
495 /** deletes a collection - removes the whole directory
496 * also instructs the MR to deactivate this collection*/
497 protected Element deleteCollection(String coll_name, String lang, boolean get_status_only) {
498
499 Element status = doc_.createElement(GSXML.STATUS_ELEM);
500 Text t;
501 if (get_status_only) {
502 t = doc_.createTextNode("no status for delete coll:"+coll_name);
503 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ACCEPTED));
504 status.appendChild(t);
505 return status;
506 }
507
508 String[] args={coll_name};
509 File coll_dir = new File(GSFile.collectionBaseDir(site_home_, coll_name));
510 if (coll_dir.exists()) {
511 if (!GSFile.deleteFile(coll_dir)) {
512 t = doc_.createTextNode(getTextString("delete.delete_error", args, lang));
513 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ERROR));
514 status.appendChild(t);
515 return status;
516 }
517 // now tell the MR about it
518
519 Element message = doc_.createElement(GSXML.MESSAGE_ELEM);
520 Element request = doc_.createElement(GSXML.REQUEST_ELEM);
521 request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_CONFIGURE);
522 request.setAttribute(GSXML.TO_ATT, "");
523 message.appendChild(request);
524 Element command = doc_.createElement(GSXML.CONFIGURE_ELEM);
525 command.setAttribute(GSXML.TYPE_ATT, GSXML.COLLECTION_ELEM);
526 command.setAttribute(GSXML.NAME_ATT, coll_name);
527 command.setAttribute(GSXML.ACTION_ATT, GSXML.CONFIG_ACTION_DEACTIVATE);
528 request.appendChild(command);
529
530 Element response = router_.process(message); // at the moment, get no info in response so ignore it
531 if (response == null) {
532 t = doc_.createTextNode(getTextString("delete.deactivate_error", args, lang));
533 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ERROR));
534 status.appendChild(t);
535 return status;
536 }
537 }
538 // success
539
540 t = doc_.createTextNode(getTextString("delete.success", args, lang));
541 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ACCEPTED));
542 status.appendChild(t);
543 return status;
544 }
545
546 protected String[] getCollectionList() {
547
548 File collectDir = new File(GSFile.collectDir(site_home_));
549 if (!collectDir.exists()) {
550 System.err.println("couldn't find collect dir: "+collectDir.toString());
551 return null;
552 }
553 System.out.println("GS2Construct: reading thru directory "+collectDir.getPath()+" to find collections.");
554 File[] contents = collectDir.listFiles();
555 int num_colls=0;
556 for (int i=0; i<contents.length;i++) {
557 if(contents[i].isDirectory() && !contents[i].getName().startsWith("CVS")) {
558 num_colls ++;
559 }
560 }
561
562 String[] names= new String[num_colls];
563
564 for (int i=0, j=0; i<contents.length;i++) {
565 if(contents[i].isDirectory()) {
566 String colName = contents[i].getName();
567 if (!colName.startsWith("CVS")) {
568 names[j] = colName;
569 j++;
570 }
571
572 }
573 }
574
575 return names;
576
577 }
578
579 private int current_id = 0;
580 private String newID() {
581 current_id++;
582 return Integer.toString(current_id);
583 }
584}
Note: See TracBrowser for help on using the repository browser.