Changeset 3564
- Timestamp:
- Jul 17, 2007, 11:28:22 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/util/AutoDetectFileFormat.java
r2648 r3564 91 91 Map<PluginDefinition, List<PluginConfiguration>> plugins = 92 92 new LinkedHashMap<PluginDefinition, List<PluginConfiguration>>(); 93 93 94 94 List<PluginDefinition> pluginDefs = null; 95 95 if (pluginDef == null) … … 108 108 for (PluginDefinition plugin : pluginDefs) 109 109 { 110 ItemQuery<PluginConfiguration> configQuery = plugin.getPluginConfigurations();111 configQuery.order(Orders.asc(Hql.property("name")));112 configQuery.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS);113 114 110 List<PluginConfiguration> configs = new LinkedList<PluginConfiguration>(); 115 for (PluginConfiguration config : configQuery.list(dc))111 if (!plugin.requiresConfiguration()) 116 112 { 117 AutoDetectingImporter importer = plugin.newInstance(AutoDetectingImporter.class, 118 null, sc, config, null); 119 if (currentItem == null || ((InteractivePlugin)importer).isInContext(context, currentItem) == null) 113 if (checkImportable(sc, plugin, null, file, context, currentItem)) 120 114 { 121 InputStream in = file.getDownloadStream(0); 122 if (importer.isImportable(in)) 115 configs.add(null); 116 } 117 } 118 if (plugin.supportsConfigurations()) 119 { 120 ItemQuery<PluginConfiguration> configQuery = plugin.getPluginConfigurations(); 121 configQuery.order(Orders.asc(Hql.property("name"))); 122 configQuery.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS); 123 for (PluginConfiguration config : configQuery.list(dc)) 124 { 125 if (checkImportable(sc, plugin, config, file, context, currentItem)) 123 126 { 124 127 configs.add(config); 125 128 } 129 } 130 } 131 if (configs.size() > 0) plugins.put(plugin, configs); 132 } 133 return plugins; 134 } 135 136 private static boolean checkImportable(SessionControl sc, PluginDefinition plugin, 137 PluginConfiguration config, File file, GuiContext context, Object currentItem) 138 { 139 AutoDetectingImporter importer = null; 140 boolean canBeUsed = false; 141 try 142 { 143 importer = plugin.newInstance(AutoDetectingImporter.class, null, sc, config, null); 144 boolean isInContext = true; 145 if (plugin.isInteractive()) 146 { 147 try 148 { 149 InteractivePlugin ip = (InteractivePlugin)importer; 150 isInContext = ip.isInContext(context, currentItem) == null; 151 } 152 catch (Throwable t) 153 { 154 isInContext = false; 155 } 156 } 157 if (isInContext) 158 { 159 InputStream in = file.getDownloadStream(0); 160 try 161 { 162 canBeUsed = importer.isImportable(in); 163 } 164 catch (Throwable t) 165 { 166 canBeUsed = false; 167 } 168 finally 169 { 126 170 try 127 171 { 128 172 in.close(); 129 173 } 130 catch ( Exception ex)174 catch (Throwable t) 131 175 {} 132 176 } 133 } 134 if (configs.size() > 0) 135 { 136 plugins.put(plugin, configs); 137 } 138 else 139 { 140 AutoDetectingImporter importer = plugin.newInstance(AutoDetectingImporter.class, 141 null, sc, null, null); 142 if (currentItem == null || ((InteractivePlugin)importer).isInContext(context, currentItem) == null) 143 { 144 InputStream in = file.getDownloadStream(0); 145 if (importer.isImportable(in)) 146 { 147 plugins.put(plugin, null); 148 } 149 try 150 { 151 in.close(); 152 } 153 catch (Exception ex) 154 {} 155 } 156 } 177 } 157 178 } 158 return plugins; 179 finally 180 { 181 if (importer != null) importer.done(); 182 } 183 return canBeUsed; 159 184 } 185 160 186 }
Note: See TracChangeset
for help on using the changeset viewer.