Changeset 6086 for trunk/gli/src/org/greenstone/gatherer/Configuration.java
- Timestamp:
- 2003-12-02T17:15:47+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/Configuration.java
r6051 r6086 45 45 import javax.swing.plaf.*; 46 46 import org.greenstone.gatherer.msm.MSMUtils; 47 import org.greenstone.gatherer.util.StaticStrings; 47 48 import org.greenstone.gatherer.util.Utility; 48 49 import org.w3c.dom.*; … … 100 101 /** The general configuration settings. */ 101 102 private Document general_config; 103 104 /** The element, from glis config file, that contains the various directory mappings. */ 105 private Element directory_mappings_element; 106 102 107 private int cache_hit = 0; 103 108 private int cache_miss = 0; … … 177 182 Gatherer.println("Loaded current Gatherer configuration."); 178 183 } 184 185 // Determine the Directory Mappings element 186 directory_mappings_element = (Element) MSMUtils.getNodeFromNamed(general_config.getDocumentElement(), StaticStrings.DIRECTORY_MAPPINGS_ELEMENT); 187 179 188 // Re-establish the color settings. 180 189 updateUI(); … … 196 205 Gatherer.println("EXEC_ADDRESS = " + exec_address); 197 206 } 207 208 /** Add a special directory mapping. */ 209 public boolean addDirectoryMapping(String name, File file) { 210 boolean result = false; 211 try { 212 // Ensure the name isn't already in use. 213 boolean found = false; 214 NodeList mappings = directory_mappings_element.getElementsByTagName(StaticStrings.MAPPING_ELEMENT); 215 for(int i = 0; !found && i < mappings.getLength(); i++) { 216 Element mapping_element = (Element) mappings.item(i); 217 if(mapping_element.getAttribute(StaticStrings.NAME_ATTRIBUTE).equalsIgnoreCase(name)) { 218 found = true; 219 } 220 mapping_element = null; 221 } 222 // Otherwise add the mapping. 223 if(!found) { 224 Element mapping_element = general_config.createElement(StaticStrings.MAPPING_ELEMENT); 225 mapping_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name); 226 mapping_element.setAttribute(StaticStrings.FILE_ATTRIBUTE, file.toString()); 227 directory_mappings_element.appendChild(mapping_element); 228 result = true; 229 mapping_element = null; 230 } 231 mappings = null; 232 } 233 catch (Exception exception) { 234 Gatherer.printStackTrace(exception); 235 } 236 return result; 237 } /** addDirectoryMapping(String name, String file) **/ 198 238 199 239 /** The default get action retrieves the named property from the desired configuration, and returns a true or false. */ … … 319 359 } */ 320 360 361 /** Retrieve the special directory mappings associated with this collection. 362 * @return A <strong>HashMap</strong> containing mappings from names to directories. 363 */ 364 public HashMap getDirectoryMappings() { 365 HashMap special_directories = new HashMap(); 366 try { 367 // Ensure the name isn't already in use. 368 boolean found = false; 369 NodeList mappings = directory_mappings_element.getElementsByTagName(StaticStrings.MAPPING_ELEMENT); 370 for(int i = 0; !found && i < mappings.getLength(); i++) { 371 Element mapping_element = (Element) mappings.item(i); 372 String name = mapping_element.getAttribute(StaticStrings.NAME_ATTRIBUTE); 373 File file = new File(mapping_element.getAttribute(StaticStrings.FILE_ATTRIBUTE)); 374 special_directories.put(name, file); 375 file = null; 376 name = null; 377 mapping_element = null; 378 } 379 mappings = null; 380 } 381 catch(Exception exception) { 382 Gatherer.printStackTrace(exception); 383 } 384 return special_directories; 385 } /** getDirectoryMappings() */ 386 321 387 /** Retrieve the current users email. These are always stored in the general settings. 322 388 * @return the email address, if it is set, as a String … … 443 509 return gsdl_path + "bin" + File.separator + "script" + File.separator; 444 510 } 511 512 /** Remove a previously defined special directory mapping. 513 * @param name The name of the mapping to remove as a <strong>String</strong>. 514 * @return The <strong>File</strong> of the mapping removed. 515 */ 516 public File removeDirectoryMapping(String name) { 517 File file = null; 518 try { 519 // Ensure the name isn't already in use. 520 boolean found = false; 521 NodeList mappings = directory_mappings_element.getElementsByTagName(StaticStrings.MAPPING_ELEMENT); 522 for(int i = 0; !found && i < mappings.getLength(); i++) { 523 Element mapping_element = (Element) mappings.item(i); 524 if(mapping_element.getAttribute(StaticStrings.NAME_ATTRIBUTE).equalsIgnoreCase(name)) { 525 file = new File(MSMUtils.getValue(mapping_element)); 526 directory_mappings_element.removeChild(mapping_element); 527 found = true; 528 } 529 mapping_element = null; 530 } 531 mappings = null; 532 } 533 catch(Exception error) { 534 Gatherer.printStackTrace(error); 535 } 536 return file; 537 } /** removeDirectoryMapping(String name) */ 445 538 446 539 /** Export the general configuration to file. */
Note:
See TracChangeset
for help on using the changeset viewer.