- Timestamp:
- 2015-06-08T21:30:46+12:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/gui/DownloadPane.java
r29972 r29974 101 101 list_scroll = getter.getDownloadJobList(); 102 102 list_scroll.setComponentOrientation(Dictionary.getOrientation()); 103 103 104 // TODO should use Vector to store all loaded downloads!! 104 105 String lang = Configuration.getLanguage(); 105 106 download_map = new HashMap(); 106 107 107 ArrayList<String> downloaderNamesList = getDownloads(lang); 108 // run downloadinfo.pl -describeall, load the downloaders into the download_map, 109 // and get back their list of names, which are of the form "<downloader>Download". 110 // Store these names in the CONTENTS[] array as "DOWNLOAD.MODE.<downloader>Download", 111 // with z3950 as a minor exception: DOWNLOAD.MODE.ZDownload. 112 ArrayList<String> downloaderNamesList = loadDownloadersInfo(lang); 108 113 int size = downloaderNamesList.size(); 109 114 CONTENTS = new String[size]; … … 112 117 CONTENTS[i] = "DOWNLOAD.MODE."+downloadName.replace("3950", ""); // A special case is Z3950Download, 113 118 // which has to be stored in CONTENTS array as DOWNLOAD.MODE.ZDownload 114 115 String shortName = downloadName.replace("Download", ""); // e.g. "Web"116 download_map.put(shortName, loadDownload(downloadName,lang));117 119 } 118 120 … … 200 202 add(list_scroll); 201 203 202 mode = "Web"; 204 //set the mode to the first downloader in the list 205 mode = convertCONTENTStoMode(CONTENTS[0]); // e.g. Web 203 206 generateOptions(options_pane,(Download)download_map.get(mode)); 204 207 previous_path = tree.getSelectionPath(); … … 233 236 } 234 237 235 private ArrayList<String> getDownloads(String lang) {236 ArrayList downloaders = null; 238 /** Supporting Functions */ 239 private ArrayList<String> loadDownloadersInfo(String lang) { 237 240 Document document = null; 238 241 Process process = null; … … 240 243 try { 241 244 if (Gatherer.isGsdlRemote) { 242 String output = Gatherer.remoteGreenstoneServer.getScriptOptions("downloadinfo.pl", "& listall");245 String output = Gatherer.remoteGreenstoneServer.getScriptOptions("downloadinfo.pl", "&describeall"); 243 246 Reader reader = new StringReader(output); 244 247 document = XMLTools.parseXML(reader); … … 256 259 args_list.add("-S"); 257 260 args_list.add(LocalGreenstone.getBinScriptDirectoryPath()+"downloadinfo.pl"); 258 args_list.add("- listall");261 args_list.add("-describeall"); 259 262 args_list.add("-xml"); 260 263 args_list.add("-language"); … … 274 277 } 275 278 catch (Exception error) { 276 System.err.println("Failed when trying to parse downloadinfo.pl - listall");279 System.err.println("Failed when trying to parse downloadinfo.pl -describeall"); 277 280 error.printStackTrace(); 278 281 } … … 282 285 283 286 if(document != null) { 284 //return parseXML(document.getDocumentElement()); 285 Element downloadList = document.getDocumentElement(); 286 int length = -1; 287 if(downloadList.hasAttribute("length")) { 288 length = Integer.parseInt(downloadList.getAttribute("length")); 289 downloaders = new ArrayList<String>(length); 290 291 for (Node node = downloadList.getFirstChild(); node != null; node = node.getNextSibling()) { 292 // goes through each <DownloadInfo> of listAll 293 294 String download_name = null; 295 296 for(Node infoNode = node.getFirstChild(); 297 infoNode != null; infoNode = infoNode.getNextSibling()) { 298 299 String node_name = infoNode.getNodeName(); 300 if(node_name.equalsIgnoreCase("Name")) { // <Name>WebDownload</Name> 301 download_name = XMLTools.getValue(infoNode); 302 } 303 // skip all the downloaders that are Abstract, as these are pure superclasses 304 else if(node_name.equalsIgnoreCase("Abstract")) { 305 String isAbstract = XMLTools.getValue(infoNode); 287 return parseXML(document.getDocumentElement()); 288 } 289 290 return null; 291 } 292 293 private ArrayList<String> parseXML(Node root) { 294 ArrayList<String> downloaders = null; 295 Element downloadList = (Element)root; 296 int length = -1; 297 if(downloadList.hasAttribute("length")) { 298 length = Integer.parseInt(downloadList.getAttribute("length")); 299 downloaders = new ArrayList<String>(length); 300 301 for (Node node = downloadList.getFirstChild(); node != null; node = node.getNextSibling()) { 302 // goes through each <DownloadInfo> of describeAll 303 304 String download_name = null; 305 306 for(Node infoNode = node.getFirstChild(); 307 infoNode != null; infoNode = infoNode.getNextSibling()) { 308 309 String node_name = infoNode.getNodeName(); 310 if(node_name.equalsIgnoreCase("Name")) { // <Name>WebDownload</Name> 311 download_name = XMLTools.getValue(infoNode); // e.g. WebDownload 312 } 313 314 // At this top level of <DownloadInfo> elements, 315 // skip all the downloaders that are Abstract, as these are pure superclasses 316 else if(node_name.equalsIgnoreCase("Abstract")) { 317 String isAbstract = XMLTools.getValue(infoNode); 318 319 if(isAbstract.equalsIgnoreCase("no") && download_name != null) { 320 downloaders.add(download_name); 321 Download downloader = parseDownloadInfoXML(node); // parse the <DownloadInfo> node properly 322 // now embedded references to abstract superclasses (embedded <DownloadInfo> nodes) 323 // will be handled 306 324 307 if(isAbstract.equalsIgnoreCase("no") && download_name != null) { 308 downloaders.add(download_name); 309 } 325 String shortName = download_name.replace("Download", ""); // e.g. "Web" 326 download_map.put(shortName, downloader); 310 327 } 311 328 } … … 317 334 } 318 335 319 /** Supporting Functions */ 320 private Download loadDownload(String download_name, String lang) { 321 Document document = null; 322 Process process = null; 323 try { 324 if (Gatherer.isGsdlRemote) { 325 String output = Gatherer.remoteGreenstoneServer.getScriptOptions("downloadinfo.pl", "&downloader="+download_name); //OR: "&listall"; 326 Reader reader = new StringReader(output); 327 document = XMLTools.parseXML(reader); 328 } 329 else { 330 ArrayList args_list = new ArrayList(); 331 String args[] = null; 332 if(Configuration.perl_path != null) { 333 args_list.add(Configuration.perl_path); 334 } else if(Utility.isWindows()) { 335 args_list.add("Perl.exe"); 336 } else { 337 args_list.add("perl"); 338 } 339 args_list.add("-S"); 340 args_list.add(LocalGreenstone.getBinScriptDirectoryPath()+"downloadinfo.pl"); 341 args_list.add("-xml"); 342 args_list.add("-language"); 343 args_list.add(lang); 344 args_list.add(download_name); 345 346 // Create the process. 347 args = (String []) args_list.toArray(new String[0]); 348 Runtime runtime = Runtime.getRuntime(); 349 DebugStream.println("Getting Download Info: "+args_list); 350 process = runtime.exec(args); 351 352 InputStream input_stream = process.getErrorStream(); 353 document = XMLTools.parseXML(input_stream); 354 } 355 356 } 357 catch (Exception error) { 358 System.err.println("Failed when trying to parse: " + download_name); 359 error.printStackTrace(); 360 } 361 finally { 362 Utility.closeProcess(process); 363 } 364 365 if(document != null) { 366 return parseXML(document.getDocumentElement()); 367 } 368 369 return null; 370 } 371 372 private Download parseXML(Node root) { 336 private Download parseDownloadInfoXML(Node root) { 337 373 338 Download download = new Download(); 374 339 String node_name = null; … … 398 363 } 399 364 else if(node_name.equalsIgnoreCase("DownloadInfo")) { 400 Download super_download = parse XML(node);365 Download super_download = parseDownloadInfoXML(node); 401 366 download.setSuper(super_download); 402 367 } … … 559 524 // type has the value DOWNLOAD.MODE.<downloader>Download, 560 525 // mode should then be of the form <downloader> 561 mode = type.replace("DOWNLOAD.MODE.", "").replace("Download", "");526 mode = convertCONTENTStoMode(type); 562 527 generateOptions(options_pane,(Download)download_map.get(mode)); 563 528 … … 569 534 } 570 535 } 536 } 537 538 private String convertCONTENTStoMode(String content) { 539 return content.replace("DOWNLOAD.MODE.", "").replace("ZDownload", "Z3950").replace("Download", ""); 571 540 } 572 541
Note:
See TracChangeset
for help on using the changeset viewer.