source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GS2Construct.java@ 24888

Last change on this file since 24888 was 24888, checked in by sjm84, 12 years ago

Some further changes to help Greenstone 3 use Perl

  • 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
38import org.apache.log4j.*;
39
40/**
41 * A Services class for building collections provides a wrapper around the old
42 * perl scripts
43 *
44 * @author <a href="mailto:[email protected]">Katherine Don</a>
45 * @version $Revision: 24888 $
46 */
47public class GS2Construct extends ServiceRack
48{
49
50 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GS2Construct.class.getName());
51
52 // services offered
53 private static final String NEW_SERVICE = "NewCollection";
54 private static final String ADD_DOC_SERVICE = "AddDocument";
55 private static final String IMPORT_SERVICE = "ImportCollection";
56 private static final String BUILD_SERVICE = "BuildCollection";
57 private static final String ACTIVATE_SERVICE = "ActivateCollection";
58 private static final String DELETE_SERVICE = "DeleteCollection";
59 private static final String RELOAD_SERVICE = "ReloadCollection";
60
61 // params used
62 private static final String COL_PARAM = "collection";
63 private static final String NEW_COL_TITLE_PARAM = "collTitle";
64 private static final String NEW_COL_ABOUT_PARAM = "collAbout";
65 private static final String CREATOR_PARAM = "creator";
66 private static final String NEW_FILE_PARAM = "newfile";
67 private static final String PROCESS_ID_PARAM = GSParams.PROCESS_ID;
68 private static final String BUILDTYPE_PARAM = "buildType";
69 private static final String BUILDTYPE_MG = "mg";
70 private static final String BUILDTYPE_MGPP = "mgpp";
71
72 // the list of the collections - store between some method calls
73 private String[] collection_list = null;
74
75 // set of listeners for any construction commands
76 protected Map listeners = null;
77
78 public GS2Construct()
79 {
80 this.listeners = Collections.synchronizedMap(new HashMap());
81
82 }
83
84 /** returns a specific service description */
85 protected Element getServiceDescription(String service, String lang, String subset)
86 {
87
88 Element description = this.doc.createElement(GSXML.SERVICE_ELEM);
89 description.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_PROCESS);
90 description.setAttribute(GSXML.NAME_ATT, service);
91 if (subset == null || subset.equals(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER))
92 {
93 description.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_NAME, getTextString(service + ".name", lang)));
94 description.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_DESCRIPTION, getTextString(service + ".description", lang)));
95 description.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_SUBMIT, getTextString(service + ".submit", lang)));
96 }
97 if (subset == null || subset.equals(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER))
98 {
99 Element param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
100 description.appendChild(param_list);
101
102 if (service.equals(NEW_SERVICE))
103 {
104
105 Element param = GSXML.createParameterDescription(this.doc, NEW_COL_TITLE_PARAM, getTextString("param." + NEW_COL_TITLE_PARAM, lang), GSXML.PARAM_TYPE_STRING, null, null, null);
106 param_list.appendChild(param);
107 param = GSXML.createParameterDescription(this.doc, CREATOR_PARAM, getTextString("param." + CREATOR_PARAM, lang), GSXML.PARAM_TYPE_STRING, null, null, null);
108 param_list.appendChild(param);
109 param = GSXML.createParameterDescription(this.doc, NEW_COL_ABOUT_PARAM, getTextString("param." + NEW_COL_ABOUT_PARAM, lang), GSXML.PARAM_TYPE_TEXT, null, null, null);
110 param_list.appendChild(param);
111 String[] types = { BUILDTYPE_MGPP, BUILDTYPE_MG };
112 String[] type_texts = { getTextString("param." + BUILDTYPE_PARAM + "." + BUILDTYPE_MGPP, lang), getTextString("param." + BUILDTYPE_PARAM + "." + BUILDTYPE_MG, lang) };
113
114 param = GSXML.createParameterDescription(this.doc, BUILDTYPE_PARAM, getTextString("param." + BUILDTYPE_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, BUILDTYPE_MGPP, types, type_texts);
115 param_list.appendChild(param);
116 }
117 else if (service.equals(ACTIVATE_SERVICE) || service.equals(IMPORT_SERVICE) || service.equals(BUILD_SERVICE) || service.equals(RELOAD_SERVICE) || service.equals(DELETE_SERVICE))
118 {
119
120 this.collection_list = getCollectionList();
121 Element param = GSXML.createParameterDescription(this.doc, COL_PARAM, getTextString("param." + COL_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, null, this.collection_list, this.collection_list);
122 param_list.appendChild(param);
123 }
124 else
125 {
126 // invalid service name
127 return null;
128 }
129 }
130 return description;
131 }
132
133 // each service must have a method "process<New service name>"
134
135 protected Element processNewCollection(Element request)
136 {
137 return runCommand(request, GS2PerlConstructor.NEW);
138 }
139
140 /** TODO:implement this */
141 protected Element processAddDocument(Element request)
142 {
143 // decode the file name, add it to the import directory
144 String name = GSPath.getFirstLink(request.getAttribute(GSXML.TO_ATT));
145 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
146 response.setAttribute(GSXML.FROM_ATT, name);
147 Element status = this.doc.createElement(GSXML.STATUS_ELEM);
148 response.appendChild(status);
149 //String lang = request.getAttribute(GSXML.LANG_ATT);
150 //String request_type = request.getAttribute(GSXML.TYPE_ATT);
151 Text t = this.doc.createTextNode("AddDocument: not implemented yet");
152 status.appendChild(t);
153 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ERROR));
154 return response;
155 }
156
157 protected Element processImportCollection(Element request)
158 {
159 return runCommand(request, GS2PerlConstructor.IMPORT);
160 }
161
162 protected Element processBuildCollection(Element request)
163 {
164 return runCommand(request, GS2PerlConstructor.BUILD);
165 }
166
167 protected Element processActivateCollection(Element request)
168 {
169 // this activates the collection on disk. but now we need to tell
170 // the MR about it. but we have to wait until the process is finished.
171 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
172 HashMap params = GSXML.extractParams(param_list, false);
173 String coll_name = (String) params.get(COL_PARAM);
174 String lang = request.getAttribute(GSXML.LANG_ATT);
175
176 systemRequest("delete", coll_name, null, lang);
177
178 Element response = runCommand(request, GS2PerlConstructor.ACTIVATE);
179 Element status = (Element) GSXML.getChildByTagName(response, GSXML.STATUS_ELEM);
180
181 String request_type = request.getAttribute(GSXML.TYPE_ATT);
182 if (request_type.equals(GSXML.REQUEST_TYPE_STATUS))
183 {
184 return response;
185 }
186
187 // check for finished
188 int status_code = Integer.parseInt(status.getAttribute(GSXML.STATUS_ERROR_CODE_ATT));
189 if (GSStatus.isCompleted(status_code) && GSStatus.isError(status_code))
190 {
191 // we shouldn't carry out the next bit, just return the response
192 return response;
193 }
194 String id = status.getAttribute(GSXML.STATUS_PROCESS_ID_ATT);
195 GS2PerlListener listener = (GS2PerlListener) this.listeners.get(id);
196 if (listener == null)
197 {
198 logger.error("somethings gone wrong, couldn't find the listener");
199 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ERROR));
200 return response;
201 }
202 while (!GSStatus.isCompleted(status_code))
203 {
204 // wait for the process, and keep checking the status code
205 // there is probably a better way to do this.
206 try
207 {
208 Thread.currentThread().sleep(100);
209 }
210 catch (Exception e)
211 { // ignore
212 }
213 status_code = listener.getStatus();
214 }
215
216 // add the rest of the messages to the status node
217 Text t = this.doc.createTextNode("\n" + listener.getUpdate());
218 status.appendChild(t);
219 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(listener.getStatus()));
220 if (GSStatus.isError(status_code))
221 {
222 return response; // without doing the next bit
223 }
224
225 t = this.doc.createTextNode("\n");
226 status.appendChild(t);
227 // once have got here, we assume
228 // the first bit proceeded successfully, now reload the collection
229 systemRequest("reload", coll_name, status, lang); // this will append more messages to the status, and overwrite the error code att
230 return response;
231
232 }
233
234 protected Element processDeleteCollection(Element request)
235 {
236
237 // the response to send back
238 String name = GSPath.getFirstLink(request.getAttribute(GSXML.TO_ATT));
239 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
240 response.setAttribute(GSXML.FROM_ATT, name);
241 Element status = this.doc.createElement(GSXML.STATUS_ELEM);
242 response.appendChild(status);
243 Text t = null; // the text node for the error/success message
244 String lang = request.getAttribute(GSXML.LANG_ATT);
245 String request_type = request.getAttribute(GSXML.TYPE_ATT);
246
247 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
248 HashMap params = GSXML.extractParams(param_list, false);
249
250 boolean get_status_only = false;
251 if (request_type.equals(GSXML.REQUEST_TYPE_STATUS))
252 {
253 get_status_only = true;
254 }
255 if (get_status_only)
256 {
257 // at the moment, delete is synchronous. but it may take ages so should do the command in another thread maybe? in which case we will want to ask for status
258 logger.error("had a status request for delete - this shouldn't happen!!");
259 //t = this.doc.createTextNode("");
260 //status.appendChild(t);
261 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ERROR));
262 return response;
263 }
264 String coll_name = (String) params.get(COL_PARAM);
265 String[] args = { coll_name };
266 File coll_dir = new File(GSFile.collectionBaseDir(this.site_home, coll_name));
267 // check that the coll is there in the first place
268 if (!coll_dir.exists())
269 {
270 t = this.doc.createTextNode(getTextString("delete.exists_error", lang, args));
271 status.appendChild(t);
272 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ERROR));
273 return response;
274 }
275
276 // try to delete the directory
277 if (!GSFile.deleteFile(coll_dir))
278 {
279 t = this.doc.createTextNode(getTextString("delete.delete_error", lang, args));
280 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ERROR));
281 status.appendChild(t);
282 return response;
283 }
284 systemRequest("delete", coll_name, status, lang);
285 return response;
286 }
287
288 protected Element processReloadCollection(Element request)
289 {
290
291 // the response to send back
292 String name = GSPath.getFirstLink(request.getAttribute(GSXML.TO_ATT));
293 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
294 response.setAttribute(GSXML.FROM_ATT, name);
295 Element status = this.doc.createElement(GSXML.STATUS_ELEM);
296 response.appendChild(status);
297 Text t = null; // the text node for the error/success message
298
299 String lang = request.getAttribute(GSXML.LANG_ATT);
300 String request_type = request.getAttribute(GSXML.TYPE_ATT);
301
302 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
303 HashMap params = GSXML.extractParams(param_list, false);
304
305 boolean get_status_only = false;
306 if (request_type.equals(GSXML.REQUEST_TYPE_STATUS))
307 {
308 get_status_only = true;
309 }
310 if (get_status_only)
311 {
312 // reload is synchronous - this makes no sense
313 logger.error("had a status request for reload - this shouldn't happen!!");
314 //t = this.doc.createTextNode("");
315 //status.appendChild(t);
316 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ERROR));
317 return response;
318 }
319
320 String coll_name = (String) params.get(COL_PARAM);
321 systemRequest("reload", coll_name, status, lang);
322 return response;
323
324 }
325
326 /**
327 * send a configure request to the message router action name should be
328 * "delete" or "reload" response will be put into the status element
329 */
330 protected void systemRequest(String action_name, String coll_name, Element status, String lang)
331 {
332 // send the request to the MR
333 Element message = this.doc.createElement(GSXML.MESSAGE_ELEM);
334 Element request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_SYSTEM, "", lang, "");
335 message.appendChild(request);
336 Element command = this.doc.createElement(GSXML.SYSTEM_ELEM);
337 request.appendChild(command);
338 command.setAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT, GSXML.COLLECTION_ELEM);
339 command.setAttribute(GSXML.SYSTEM_MODULE_NAME_ATT, coll_name);
340
341 if (action_name.equals("delete"))
342 {
343 command.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_DEACTIVATE);
344 }
345 else if (action_name.equals("reload"))
346 {
347 command.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_ACTIVATE);
348 }
349 else
350 {
351 logger.error("invalid action name passed to systemRequest:" + action_name);
352 return;
353 }
354 request.appendChild(command);
355 Node response = this.router.process(message); // at the moment, get no info in response so ignore it
356 Text t;
357 String[] args = { coll_name };
358
359 if (status != null)
360 {
361 if (response == null)
362 {
363 t = this.doc.createTextNode(getTextString(action_name + ".configure_error", lang, args));
364 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ERROR));
365 status.appendChild(t);
366 return;
367 }
368
369 // if we got here, we have succeeded!
370 t = this.doc.createTextNode(getTextString(action_name + ".success", lang, args));
371 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.SUCCESS));
372 status.appendChild(t);
373 }
374 }
375
376 /**
377 * configure the service module for now, all services have type=build - need
378 * to think about this
379 */
380 public boolean configure(Element info, Element extra_info)
381 {
382 if (!super.configure(info, extra_info))
383 {
384 return false;
385 }
386
387 logger.info("configuring GS2Construct");
388
389 Element e = null;
390 // hard code in the services for now
391
392 // set up short_service_info_ - for now just has name and type
393
394 e = this.doc.createElement(GSXML.SERVICE_ELEM);
395 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_PROCESS);
396 e.setAttribute(GSXML.NAME_ATT, NEW_SERVICE);
397 this.short_service_info.appendChild(e);
398
399 e = this.doc.createElement(GSXML.SERVICE_ELEM);
400 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_PROCESS);
401 e.setAttribute(GSXML.NAME_ATT, IMPORT_SERVICE);
402 this.short_service_info.appendChild(e);
403
404 e = this.doc.createElement(GSXML.SERVICE_ELEM);
405 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_PROCESS);
406 e.setAttribute(GSXML.NAME_ATT, BUILD_SERVICE);
407 this.short_service_info.appendChild(e);
408
409 e = this.doc.createElement(GSXML.SERVICE_ELEM);
410 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_PROCESS);
411 e.setAttribute(GSXML.NAME_ATT, ACTIVATE_SERVICE);
412 this.short_service_info.appendChild(e);
413
414 e = this.doc.createElement(GSXML.SERVICE_ELEM);
415 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_PROCESS);
416 e.setAttribute(GSXML.NAME_ATT, DELETE_SERVICE);
417 this.short_service_info.appendChild(e);
418
419 e = this.doc.createElement(GSXML.SERVICE_ELEM);
420 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_PROCESS);
421 e.setAttribute(GSXML.NAME_ATT, RELOAD_SERVICE);
422 this.short_service_info.appendChild(e);
423
424 //e = this.doc.createElement(GSXML.SERVICE_ELEM);
425 //e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_PROCESS);
426 //e.setAttribute(GSXML.NAME_ATT, ADD_DOC_SERVICE);
427 //this.short_service_info.appendChild(e);
428
429 return true;
430 }
431
432 /** returns a response element */
433 protected Element runCommand(Element request, int type)
434 {
435 // the response to send back
436 String name = GSPath.getFirstLink(request.getAttribute(GSXML.TO_ATT));
437 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
438 response.setAttribute(GSXML.FROM_ATT, name);
439 Element status = this.doc.createElement(GSXML.STATUS_ELEM);
440 response.appendChild(status);
441
442 String lang = request.getAttribute(GSXML.LANG_ATT);
443 String uid = request.getAttribute(GSXML.USER_ID_ATT);
444 String request_type = request.getAttribute(GSXML.TYPE_ATT);
445
446 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
447 HashMap params = GSXML.extractParams(param_list, false);
448
449 boolean get_status_only = false;
450 if (request_type.equals(GSXML.REQUEST_TYPE_STATUS))
451 {
452 get_status_only = true;
453 }
454
455 // just check for status messages if that's all that's required
456 if (get_status_only)
457 {
458 String id = (String) params.get(PROCESS_ID_PARAM);
459 status.setAttribute(GSXML.STATUS_PROCESS_ID_ATT, id);
460 GS2PerlListener listener = (GS2PerlListener) this.listeners.get(id);
461 if (listener == null)
462 {
463 Text t = this.doc.createTextNode(getTextString("general.process_id_error", lang));
464 status.appendChild(t);
465 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ERROR));
466 }
467 else
468 {
469 Text t = this.doc.createTextNode(listener.getUpdate());
470 status.appendChild(t);
471 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(listener.getStatus()));
472 // check that we actually should be removing the listener here
473 if (listener.isFinished())
474 { // remove this listener - its job is done
475 this.listeners.remove(id); // not working
476 }
477 }
478 return response;
479
480 }
481
482 // do teh actual command
483 String coll_name = null;
484 if (type == GS2PerlConstructor.NEW)
485 {
486 String coll_title = (String) params.get(NEW_COL_TITLE_PARAM);
487 coll_name = createNewCollName(coll_title);
488 }
489 else
490 {
491 coll_name = (String) params.get(COL_PARAM);
492 }
493 logger.info("Coll name = " + coll_name);
494 // makes a paramList of the relevant params
495 Element other_params = extractOtherParams(params, type);
496
497 //create the constructor to do the work
498 GS2PerlConstructor constructor = new GS2PerlConstructor("perl_build");
499 if (!constructor.configure())
500 {
501 Text t = this.doc.createTextNode(getTextString("general.configure_constructor_error", lang));
502 status.appendChild(t);
503 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ERROR));
504 return response;
505 }
506
507 GS2PerlListener listener = new GS2PerlListener();
508 constructor.setSiteHome(this.site_home);
509 constructor.setCollectionName(coll_name);
510 constructor.setActionType(type);
511 constructor.setProcessParams(other_params);
512
513 constructor.addListener(listener);
514 constructor.start();
515
516 String id = newID();
517 this.listeners.put(id, listener);
518
519 status.setAttribute(GSXML.STATUS_PROCESS_ID_ATT, id);
520 status.setAttribute(GSXML.STATUS_ERROR_CODE_ATT, Integer.toString(GSStatus.ACCEPTED));
521 Text t = this.doc.createTextNode(getTextString("general.process_start", lang));
522 status.appendChild(t);
523 return response;
524 }
525
526 //************************
527 // some helper functions
528 //************************
529
530 /** parse the collect directory and return a list of collection names */
531 protected String[] getCollectionList()
532 {
533
534 File collectDir = new File(GSFile.collectDir(this.site_home));
535 if (!collectDir.exists())
536 {
537 logger.error("couldn't find collect dir: " + collectDir.toString());
538 return null;
539 }
540 logger.info("GS2Construct: reading thru directory " + collectDir.getPath() + " to find collections.");
541 File[] contents = collectDir.listFiles();
542 int num_colls = 0;
543 for (int i = 0; i < contents.length; i++)
544 {
545 if (contents[i].isDirectory() && !contents[i].getName().startsWith("CVS"))
546 {
547 num_colls++;
548 }
549 }
550
551 String[] names = new String[num_colls];
552
553 for (int i = 0, j = 0; i < contents.length; i++)
554 {
555 if (contents[i].isDirectory())
556 {
557 String colName = contents[i].getName();
558 if (!colName.startsWith("CVS"))
559 {
560 names[j] = colName;
561 j++;
562 }
563
564 }
565 }
566
567 return names;
568
569 }
570
571 /** ids used for process id */
572 private int current_id = 0;
573
574 private String newID()
575 {
576 current_id++;
577 return Integer.toString(current_id);
578 }
579
580 /** creates a new short name from the collection title */
581 protected String createNewCollName(String coll_title)
582 {
583
584 String base_name = null;
585 // take the first 6 letters
586 if (coll_title.length() < 6)
587 {
588 base_name = coll_title;
589 }
590 else
591 {
592 base_name = coll_title.substring(0, 6);
593 }
594 File coll_dir = new File(GSFile.collectionBaseDir(this.site_home, base_name));
595 if (!coll_dir.exists())
596 { // this name is ok - not used yet
597 return base_name;
598 }
599
600 // now we have to make a new name until we get a good one
601 // try name1, name2 name3 etc
602 int i = 0;
603 while (coll_dir.exists())
604 {
605 i++;
606 coll_dir = new File(GSFile.collectionBaseDir(this.site_home, base_name + Integer.toString(i)));
607 }
608 return base_name + Integer.toString(i);
609
610 }
611
612 /**
613 * takes the params from the request (in the HashMap) and extracts any that
614 * need to be passed to the constructor and puts them into a paramList
615 * element
616 */
617 protected Element extractOtherParams(HashMap params, int type)
618 {
619
620 Element param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
621 if (type == GS2PerlConstructor.NEW)
622 {
623 Element param = this.doc.createElement(GSXML.PARAM_ELEM);
624 param.setAttribute(GSXML.NAME_ATT, "creator");
625 param.setAttribute(GSXML.VALUE_ATT, (String) params.get(CREATOR_PARAM));
626
627 param_list.appendChild(param);
628 param = this.doc.createElement(GSXML.PARAM_ELEM);
629 param.setAttribute(GSXML.NAME_ATT, "about");
630 param.setAttribute(GSXML.VALUE_ATT, (String) params.get(NEW_COL_ABOUT_PARAM));
631 param_list.appendChild(param);
632 param = this.doc.createElement(GSXML.PARAM_ELEM);
633 param.setAttribute(GSXML.NAME_ATT, "title");
634 param.setAttribute(GSXML.VALUE_ATT, (String) params.get(NEW_COL_TITLE_PARAM));
635 param_list.appendChild(param);
636 param = this.doc.createElement(GSXML.PARAM_ELEM);
637 param.setAttribute(GSXML.NAME_ATT, "buildtype");
638 param.setAttribute(GSXML.VALUE_ATT, (String) params.get(BUILDTYPE_PARAM));
639 param_list.appendChild(param);
640 return param_list;
641 }
642
643 // other ones dont have params yet
644 return null;
645 }
646
647}
Note: See TracBrowser for help on using the repository browser.