Changeset 5617
- Timestamp:
- Apr 28, 2011, 8:09:11 AM (12 years ago)
- Location:
- trunk/src
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/ExtensionsControl.java
r5616 r5617 68 68 import net.sf.basedb.util.extensions.xml.ExtensionPointFilter; 69 69 import net.sf.basedb.util.extensions.xml.PluginInfo; 70 import net.sf.basedb.util.extensions.xml.XmlLoader;71 70 import net.sf.basedb.util.filter.Filter; 72 71 … … 255 254 256 255 // 2b. Load plug-in definitions information 257 PluginInstallationProcessor pluginInstaller = new PluginInstallationProcessor(dc, new XmlLoader(),results);256 PluginInstallationProcessor pluginInstaller = new PluginInstallationProcessor(dc, results); 258 257 manager.processFiles(pluginInstaller, installFilter); 259 258 numInstalledPlugins = pluginInstaller.getNumPlugins(); -
trunk/src/core/net/sf/basedb/core/Application.java
r5616 r5617 553 553 554 554 // Initialize extensions system 555 // TODO -- should this be moved to a utility class? Probably...555 boolean extensionsAreDisabled = Config.getBoolean("extensions.disabled"); 556 556 Registry xtRegistry = new Registry(); 557 557 java.io.File xtSettings = new java.io.File(userFilesDirectory, "extension-settings.xml"); … … 562 562 // Add core plug-ins 563 563 xtManager.addURI(Application.class.getResource("/core-plugins.xml").toURI()); 564 565 if (!Config.getBoolean("extensions.disabled")) 566 { 567 // Add plugins directory to the manager (unless disabled) 568 xtManager.addDirectory(pluginsDirectory); 569 } 564 // Add plugins directory to the manager (unless disabled) 565 if (!extensionsAreDisabled) xtManager.addDirectory(pluginsDirectory); 570 566 571 567 // Register and load core extensions only -
trunk/src/core/net/sf/basedb/core/Install.java
r5615 r5617 168 168 try 169 169 { 170 Config.setProperty("extensions.disabled", "true"); 170 171 Application.start(false, false, false); 171 172 session = HibernateUtil.newSession(); … … 2503 2504 Create {@link PluginConfiguration}s from a XML file. 2504 2505 */ 2506 @SuppressWarnings("unchecked") 2505 2507 private static void createPluginConfigurations(String filePath, boolean update) 2506 2508 throws BaseException … … 2527 2529 } 2528 2530 2529 URL dtdURL = Install.class.getResource("/net/sf/basedb/core/dtd/plugin-configuration-file.dtd"); 2530 URL fileURL = Install.class.getResource(filePath); 2531 Document doc = XMLUtil.getValidatedXml(fileURL, dtdURL); 2532 Element rootElement = doc.getRootElement(); 2533 2534 List configurations = rootElement.getChildren(); 2535 2536 for (Object obj : configurations) 2537 { 2538 Element configuration = (Element)obj; 2531 List<Element> configurations = PluginConfiguration.loadXmlFile(Install.class.getResource(filePath).openStream(), filePath); 2532 2533 for (Element configuration : configurations) 2534 { 2539 2535 String name = configuration.getChildText("configname"); 2540 2536 String description = configuration.getChildText("description"); … … 2560 2556 try 2561 2557 { 2562 PluginDefinition plugin Definition= PluginDefinition.getByClassName(dc, pluginClassName);2558 PluginDefinition plugin = PluginDefinition.getByClassName(dc, pluginClassName); 2563 2559 2564 2560 // Create a new plugin configurationj 2565 PluginConfiguration pluginConfig = PluginConfiguration.getNew(dc, pluginDefinition); 2566 pluginConfig.setItemKey(pluginDefinition.getItemKey()); 2567 pluginConfig.setProjectKey(pluginDefinition.getProjectKey()); 2568 dc.saveItem(pluginConfig); 2569 pluginConfig.setName(name); 2570 pluginConfig.setDescription(description); 2571 2572 // Get the confiuration parameters from file 2573 List parameters = configuration.getChildren("parameter"); 2574 for (Object elementObj : parameters) 2575 { 2576 Element parameter = (Element)elementObj; 2577 String parametername = parameter.getChildText("name"); 2578 String cl = parameter.getChildText("class"); 2579 String label = parameter.getChildText("label").length() > 0 ? parameter.getChildText("label") : name; 2580 Class clazz = null; 2581 List<Object> values = new ArrayList<Object>() ; 2582 2583 if (cl.length() > 0) 2584 { 2585 clazz = Class.forName(cl); 2586 List children = parameter.getChildren("value"); 2587 // Get the parameter values 2588 for (Object ch : children) 2589 { 2590 String text = ((Element)ch).getText(); 2591 if (clazz.equals(Boolean.class)) values.add(Boolean.valueOf(text)); 2592 else if (clazz.equals(Date.class)) values.add(DateUtil.parseString(text)); 2593 else if (clazz.equals(Double.class)) values.add(new Double(text)); 2594 else if (clazz.equals(Float.class)) values.add(new Float(text)); 2595 else if (clazz.equals(Long.class)) values.add(new Long(text)); 2596 else if (clazz.equals(String.class)) values.add(text); 2597 } 2598 // Get the parametertype 2599 ParameterType pType; 2600 if (clazz.equals(Boolean.class)) pType = new BooleanParameterType(); 2601 else if (clazz.equals(Date.class)) pType = new DateParameterType(); 2602 else if (clazz.equals(Double.class)) pType = new DoubleParameterType(); 2603 else if (clazz.equals(Float.class)) pType = new FloatParameterType(); 2604 else if (clazz.equals(Integer.class)) pType = new IntegerParameterType(); 2605 else if (clazz.equals(Long.class)) pType = new LongParameterType(); 2606 else if (clazz.equals(String.class)) pType = new StringParameterType(); 2607 else pType = null; 2608 pluginConfig.setParameterValues(parametername,label, "", pType, values); 2609 } 2610 } 2561 PluginConfiguration config = PluginConfiguration.getNew(dc, plugin); 2562 config.setItemKey(plugin.getItemKey()); 2563 config.setProjectKey(plugin.getProjectKey()); 2564 dc.saveItem(config); 2565 config.setName(name); 2566 config.setDescription(description); 2567 config.setParameterValues((List<Element>)configuration.getChildren("parameter")); 2611 2568 } 2612 2569 catch(Throwable ex) -
trunk/src/core/net/sf/basedb/core/PluginConfiguration.java
r5595 r5617 35 35 import net.sf.basedb.core.query.Hql; 36 36 import net.sf.basedb.core.query.Expressions; 37 37 import net.sf.basedb.util.XMLUtil; 38 39 import java.io.IOException; 40 import java.io.InputStream; 41 import java.net.URL; 42 import java.util.ArrayList; 38 43 import java.util.Date; 39 44 import java.util.HashSet; … … 42 47 import java.util.Set; 43 48 import java.util.Collections; 49 50 import org.jdom.Document; 51 import org.jdom.Element; 52 import org.jdom.JDOMException; 44 53 45 54 /** … … 165 174 } 166 175 return query; 176 } 177 178 /** 179 Load a configurations xml file from the given stream. 180 @param in The input stream to read from 181 @param fileName The name of the originating file (optional) 182 @return A list with all <configuration> elements in the file 183 @since 3.0 184 */ 185 @SuppressWarnings("unchecked") 186 public static List<Element> loadXmlFile(InputStream in, String fileName) 187 throws IOException, JDOMException 188 { 189 URL dtdURL = PluginConfiguration.class.getResource("/net/sf/basedb/core/dtd/plugin-configuration-file.dtd"); 190 Document doc = XMLUtil.getValidatedXML(in, dtdURL, fileName); 191 Element rootElement = doc.getRootElement(); 192 return (List<Element>)rootElement.getChildren(); 167 193 } 168 194 … … 666 692 667 693 694 /** 695 Sets parameters for a PluginConfiguration from the elements in a xml 696 configurations file. 697 698 @param parameters A list of the parameters that shall be set to the configuration 699 @throws ClassNotFoundException If there is an error while trying to find the type of the parameters. 700 @since 3.0 701 */ 702 @SuppressWarnings("unchecked") 703 public void setParameterValues(List<Element> parameters) 704 throws ClassNotFoundException 705 { 706 checkPermission(Permission.WRITE); 707 // Set each configuration parameter for the plugin. 708 for (Element parameter : parameters) 709 { 710 String name = parameter.getChildText("name"); 711 String cl = parameter.getChildText("class"); 712 String label = parameter.getChildText("label"); 713 if (label == null || label.length() == 0) label = name; 714 String description = parameter.getChildText("description"); 715 Class clazz = null; 716 List values = null; 717 718 if (cl.length() > 0) 719 { 720 clazz = Class.forName(cl); 721 values = getValueList(parameter, clazz); 722 ParameterType pType = getParameterType(clazz, values); 723 setParameterValues(name,label, description, pType, values); 724 } 725 } 726 } 727 728 /** 729 Gets the list of values for a parameter from the XML-file. 730 Returns a list with parameter values. 731 */ 732 @SuppressWarnings("unchecked") 733 private <T> List<T> getValueList(Element parameter, Class<T> classType) 734 { 735 List<Element> children = (List<Element>)parameter.getChildren("value"); 736 List<T> values = new ArrayList<T>(); 737 for (Object ch : children) 738 { 739 String text = ((Element)ch).getText(); 740 if (classType.equals(Boolean.class)) values.add((T)Boolean.valueOf(text)); 741 else if (classType.equals(Date.class)) values.add((T)DateUtil.parseString(text)); 742 else if (classType.equals(Double.class)) values.add((T)Double.valueOf(text)); 743 else if (classType.equals(Float.class)) values.add((T)Float.valueOf(text)); 744 else if (classType.equals(Long.class)) values.add((T)Long.valueOf(text)); 745 else if (classType.equals(String.class)) values.add((T)text); 746 } 747 return values; 748 } 749 750 /** 751 Gets the ParameterType to use with a class. 752 Returns null if this importer doesn't support the class. 753 */ 754 @SuppressWarnings("unchecked") 755 private <T> ParameterType<T> getParameterType(Class<T> parameterClass, List<?> values) 756 { 757 int multiplicity = 1; 758 if (values != null && values.size() > 1) multiplicity = values.size(); 759 ParameterType pType = null; 760 761 if (parameterClass.equals(Boolean.class)) 762 { 763 pType = new BooleanParameterType(null, false, multiplicity, null); 764 } 765 else if (parameterClass.equals(Date.class)) 766 { 767 pType = new DateParameterType(null, false, multiplicity, 0, 0, null); 768 } 769 else if (parameterClass.equals(Double.class)) 770 { 771 pType = new DoubleParameterType(null, null, null, false, multiplicity, 0, 0, null); 772 } 773 else if (parameterClass.equals(Float.class)) 774 { 775 pType = new FloatParameterType(null, null, null, false, multiplicity, 0, 0, null); 776 } 777 else if (parameterClass.equals(Integer.class)) 778 { 779 pType = new IntegerParameterType(null, null, null, false, multiplicity, 0, 0, null); 780 } 781 else if (parameterClass.equals(Long.class)) 782 { 783 pType = new LongParameterType(null, null, null, false, multiplicity, 0, 0, null); 784 } 785 else if (parameterClass.equals(String.class)) 786 { 787 // Find longest string 788 int maxLength = 255; 789 if (values != null && !values.isEmpty()) 790 { 791 for (Object obj : values) 792 { 793 if (obj instanceof String) 794 { 795 String str = obj.toString(); 796 if (str.length() > maxLength) maxLength = str.length(); 797 } 798 } 799 } 800 pType = new StringParameterType(maxLength, null, false, multiplicity, 0, 0); 801 } 802 return pType; 803 } 804 805 668 806 } -
trunk/src/core/net/sf/basedb/core/Update.java
r5592 r5617 73 73 try 74 74 { 75 Config.setProperty("extensions.disabled", "true"); 75 76 Application.start(false, false, false); 76 77 … … 192 193 try 193 194 { 195 Config.setProperty("extensions.disabled", "true"); 194 196 Application.start(false, false, false); 195 197 -
trunk/src/core/net/sf/basedb/util/extensions/manager/ExtensionsFile.java
r5616 r5617 385 385 386 386 /** 387 Get an input stream for reading the resource specified by the 388 given path 389 @param path The path of the resource 390 @return An input stream (or null if this extensions file is not a JAR file or if the given path is not found) 391 @throws IOException 392 */ 393 public InputStream getStream(String path) 394 throws IOException 395 { 396 InputStream in = null; 397 if (isJar()) 398 { 399 final ZipFile zipFile = new ZipFile(getFile()); 400 ZipEntry zipEntry = zipFile.getEntry(path); 401 if (zipEntry != null) 402 { 403 in = new CloseResourceInputStream(zipFile.getInputStream(zipEntry), 404 new Closeable() 405 { 406 // Make sure the zip file is closed when the returned stream is closed 407 @Override 408 public void close() 409 throws IOException 410 { 411 zipFile.close(); 412 } 413 } 414 ); 415 } 416 } 417 return in; 418 } 419 420 421 /** 387 422 Validate the XML file with the extension definitions. 388 423 */ -
trunk/src/core/net/sf/basedb/util/extensions/manager/ExtensionsManager.java
r5616 r5617 91 91 this.installedObjects = new HashMap<ObjectKey<?>, ExtensionsFile>(); 92 92 addIgnore(settingsFile); 93 // Add installed files94 for (File f : settings.getInstalledFiles())95 {96 ExtensionsFile xtFile = new ExtensionsFile(this, f);97 addExtensionsFile(xtFile);98 }99 93 } 100 94 … … 142 136 /** 143 137 Add a directory to this manager. The directory will be monitored 144 for extension files in the future. 138 for extension files in the future. Files in the directory that 139 are installed as per the settings {@link Settings#isInstalledFile(File)} 140 are loaded into manager. 145 141 <p> 146 This method call is ignored if the 147 path is not pointing to anexisting directory.142 This method call is ignored if the path is not pointing to an 143 existing directory. 148 144 149 145 @param dir An existing directory 150 146 @return The number of files in the directory that was 151 not previously known to the manager152 */ 153 public synchronized voidaddDirectory(File dir)147 installed 148 */ 149 public synchronized int addDirectory(File dir) 154 150 { 155 151 if (dir == null) throw new NullPointerException("dir"); 156 if (!dir.isDirectory()) return ;152 if (!dir.isDirectory()) return 0; 157 153 directories.add(dir); 154 return scanForInstalledFiles(dir, settings); 158 155 } 159 156 … … 372 369 373 370 /** 371 Scan the given directory and add files that are installed 372 according to the settings. 373 @param dir The directory to scan 374 @return The number of installed files in the given directory 375 */ 376 private int scanForInstalledFiles(File dir, Settings settings) 377 { 378 int numInstalled = 0; 379 380 if (!dir.isDirectory()) 381 { 382 log.warn("File '" + dir + "' is not a directory. Ignoring."); 383 return numInstalled; 384 } 385 386 log.info("Scanning directory: " + dir); 387 FileFilter filter = new RegexpFileFilter(".*\\.(xml|jar)", ""); 388 File[] files = dir.listFiles(filter); 389 390 if (files != null && files.length > 0) 391 { 392 log.debug("Found " + files.length + " files"); 393 for (File file : files) 394 { 395 if (ignore.contains(file)) 396 { 397 log.debug("File '" + file + "' is ignored."); 398 continue; // with the next file 399 } 400 401 URI uri = file.toURI(); 402 ExtensionsFile xtFile = xtFiles.get(uri); 403 if (xtFile != null) 404 { 405 log.debug("File '" + xtFile + "' is a known file."); 406 } 407 else if (settings.isInstalledFile(file)) 408 { 409 log.debug("Adding installed file: " + file); 410 xtFile = new ExtensionsFile(this, file); 411 addExtensionsFile(xtFile); 412 numInstalled++; 413 } 414 else 415 { 416 log.debug("File '" + file + "' is not installed."); 417 } 418 } 419 log.info("Found " + numInstalled + " new *.xml and *.jar files"); 420 } 421 else 422 { 423 log.info("Found no *.xml or *.jar files"); 424 } 425 return numInstalled; 426 } 427 428 429 /** 374 430 Get a list of all extension files managed by this manager. 375 431 @return A list -
trunk/src/core/net/sf/basedb/util/extensions/manager/processor/PluginInstallationProcessor.java
r5616 r5617 23 23 24 24 import java.io.InputStream; 25 import java.util.HashMap; 25 26 import java.util.List; 27 import java.util.Map; 28 29 import org.jdom.Element; 26 30 27 31 import net.sf.basedb.core.DbControl; 28 32 import net.sf.basedb.core.ItemKey; 33 import net.sf.basedb.core.ItemQuery; 29 34 import net.sf.basedb.core.Permission; 35 import net.sf.basedb.core.PluginConfiguration; 30 36 import net.sf.basedb.core.PluginDefinition; 37 import net.sf.basedb.core.Type; 38 import net.sf.basedb.core.query.Expressions; 39 import net.sf.basedb.core.query.Hql; 40 import net.sf.basedb.core.query.Restrictions; 31 41 import net.sf.basedb.util.FileUtil; 32 42 import net.sf.basedb.util.extensions.manager.ExtensionsFile.WriteableExtensionsFile; … … 36 46 import net.sf.basedb.util.extensions.manager.PluginInfoKey; 37 47 import net.sf.basedb.util.extensions.manager.ProcessResults; 48 import net.sf.basedb.util.extensions.xml.PluginDefinitionFilter; 38 49 import net.sf.basedb.util.extensions.xml.PluginInfo; 39 50 import net.sf.basedb.util.extensions.xml.XmlLoader; … … 67 78 (if not given, only the information from the XML files are loaded, 68 79 the plug-ins are not installed) 69 @param loader The XML loader to use when parsing the metadata 70 */ 71 public PluginInstallationProcessor(DbControl dc, XmlLoader loader, ProcessResults results) 80 */ 81 public PluginInstallationProcessor(DbControl dc, ProcessResults results) 72 82 { 73 83 this.dc = dc; 74 this.loader = loader;84 this.loader = new XmlLoader(); 75 85 this.results = results; 76 86 } … … 86 96 this.numError = 0; 87 97 this.numTotalPlugins = 0; 88 } 89 98 loader.setFilter(new PluginDefinitionFilter()); 99 } 100 101 @SuppressWarnings("unchecked") 90 102 @Override 91 103 public void processFile(ExtensionsManager manager, WriteableExtensionsFile wFile) … … 96 108 try 97 109 { 98 log.info("Loading extensions from file: " + xtFile);110 log.info("Loading plug-in definitions from file: " + xtFile); 99 111 100 112 in = xtFile.getXmlStream(); 101 113 loader.loadXmlFile(in, xtFile.getName(), xtFile.getClassLoader(), true); 114 FileUtil.close(in); 102 115 List<PluginInfo> plugins = loader.getPluginDefinitions(); 103 116 … … 105 118 int numUpdated = 0; 106 119 int numProcessed = 0; 120 int numConfigurations = 0; 121 Map<String, PluginDefinition> allPlugins = new HashMap<String, PluginDefinition>(); 107 122 if (plugins.size() > 0) 108 123 { … … 122 137 { 123 138 PluginDefinition plugin = PluginDefinition.installOrUpdate(dc, info, jarFile, shareToEveryone); 139 allPlugins.put(info.getClassName(), plugin); 124 140 if (plugin.isInDatabase()) 125 141 { … … 136 152 } 137 153 154 // Load plug-in configurations 155 if (dc != null) 156 { 157 in = xtFile.getStream("META-INF/plugin-configurations.xml"); 158 if (in != null) 159 { 160 List<Element> configurations = PluginConfiguration.loadXmlFile(in, "META-INF/plugin-configurations.xml"); 161 FileUtil.close(in); 162 for (Element configuration : configurations) 163 { 164 String name = configuration.getChildText("configname"); 165 String description = configuration.getChildText("description"); 166 String pluginClassName = configuration.getAttributeValue("pluginClassName"); 167 168 PluginDefinition plugin = allPlugins.get(pluginClassName); 169 if (plugin != null) 170 { 171 PluginConfiguration config = null; 172 if (plugin.isInDatabase()) 173 { 174 ItemQuery<PluginConfiguration> query = plugin.getPluginConfigurations(); 175 query.restrict(Restrictions.eq(Hql.property("name"), Expressions.parameter("name", name, Type.STRING))); 176 List<PluginConfiguration> existing = query.list(dc); 177 if (existing.size() == 0) 178 { 179 config = plugin.newPluginConfiguration(); 180 } 181 } 182 else 183 { 184 config = plugin.newPluginConfiguration(); 185 } 186 if (config != null && !config.isInDatabase()) 187 { 188 dc.saveItem(config); 189 config.setItemKey(plugin.getItemKey()); 190 config.setProjectKey(plugin.getProjectKey()); 191 config.setName(name); 192 config.setDescription(description); 193 config.setParameterValues((List<Element>)configuration.getChildren("parameter")); 194 numConfigurations++; 195 } 196 } 197 198 } 199 } 200 } 201 138 202 numFiles++; 139 203 numTotalPlugins += numInstalled + numUpdated; … … 142 206 if (numInstalled > 0) results.addMessage(xtFile, numInstalled + " plug-in(s) installed."); 143 207 if (numUpdated > 0) results.addMessage(xtFile, numUpdated + " plug-in(s) updated."); 208 if (numConfigurations > 0) results.addMessage(xtFile, numConfigurations + " plug-in configuration(s) created"); 144 209 if (numInstalled == 0 && numUpdated == 0 && numProcessed > 0) 145 210 { -
trunk/src/install/net/sf/basedb/install/Webclient.java
r5615 r5617 90 90 throws BaseException 91 91 { 92 Config.setProperty("extensions.disabled", "true"); 92 93 Application.start(false); 93 94 SessionControl sc = Application.newSessionControl(null, null, null); -
trunk/src/plugins/core/net/sf/basedb/plugins/PluginConfigurationImporter.java
r5612 r5617 26 26 import net.sf.basedb.core.BaseException; 27 27 import net.sf.basedb.core.BooleanParameterType; 28 import net.sf.basedb.core.DateParameterType;29 import net.sf.basedb.core.DateUtil;30 28 import net.sf.basedb.core.DbControl; 31 import net.sf.basedb.core.DoubleParameterType;32 29 import net.sf.basedb.core.File; 33 30 import net.sf.basedb.core.FileParameterType; 34 import net.sf.basedb.core.FloatParameterType;35 import net.sf.basedb.core.IntegerParameterType;36 31 import net.sf.basedb.core.InvalidDataException; 37 32 import net.sf.basedb.core.Item; 38 33 import net.sf.basedb.core.ItemContext; 39 34 import net.sf.basedb.core.ItemNotFoundException; 40 import net.sf.basedb.core.LongParameterType;41 import net.sf.basedb.core.ParameterType;42 35 import net.sf.basedb.core.PluginConfiguration; 43 36 import net.sf.basedb.core.PluginDefinition; … … 45 38 import net.sf.basedb.core.ProgressReporter; 46 39 import net.sf.basedb.core.RequestInformation; 47 import net.sf.basedb.core.StringParameterType;48 40 import net.sf.basedb.core.plugin.AbstractPlugin; 49 41 import net.sf.basedb.core.plugin.AutoDetectingImporter; … … 56 48 import net.sf.basedb.core.signal.SignalTarget; 57 49 import net.sf.basedb.core.signal.ThreadSignalHandler; 58 import net.sf.basedb.util. XMLUtil;50 import net.sf.basedb.util.FileUtil; 59 51 60 52 import java.io.BufferedReader; … … 62 54 import java.io.InputStream; 63 55 import java.io.InputStreamReader; 64 import java.net.URL;65 56 import java.nio.charset.Charset; 66 57 import java.util.ArrayList; 67 58 import java.util.Arrays; 68 import java.util.Date;69 59 import java.util.HashMap; 70 60 import java.util.HashSet; … … 75 65 import java.util.jar.JarFile; 76 66 77 import org.jdom.Document;78 67 import org.jdom.Element; 79 68 import org.jdom.JDOMException; … … 340 329 } 341 330 331 @SuppressWarnings("unchecked") 342 332 public void doImport(InputStream in, ProgressReporter progress) 343 333 throws BaseException … … 353 343 filePath = f.getPath().toString(); 354 344 } 355 //Get the root element of the XML file356 URL dtdURL = PluginConfigurationImporter.class.getResource("/net/sf/basedb/core/dtd/"+dtdFileName);357 Document doc = XMLUtil.getValidatedXML(in, dtdURL, filePath);358 Element rootElement = doc.getRootElement();359 345 346 List<Element> configurations = PluginConfiguration.loadXmlFile(in, filePath); 360 347 int parameternumber = 0; 361 List configurations = rootElement.getChildren(); 362 for (Object obj : configurations) 348 for (Element configuration : configurations) 363 349 { 364 350 ThreadSignalHandler.checkInterrupted(); 365 Element configuration = (Element)obj;366 351 String name = configuration.getChildText("configname"); 367 352 String description = configuration.getChildText("description"); 368 353 String pluginClassName = configuration.getAttributeValue("pluginClassName"); 369 PluginDefinition plugin Definition= null;354 PluginDefinition plugin = null; 370 355 try 371 356 { 372 plugin Definition= PluginDefinition.getByClassName(dc, pluginClassName);357 plugin = PluginDefinition.getByClassName(dc, pluginClassName); 373 358 374 boolean importConfiguration = !importAll &&getConfigurationInstallOption(parameternumber);375 if ( (importConfiguration || importAll))359 boolean importConfiguration = importAll || getConfigurationInstallOption(parameternumber); 360 if (importConfiguration) 376 361 { 377 PluginConfiguration pluginConfig = PluginConfiguration.getNew(dc, pluginDefinition);362 PluginConfiguration config = PluginConfiguration.getNew(dc, plugin); 378 363 if (setPermissions) 379 364 { 380 pluginConfig.setItemKey(pluginDefinition.getItemKey());381 pluginConfig.setProjectKey(pluginDefinition.getProjectKey());365 config.setItemKey(plugin.getItemKey()); 366 config.setProjectKey(plugin.getProjectKey()); 382 367 } 383 pluginConfig.setName(name); 384 pluginConfig.setDescription(description); 385 dc.saveItem(pluginConfig); 386 387 List parameters = configuration.getChildren("parameter"); 388 setPluginConf(parameters, pluginConfig); 368 config.setName(name); 369 config.setDescription(description); 370 config.setParameterValues((List<Element>)configuration.getChildren("parameter")); 371 dc.saveItem(config); 389 372 } 390 373 } … … 486 469 487 470 DbControl dc = null; 488 471 InputStream in = null; 489 472 try 490 473 { 491 474 dc = sc.newDbControl(); 492 475 //Get the root element of the XML file 493 String filePath = null;494 476 File file = (File)job.getValue("xmlfile"); 495 { 496 file = File.getById(dc, file.getId()); 497 filePath = file.getPath().toString(); 498 } 499 URL dtdURL = PluginConfigurationImporter.class.getResource("/net/sf/basedb/core/dtd/"+dtdFileName); 500 InputStream is = file.getDownloadStream(0); 501 Document doc = XMLUtil.getValidatedXML(is, dtdURL, filePath); 502 is.close(); 503 Element rootElement = doc.getRootElement(); 477 file = File.getById(dc, file.getId()); 478 String filePath = file.getPath().toString(); 479 480 in = file.getDownloadStream(0); 481 List<Element> configurations = PluginConfiguration.loadXmlFile(in, filePath); 482 FileUtil.close(in); 504 483 505 484 List<PluginParameter<?>> typeList = null; 506 List configurations = rootElement.getChildren();507 485 int parameternumber = 0; 508 486 for (Object obj : configurations) … … 564 542 finally 565 543 { 566 if (dc != null) 567 { 568 dc.close(); 569 } 544 if (dc != null) dc.close(); 545 FileUtil.close(in); 570 546 } 571 547 } 572 548 return configureSelection; 573 }574 575 /**576 Gets the list of values for a parameter from the XML-file.577 Returns a list with parameter values.578 */579 private List getValueList(Element parameter, Class classType)580 {581 List children = parameter.getChildren("value");582 List<Object> values = new ArrayList<Object>();583 for (Object ch : children)584 {585 String text = ((Element)ch).getText();586 if (classType.equals(Boolean.class)) values.add(Boolean.valueOf(text));587 else if (classType.equals(Date.class)) values.add(DateUtil.parseString(text));588 else if (classType.equals(Double.class)) values.add(Double.parseDouble(text));589 else if (classType.equals(Float.class)) values.add(Float.parseFloat(text));590 else if (classType.equals(Long.class)) values.add(Long.parseLong(text));591 else if (classType.equals(String.class)) values.add(text);592 }593 return values;594 }595 596 /**597 Gets the ParameterType to use with a class.598 Returns null if this importer doesn't support the class.599 */600 private ParameterType getParameterType(Class parameterClass, List<?> values)601 {602 int multiplicity = 1;603 if (values != null && values.size() > 1) multiplicity = values.size();604 ParameterType pType = null;605 606 if (parameterClass.equals(Boolean.class))607 {608 pType = new BooleanParameterType(null, false, multiplicity, null);609 }610 else if (parameterClass.equals(Date.class))611 {612 pType = new DateParameterType(null, false, multiplicity, 0, 0, null);613 }614 else if (parameterClass.equals(Double.class))615 {616 pType = new DoubleParameterType(null, null, null, false, multiplicity, 0, 0, null);617 }618 else if (parameterClass.equals(Float.class))619 {620 pType = new FloatParameterType(null, null, null, false, multiplicity, 0, 0, null);621 }622 else if (parameterClass.equals(Integer.class))623 {624 pType = new IntegerParameterType(null, null, null, false, multiplicity, 0, 0, null);625 }626 else if (parameterClass.equals(Long.class))627 {628 pType = new LongParameterType(null, null, null, false, multiplicity, 0, 0, null);629 }630 else if (parameterClass.equals(String.class))631 {632 // Find longest string633 int maxLength = 255;634 if (values != null && !values.isEmpty())635 {636 for (Object obj : values)637 {638 if (obj instanceof String)639 {640 String str = obj.toString();641 if (str.length() > maxLength) maxLength = str.length();642 }643 }644 }645 pType = new StringParameterType(maxLength, null, false, multiplicity, 0, 0);646 }647 return pType;648 }649 650 /**651 Sets parameters for a PluginConfiguration652 @param parameters A list of the parameters that shall be set to the configuration653 @param plc The @link{PluginConfiguration} that the parameters shall be added to.654 @throws ClassNotFoundException If there is an error while trying to find the type of the parameters.655 */656 private void setPluginConf(List parameters, PluginConfiguration plc)657 throws ClassNotFoundException658 {659 // Set each configuration parameter for the plugin.660 for (Object elementObj : parameters)661 {662 Element parameter = (Element)elementObj;663 String name = parameter.getChildText("name");664 String cl = parameter.getChildText("class");665 String label = parameter.getChildText("label");666 if (label == null || label.length() == 0) label = name;667 String description = parameter.getChildText("description");668 Class clazz = null;669 List<?> values = null;670 671 if (cl.length() > 0)672 {673 clazz = Class.forName(cl);674 values = getValueList(parameter, clazz);675 ParameterType pType = getParameterType(clazz, values);676 plc.setParameterValues(name,label, description, pType, values);677 }678 }679 549 } 680 550 … … 689 559 if (configurationMap != null) 690 560 { 691 Boolean value = configurationMap.get(orderNumber); 692 importIt = value != null ? value : false; 561 importIt = Boolean.TRUE.equals(configurationMap.get(orderNumber)); 693 562 } 694 563 else if (job != null) 695 564 { 696 importIt = job.getValue("configuration"+orderNumber) != null ? 697 Boolean.TRUE.equals(job.getValue("configuration" + orderNumber)) : false; 565 importIt = Boolean.TRUE.equals(job.getValue("configuration" + orderNumber)); 698 566 } 699 567
Note: See TracChangeset
for help on using the changeset viewer.