Changeset 5721
- Timestamp:
- 2003-10-23T11:15:10+13:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/collection/Collection.java
r5581 r5721 50 50 import org.greenstone.gatherer.msm.MetadataSetManager; 51 51 import org.greenstone.gatherer.msm.MSMUtils; 52 import org.greenstone.gatherer.util.StaticStrings; 52 53 import org.greenstone.gatherer.util.Utility; 53 54 import org.w3c.dom.*; … … 74 75 /** The file the collection is in (the file may not actually exist, such in the case of a legacy collection)! */ 75 76 private File file; 76 /** The name of the argument element. */ 77 static final private String ARGUMENT = "Argument"; 77 /** The name of the argument element. */ 78 static final private String ARGUMENT = "Argument"; 79 static final private String BASE_COLLECTION = "base_collection"; 78 80 /** The name of the build element. */ 79 81 static final private String BUILD = "Build"; … … 161 163 } 162 164 165 /** Determine the path to the base collection. 166 * @return the path as a String 167 */ 168 public String getBaseCollection() { 169 return getString(BASE_COLLECTION); 170 } 171 163 172 /** Determine the number of documents and folders in this collection. */ 164 173 public int getCount() { … … 304 313 } 305 314 315 public void setBaseCollection(String base_collection) { 316 set(BASE_COLLECTION, base_collection); 317 } 318 306 319 /** Set the value of imported to the given value. 307 320 * @param value The new value for imported, <i>true</i> if the collection has been imported successfully, <i>false</i> otherwise. … … 359 372 } 360 373 374 /** Get the value of a collection argument. */ 375 private String getString(String name) { 376 String result = ""; 377 try { 378 Element document_element = document.getDocumentElement(); 379 NodeList arguments = document_element.getElementsByTagName(ARGUMENT); 380 boolean found = false; 381 for(int i = 0; !found && i < arguments.getLength(); i++) { 382 Element argument_element = (Element) arguments.item(i); 383 if(argument_element.getParentNode() == document_element) { 384 if(argument_element.getAttribute(NAME).equalsIgnoreCase(name)) { 385 result = MSMUtils.getValue(argument_element); 386 found = true; 387 } 388 } 389 argument_element = null; 390 } 391 arguments = null; 392 document_element = null; 393 } 394 catch (Exception error) { 395 Gatherer.printStackTrace(error); 396 } 397 return result; 398 } 399 361 400 /** Method to retrieve the current build options associated with this Collection. */ 362 401 private Element getBuildValues() { … … 407 446 } 408 447 409 /** Set the value of a collection argument. */ 410 private void set(String name, boolean value) { 411 try { 412 Element document_element = document.getDocumentElement(); 413 NodeList arguments = document_element.getElementsByTagName(ARGUMENT); 414 boolean found = false; 415 for(int i = 0; !found && i < arguments.getLength(); i++) { 416 Element argument_element = (Element) arguments.item(i); 417 if(argument_element.getParentNode() == document_element) { 418 if(argument_element.getAttribute(NAME).equalsIgnoreCase(name)) { 419 // Strip any current value nodes. 420 while(argument_element.hasChildNodes()) { 421 argument_element.removeChild(argument_element.getFirstChild()); 422 } 423 // Append new value 424 argument_element.appendChild(document.createTextNode(value ? "true" : "false")); 425 } 426 } 427 argument_element = null; 428 } 429 arguments = null; 430 document_element = null; 431 } 432 catch (Exception error) { 433 Gatherer.printStackTrace(error); 434 } 435 } 448 /** Set the value of a collection argument. */ 449 private void set(String name, boolean value) { 450 set(name, (value ? StaticStrings.TRUE_STR : StaticStrings.FALSE_STR)); 451 } 452 453 private void set(String name, String value) { 454 try { 455 Element document_element = document.getDocumentElement(); 456 NodeList arguments = document_element.getElementsByTagName(ARGUMENT); 457 boolean found = false; 458 for(int i = 0; !found && i < arguments.getLength(); i++) { 459 Element argument_element = (Element) arguments.item(i); 460 if(argument_element.getParentNode() == document_element) { 461 if(argument_element.getAttribute(NAME).equalsIgnoreCase(name)) { 462 // Strip any current value nodes. 463 while(argument_element.hasChildNodes()) { 464 argument_element.removeChild(argument_element.getFirstChild()); 465 } 466 // Append new value 467 argument_element.appendChild(document.createTextNode(value)); 468 found = true; 469 } 470 } 471 argument_element = null; 472 } 473 // Append it 474 if(!found) { 475 Element argument_element = document.createElement(ARGUMENT); 476 argument_element.setAttribute(NAME, name); 477 argument_element.appendChild(document.createTextNode(value)); 478 document_element.appendChild(argument_element); 479 argument_element = null; 480 } 481 arguments = null; 482 document_element = null; 483 } 484 catch (Exception error) { 485 Gatherer.printStackTrace(error); 486 } 487 } 436 488 }
Note:
See TracChangeset
for help on using the changeset viewer.