Changeset 3732
- Timestamp:
- Sep 14, 2007, 2:03:09 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/plugins/core/net/sf/basedb/plugins/PluginConfigurationImporter.java
r3720 r3732 74 74 import java.util.Map; 75 75 import java.util.Set; 76 import java.util.jar.JarEntry; 77 import java.util.jar.JarFile; 76 78 77 79 import org.jdom.Document; 78 80 import org.jdom.Element; 81 import org.jdom.JDOMException; 79 82 80 83 /** … … 143 146 private boolean setPermissions; 144 147 private boolean importAll; 148 private HashMap<Integer, Boolean> configurationMap; 145 149 146 150 /* … … 347 351 throws BaseException 348 352 { 349 DbControl dc = null; 350 353 DbControl dc = null; 351 354 try 352 355 { … … 358 361 filePath = f.getPath().toString(); 359 362 } 360 361 363 //Get the root element of the XML file 362 364 URL dtdURL = PluginConfigurationImporter.class.getResource("/net/sf/basedb/core/dtd/"+dtdFileName); 363 Document doc = XMLUtil.getValidatedXML(in, dtdURL, filePath); 365 Document doc = XMLUtil.getValidatedXML(in, dtdURL, filePath); 364 366 Element rootElement = doc.getRootElement(); 365 367 366 368 int parameternumber = 0; 367 List configurations = rootElement.getChildren(); 369 List configurations = rootElement.getChildren(); 368 370 for (Object obj : configurations) 369 371 { … … 373 375 String pluginClassName = configuration.getAttributeValue("pluginClassName"); 374 376 375 boolean importConfiguration = !importAll && 376 job.getValue("configuration"+parameternumber) != null ? Boolean.TRUE.equals(job.getValue("configuration"+parameternumber)) : false; 377 boolean importConfiguration = !importAll && getConfigurationInstallOption(parameternumber); 377 378 if (importConfiguration || importAll) 378 379 { … … 410 411 /* 411 412 ----------------------------------------------------- 412 */ 413 */ 414 415 /** 416 Imports plugin configurations direct from an xml file, located in a jar. 417 @since 2.5 418 @param jarPath Path to the jar-file 419 @param xmlPath Where in the jar-file the XML-file is located 420 @param configurations A hasmap with a boolean value for each configuration in the xml-file. 421 The value should be TRUE if the configuration should be imported, FALSE otherwise. 422 @param importAll If all configurations in the xml-file should be imported or not. 423 @param setPermissions If the configurations should be shared to the same users as the plugins they belong to. 424 @throws IOException When something goes wrong accessing a file 425 @throws JDOMException When failed to read the XML-file 426 @throws BaseException When the hashmap with import options has different 427 size compared to number of configurations in XML-file 428 429 */ 430 public void importPluginConfigurationsFromJar(String jarPath, String xmlPath, 431 HashMap<Integer, Boolean> configurations, boolean importAll, boolean setPermissions) 432 throws IOException, JDOMException, BaseException 433 { 434 this.importAll = importAll; 435 this.setPermissions = setPermissions; 436 this.configurationMap = configurations; 437 438 URL dtdURL = PluginConfigurationImporter.class.getResource("/net/sf/basedb/core/dtd/"+dtdFileName); 439 440 JarFile jar = new JarFile(jarPath); 441 InputStream is = jar.getInputStream(new JarEntry(xmlPath)); 442 Document doc = XMLUtil.getValidatedXML(is, dtdURL, null); 443 is.close(); 444 Element rootElement = doc.getRootElement(); 445 List children = rootElement.getChildren(); 446 447 if (children.size() != configurations.size()) 448 { 449 throw new BaseException("The list of configuration to import or not does'n " + 450 "have the same size as the list of available plugins"); 451 } 452 453 is = jar.getInputStream(new JarEntry(xmlPath)); 454 doImport(is, null); 455 is.close(); 456 } 457 413 458 414 459 private RequestInformation getConfiguredJobParameters() … … 433 478 } 434 479 480 /** 481 Gets request information to set which configuration to import 482 @return request information with parameter to use. 483 */ 435 484 private RequestInformation getConfiguredSelectionParameters() 436 485 { … … 519 568 } 520 569 } 521 522 570 } 523 571 return configureSelection; … … 613 661 } 614 662 } 663 664 /** 665 Returns if a configuration in a certain place/order in the XML-file should be imported 666 @param orderNumber The number of order the configuration has in the XML-file 667 @return TRUE if the configuration should be imported, FALSE otherwise. 668 */ 669 private boolean getConfigurationInstallOption(int orderNumber) 670 { 671 boolean importIt = false; 672 if (configurationMap != null) 673 { 674 Boolean value = configurationMap.get(orderNumber); 675 importIt = value != null ? value : false; 676 } 677 else if (job != null) 678 { 679 importIt = job.getValue("configuration"+orderNumber) != null ? 680 Boolean.TRUE.equals(job.getValue("configuration" + orderNumber)) : false; 681 } 682 683 return importIt; 684 } 615 685 }
Note: See TracChangeset
for help on using the changeset viewer.