@Override public ILayer createLayer(URI source) throws LayerException { if(!source.isAbsolute()) { // If URI is not absolute ex URI.create("../folder/myfile.shp"), then create a canonical URI try { source = new File(location != null ? new File(location) : new File("./"), source.toString()).getCanonicalFile().toURI(); } catch (IOException ex) { throw new LayerException(ex); } } String layerName; try { layerName = FileUtils.getNameFromURI(source); } catch (UnsupportedOperationException ex) { try { layerName = dataManager.findUniqueTableName(I18N.tr("Layer")); } catch (SQLException ex2) { throw new LayerException(ex2); } } return createLayer(layerName, source); }
@Override public void run(ProgressMonitor pm) { long deb = System.currentTimeMillis(); try(Connection connection = dataManager.getDataSource().getConnection()) { ProgressMonitor filePm = pm.startTask(files.size()); boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData()); for(File file : files) { String ext = FilenameUtils.getExtension(file.getName()); DriverFunction driverFunction = driverFunctionContainer.getImportDriverFromExt(ext, driverType); if(driverFunction != null) { TableLocation tableName = new TableLocation("","",dataManager.findUniqueTableName( TableLocation.capsIdentifier(FileUtils.getNameFromURI(file.toURI()), isH2))); driverFunction.importFile(connection, tableName.toString() ,file, new H2GISProgressMonitor(filePm)); } else { LOGGER.error(I18N.tr("No driver found for {0} extension", ext)); } } } catch (SQLException ex) { LOGGER.error(I18N.tr("Cannot import the file"), ex); // Print additional information while((ex = ex.getNextException()) != null) { LOGGER.error(ex.getLocalizedMessage()); } } catch (IOException ex) { LOGGER.error(I18N.tr("Cannot import the file"), ex); } LOGGER.info(I18N.tr("Importation done in {0} sec", (System.currentTimeMillis() - deb) / 1000d)); catalog.refreshSourceList(); } }