Changeset 7959
- Timestamp:
- 2004-08-16T22:36:17+12:00 (20 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer/cdm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/ClassifierManager.java
r7151 r7959 35 35 import java.awt.event.*; 36 36 import java.io.*; 37 import java.net.*; 37 38 import java.util.*; 38 39 import java.util.jar.*; … … 299 300 * @return A <strong>String</strong> containing just the classifiers name, without extension. 300 301 */ 301 private String getClassifierName( File classifier) {302 String name = classifier.getName();302 private String getClassifierName(String filename) { 303 String name = filename; 303 304 if(name.indexOf(".") != -1) { 304 305 name = name.substring(0, name.indexOf(".")); … … 310 311 * @param classifier The classifier <strong>File</strong> you wish to load. 311 312 */ 312 private void loadClassifier( Fileclassifier, String lang) {313 ///ystem.err.println("Attempting to parse " + classifier .toString());313 private void loadClassifier(String classifier, String lang) { 314 ///ystem.err.println("Attempting to parse " + classifier); 314 315 Document document = null; 316 InputStream input_stream = null; 317 315 318 long start; 316 319 long end; 317 320 // Run classinfo on this classifier, and then send the results for parsing. 318 321 try { 319 String args[] = null; 320 if(Utility.isWindows()) { 321 args = new String[6]; 322 if(Gatherer.config.perl_path != null) { 323 args[0] = Gatherer.config.perl_path; 322 if (Gatherer.isGsdlRemote) { 323 String launch = Gatherer.cgiBase + "launch"; 324 launch += "?cmd=classinfo.pl"; 325 launch += "&xml=&language="+lang; 326 launch += "&class=" + getClassifierName(classifier); 327 328 System.err.println("*** launch = " + launch); 329 330 URL launch_url = new URL(launch); 331 URLConnection launch_connection = launch_url.openConnection(); 332 input_stream = launch_connection.getInputStream(); 333 } 334 else { 335 String args[] = null; 336 if(Utility.isWindows()) { 337 args = new String[6]; 338 if(Gatherer.config.perl_path != null) { 339 args[0] = Gatherer.config.perl_path; 340 } 341 else { 342 args[0] = "Perl.exe"; 343 } 344 args[1] = Gatherer.config.gsdl_path + "bin" + File.separator + "script" + File.separator + "classinfo.pl"; 345 args[2] = "-xml"; 346 args[3] = "-language"; 347 args[4] = lang; 348 args[5] = getClassifierName(classifier); 324 349 } 325 350 else { 326 args[0] = "Perl.exe"; 327 } 328 args[1] = Gatherer.config.gsdl_path + "bin" + File.separator + "script" + File.separator + "classinfo.pl"; 329 args[2] = "-xml"; 330 args[3] = "-language"; 331 args[4] = lang; 332 args[5] = getClassifierName(classifier); 333 } 334 else { 335 args = new String[5]; 336 args[0] = "classinfo.pl"; 337 args[1] = "-xml"; 338 args[2] = "-language"; 339 args[3] = lang; 340 args[4] = getClassifierName(classifier); 341 } 342 343 // Create the process. 344 Runtime runtime = Runtime.getRuntime(); 345 Process process = runtime.exec(args); 346 BufferedReader error_in = new BufferedReader(new InputStreamReader(process.getErrorStream(), "UTF-8")); 347 String line = ""; 348 StringBuffer xml = new StringBuffer(""); 349 boolean xml_content = false; 350 while((line = error_in.readLine()) != null) { 351 if(xml_content) { 352 xml.append(line); 353 xml.append("\n"); 354 } 355 else if(line.trim().startsWith("<?xml")) { 356 xml_content = true; 357 xml.append(line); 358 xml.append("\n"); 359 } 360 } 361 error_in = null; 362 process = null; 363 runtime = null; 364 // If something has gone horribly wrong then xml will be empty. 365 if(xml.length() != 0) { 366 // Then read the xml from the piped input stream. 367 InputSource source = new InputSource(new StringReader(xml.toString())); 368 DOMParser parser = new DOMParser(); 369 parser.parse(source); 370 document = parser.getDocument(); 371 parser = null; 372 source = null; 373 } 374 else { 375 String classifier_name = getClassifierName(classifier); 376 Gatherer.println("Zero length argument xml detected for: " + classifier_name); 377 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.ClassifierManager.Classifier_XML_Parse_Failed", classifier_name), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 378 classifier_name = null; 379 } 351 args = new String[5]; 352 args[0] = "classinfo.pl"; 353 args[1] = "-xml"; 354 args[2] = "-language"; 355 args[3] = lang; 356 args[4] = getClassifierName(classifier); 357 } 358 359 // Create the process. 360 Runtime runtime = Runtime.getRuntime(); 361 Process process = runtime.exec(args); 362 363 input_stream = process.getErrorStream(); 364 } 365 366 StringBuffer xml = Utility.readXMLStream(input_stream); 367 document = Utility.XMLStringToDOM(xml,classifier); 380 368 } 381 369 catch (Exception error) { … … 388 376 } 389 377 390 /** Method to initially load information from the standard plug-ins within the gsdl Perl library.378 /** Method to initially load information from the standard classifiers within the gsdl Perl library. 391 379 * @see org.greenstone.gatherer.util.Utility 392 380 */ … … 399 387 } 400 388 catch (Exception error) { 401 } 389 Gatherer.println("Unable to open "+ Utility.BASE_DIR + "classifier.dat"); 390 } 391 402 392 if(library == null) { 403 393 library = new ArrayList(); 404 // Retrieve the gsdl home directory... 405 String directory = Gatherer.config.gsdl_path; 406 directory = directory + "perllib" + File.separator + "classify" + File.separator; 407 String current_lang = Gatherer.config.getLanguage(); 408 File files[] = (new File(directory)).listFiles(); 409 if(files != null) { 410 // Create a progress indicator. 411 ParsingProgress progress = new ParsingProgress(Dictionary.get("CDM.ClassifierManager.Parsing.Title"), Dictionary.get("CDM.ClassifierManager.Parsing.Message"), files.length); 412 for(int i = 0; i < files.length; i++) { 413 // We only want to check Perl Modules. 414 if(files[i].getName().endsWith(".pm")) { 415 loadClassifier(files[i], current_lang); 416 } 417 progress.inc(); 418 } 419 progress.dispose(); 420 progress.destroy(); 421 progress = null; 422 } 423 } 424 } 394 395 if (Gatherer.isGsdlRemote) { 396 397 String lang = Gatherer.config.getLanguage(); 398 399 String launch = Gatherer.cgiBase + "launch"; 400 launch += "?cmd=classinfo.pl"; 401 launch += "&xml=&language="+lang; 402 launch += "&listall="; 403 404 System.err.println("*** launch = " + launch); 405 406 try { 407 URL launch_url = new URL(launch); 408 URLConnection launch_connection = launch_url.openConnection(); 409 InputStream input_stream = launch_connection.getInputStream(); 410 loadClassifiers(input_stream); 411 } 412 catch (Exception error) { 413 System.err.println("Failed when trying to connect to : " + launch); 414 error.printStackTrace(); 415 } 416 417 } 418 else { 419 420 // Retrieve the gsdl home directory... 421 String directory = Gatherer.config.gsdl_path; 422 directory = directory + "perllib" + File.separator + "classify" + File.separator; 423 424 String current_lang = Gatherer.config.getLanguage(); 425 File files[] = (new File(directory)).listFiles(); 426 if(files != null) { 427 // Create a progress indicator. 428 ParsingProgress progress = new ParsingProgress(Dictionary.get("CDM.ClassifierManager.Parsing.Title"), Dictionary.get("CDM.ClassifierManager.Parsing.Message"), files.length); 429 for(int i = 0; i < files.length; i++) { 430 // We only want to check Perl Modules. 431 if(files[i].getName().endsWith(".pm")) { 432 loadClassifier(files[i].getName(), current_lang); 433 } 434 progress.inc(); 435 } 436 progress.dispose(); 437 progress.destroy(); 438 progress = null; 439 } 440 } 441 } 442 } 443 444 445 446 /** Method to load classifier information from a specified input stream (could be local or through URL). Of course no classifiers may be found at this location. 447 * @param input_stream An <strong>InputStream</strong> indicating the where list of classifiers -- encoded in XML -- can be read from 448 */ 449 private void loadClassifiers(InputStream input_stream) 450 { 451 StringBuffer xml = Utility.readXMLStream(input_stream); 452 Document document = Utility.XMLStringToDOM(xml, "-listall"); 453 454 // Parse XML to build up list of classifier names 455 Node root = document.getDocumentElement(); 456 457 NamedNodeMap attributes = root.getAttributes(); 458 Node length_node = attributes.getNamedItem("length"); 459 String num_classifiers_str = length_node.getNodeValue(); 460 int num_classifiers = Integer.parseInt(num_classifiers_str); 461 String class_list[] = new String[num_classifiers]; 462 463 Node node = root.getFirstChild(); 464 int i = 0; 465 while (node != null) { 466 String node_name = node.getNodeName(); 467 if (node_name.equalsIgnoreCase("ClassifyName")) { 468 String name = MSMUtils.getValue(node); 469 class_list[i] = name; 470 i++; 471 } 472 473 node = node.getNextSibling(); 474 } 475 476 String current_lang = Gatherer.config.getLanguage(); 477 if (num_classifiers>0) { 478 // Create a progress indicator. 479 ParsingProgress progress = new ParsingProgress(Dictionary.get("CDM.ClassifierManager.Parsing.Title"), Dictionary.get("CDM.ClassifierManager.Parsing.Message"), num_classifiers); 480 481 for (i=0; i<num_classifiers; i++) { 482 String classifier = class_list[i]; 483 loadClassifier(classifier, current_lang); 484 progress.inc(); 485 } 486 progress.dispose(); 487 progress.destroy(); 488 progress = null; 489 } 490 } 491 425 492 426 493 /** Parses a DOM tree model turning it into a Classifier and its associated arguments. -
trunk/gli/src/org/greenstone/gatherer/cdm/PlugInManager.java
r7742 r7959 30 30 import java.awt.event.*; 31 31 import java.io.*; 32 import java.net.*; 32 33 import java.util.*; 33 34 import javax.swing.*; … … 344 345 * @return A <strong>String</strong> containing just the plugins name, without extension. 345 346 */ 346 private String getPlugInName( File plugin) {347 String name = plugin.getName();347 private String getPlugInName(String filename) { 348 String name = filename; 348 349 if(name.indexOf(".") != -1) { 349 350 name = name.substring(0, name.indexOf(".")); … … 352 353 } 353 354 355 354 356 /** Method to load the details of a single plug-in. 355 357 * @param plugin The plugin <strong>File</strong> you wish to load. 356 358 */ 357 private void loadPlugIn( Fileplugin, String lang) {359 private void loadPlugIn(String plugin, String lang) { 358 360 Document document = null; 361 InputStream input_stream = null; 359 362 360 363 // Run pluginfo on this plugin, and then send the results for parsing. 361 364 try { 362 String args[] = null; 363 if(Utility.isWindows()) { 364 args = new String[6]; 365 if(Gatherer.config.perl_path != null) { 366 args[0] = Gatherer.config.perl_path; 365 if (Gatherer.isGsdlRemote) { 366 String launch = Gatherer.cgiBase + "launch"; 367 launch += "?cmd=pluginfo.pl"; 368 launch += "&xml=&language="+lang; 369 launch += "&plug=" + getPlugInName(plugin); 370 371 System.err.println("*** launch = " + launch); 372 373 URL launch_url = new URL(launch); 374 URLConnection launch_connection = launch_url.openConnection(); 375 input_stream = launch_connection.getInputStream(); 376 } 377 else { 378 String args[] = null; 379 if(Utility.isWindows()) { 380 args = new String[6]; 381 if(Gatherer.config.perl_path != null) { 382 args[0] = Gatherer.config.perl_path; 383 } 384 else { 385 args[0] = "Perl.exe"; 386 } 387 args[1] = Gatherer.config.gsdl_path + "bin" + File.separator + "script" + File.separator + "pluginfo.pl"; 388 args[2] = "-xml"; 389 args[3] = "-language"; 390 args[4] = lang; 391 args[5] = getPlugInName(plugin); 367 392 } 368 393 else { 369 args[0] = "Perl.exe"; 370 } 371 args[1] = Gatherer.config.gsdl_path + "bin" + File.separator + "script" + File.separator + "pluginfo.pl"; 372 args[2] = "-xml"; 373 args[3] = "-language"; 374 args[4] = lang; 375 args[5] = getPlugInName(plugin); 376 } 377 else { 378 args = new String[5]; 379 args[0] = "pluginfo.pl"; 380 args[1] = "-xml"; 381 args[2] = "-language"; 382 args[3] = lang; 383 args[4] = getPlugInName(plugin); 384 } 385 // Create the process. 386 Runtime runtime = Runtime.getRuntime(); 387 Process process = runtime.exec(args); 388 //InputStream input_stream = process.getErrorStream(); 389 BufferedReader error_in = new BufferedReader(new InputStreamReader(process.getErrorStream(), "UTF-8")); 390 String line = ""; 391 StringBuffer xml = new StringBuffer(""); 392 boolean xml_content = false; 393 while((line = error_in.readLine()) != null) { 394 if(xml_content) { 395 xml.append(line); 396 xml.append("\n"); 397 } 398 else if(line.trim().startsWith("<?xml")) { 399 xml_content = true; 400 xml.append(line); 401 xml.append("\n"); 402 } 403 } 404 error_in = null; 405 process = null; 406 runtime = null; 407 args = null; 408 // If something has gone horribly wrong then xml will be empty. 409 if(xml.length() != 0) { 410 // Then read the xml from the piped input stream. 411 InputSource source = new InputSource(new StringReader(xml.toString())); 412 DOMParser parser = new DOMParser(); 413 parser.parse(source); 414 document = parser.getDocument(); 415 parser = null; 416 source = null; 417 } 418 else { 419 String plugin_name = getPlugInName(plugin); 420 //Gatherer.println("Zero length argument xml detected for: " + plugin_name); 421 String[] margs = new String[1]; 422 margs[0] = plugin_name; 423 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.PlugInManager.PlugIn_XML_Parse_Failed", margs), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 424 } 394 args = new String[5]; 395 args[0] = "pluginfo.pl"; 396 args[1] = "-xml"; 397 args[2] = "-language"; 398 args[3] = lang; 399 args[4] = getPlugInName(plugin); 400 } 401 402 // Create the process. 403 Runtime runtime = Runtime.getRuntime(); 404 Process process = runtime.exec(args); 405 input_stream = process.getErrorStream(); 406 } 407 408 StringBuffer xml = Utility.readXMLStream(input_stream); 409 document = Utility.XMLStringToDOM(xml,plugin); 425 410 } 426 411 catch (Exception error) { 427 System.err.println("Failed when trying to parse: " + plugin.getName());412 System.err.println("Failed when trying to parse: " + plugin); 428 413 error.printStackTrace(); 429 414 } … … 444 429 catch (Exception error) { 445 430 Gatherer.println("Unable to open "+ Utility.BASE_DIR + "plugins.dat"); 446 447 } 431 } 432 448 433 if(library == null) { 449 434 library = new ArrayList(); 450 // Retrieve the gsdl home directory... 451 String directory = Gatherer.config.gsdl_path; 452 directory = directory + "perllib" + File.separator + "plugins" + File.separator; 453 loadPlugIns(new File(directory)); 454 } 455 } 435 if (Gatherer.isGsdlRemote) { 436 437 String lang = Gatherer.config.getLanguage(); 438 439 String launch = Gatherer.cgiBase + "launch"; 440 launch += "?cmd=pluginfo.pl"; 441 launch += "&xml=&language="+lang; 442 launch += "&listall="; 443 444 System.err.println("*** launch = " + launch); 445 446 try { 447 URL launch_url = new URL(launch); 448 URLConnection launch_connection = launch_url.openConnection(); 449 InputStream input_stream = launch_connection.getInputStream(); 450 loadPlugIns(input_stream); 451 } 452 catch (Exception error) { 453 System.err.println("Failed when trying to connect to : " + launch); 454 error.printStackTrace(); 455 } 456 457 } 458 else { 459 // Retrieve the gsdl home directory... 460 String directory = Gatherer.config.gsdl_path; 461 directory = directory + "perllib" + File.separator + "plugins" + File.separator; 462 loadPlugIns(new File(directory)); 463 } 464 } 465 } 466 467 468 469 470 /** Method to load plug-in information from a specified input stream (could be local or through URL). Of course no plug-ins may be found at this location. 471 * @param input_stream An <strong>InputStream</strong> indicating the where list of plugins -- encoded in XML -- can be read from 472 */ 473 private void loadPlugIns(InputStream input_stream) 474 { 475 StringBuffer xml = Utility.readXMLStream(input_stream); 476 Document document = Utility.XMLStringToDOM(xml, "-listall"); 477 478 // Parse XML to build up list of plugin names 479 Node root = document.getDocumentElement(); 480 481 NamedNodeMap attributes = root.getAttributes(); 482 Node length_node = attributes.getNamedItem("length"); 483 String num_plugins_str = length_node.getNodeValue(); 484 int num_plugins = Integer.parseInt(num_plugins_str); 485 String plugin_list[] = new String[num_plugins]; 486 487 Node node = root.getFirstChild(); 488 int i = 0; 489 while (node != null) { 490 String node_name = node.getNodeName(); 491 if (node_name.equalsIgnoreCase("PluginName")) { 492 String name = MSMUtils.getValue(node); 493 plugin_list[i] = name; 494 i++; 495 } 496 497 node = node.getNextSibling(); 498 } 499 500 501 boolean is_windows = Utility.isWindows(); 502 boolean is_mac = Utility.isMac(); 503 504 String current_lang = Gatherer.config.getLanguage(); 505 if (num_plugins>0) { 506 // Create a progress indicator. 507 ParsingProgress progress = new ParsingProgress(Dictionary.get("CDM.PlugInManager.Parsing.Title"), Dictionary.get("CDM.PlugInManager.Parsing.Message"), num_plugins); 508 509 for (i=0; i<num_plugins; i++) { 510 String plugin = plugin_list[i]; 511 if (plugin.equals("GMLPlug.pm") || ((is_windows || is_mac) && plugin.equals("DBPlug.pm"))) { 512 // don't load GMLPlug or DBPlug for windows 513 } else { 514 loadPlugIn(plugin, current_lang); 515 } 516 517 progress.inc(); 518 } 519 progress.dispose(); 520 progress.destroy(); 521 progress = null; 522 } 523 } 524 525 456 526 /** Method to load plug-in information from a specified directory. Of course no plug-ins may be found at this location. 457 527 * @param directory A <strong>File</strong> indicating the directory to be scanned for plug-ins. … … 471 541 // don't load GMLPlug or DBPlug for windows 472 542 } else { 473 loadPlugIn(files[i] , current_lang);543 loadPlugIn(files[i].getName(), current_lang); 474 544 } 475 545 }
Note:
See TracChangeset
for help on using the changeset viewer.