use of org.talend.core.ui.export.TarFileExporterFullPath in project tdi-studio-se by Talend.
the class ExportItemUtil method exportItems.
public void exportItems(File destination, final Collection<Item> items, List<String> folders, boolean exportAllVersions, IProgressMonitor progressMonitor) throws Exception {
// bug 11301 :export 0 items
Collection<Item> workItems = items;
if (workItems == null) {
workItems = new ArrayList<Item>();
}
Collection<Item> otherVersions = new ArrayList<Item>();
// get all versions of the exported items if wanted
if (exportAllVersions) {
otherVersions = getOtherVersions(workItems);
workItems.addAll(otherVersions);
otherVersions.clear();
}
// else keep current items version only
try {
File tmpDirectory = null;
Map<File, IPath> toExport;
// TDI-27660:if not give the path of export file,get its default parent path.
File parentDesFile = checkAndGetDesParentFile(destination);
if (destination.getName().endsWith(FileConstants.TAR_FILE_SUFFIX)) {
createFolder(parentDesFile);
exporter = new TarFileExporterFullPath(destination.getAbsolutePath(), false);
} else if (destination.getName().endsWith(FileConstants.TAR_GZ_FILE_SUFFIX)) {
createFolder(parentDesFile);
exporter = new TarFileExporterFullPath(destination.getAbsolutePath(), true);
} else if (destination.getName().endsWith(FileConstants.ZIP_FILE_SUFFIX)) {
createFolder(parentDesFile);
exporter = new ZipFileExporterFullPath(destination.getAbsolutePath(), true);
} else {
createFolder(destination);
}
if (exporter != null) {
tmpDirectory = createTmpDirectory();
}
try {
if (exporter != null) {
toExport = exportItems2(workItems, tmpDirectory, true, progressMonitor);
// IPath rootPath = new Path(destination.getName()).removeFileExtension().removeFileExtension();
for (File file : toExport.keySet()) {
IPath path = toExport.get(file);
// exporter.write(file.getAbsolutePath(), rootPath.append(path).toString());
exporter.write(file.getAbsolutePath(), path.toString());
}
if (folders != null) {
// filter folders that already created
List<String> toRemove = new ArrayList<String>();
for (String folderPath : folders) {
for (IPath resourcePath : toExport.values()) {
if (resourcePath.toPortableString().contains(folderPath)) {
toRemove.add(folderPath);
break;
}
}
}
folders.removeAll(toRemove);
for (String folderPath : folders) {
exporter.writeFolder(folderPath);
}
}
} else {
toExport = exportItems2(workItems, destination, true, progressMonitor);
if (folders != null) {
// filter folders that already created
List<String> toRemove = new ArrayList<String>();
for (String folderPath : folders) {
for (IPath resourcePath : toExport.values()) {
if (resourcePath.toPortableString().contains(folderPath)) {
toRemove.add(folderPath);
break;
}
}
}
folders.removeAll(toRemove);
for (String folderPath : folders) {
IPath fullPath = new Path(destination.getAbsolutePath());
fullPath = fullPath.append(folderPath);
FilesUtils.createFoldersIfNotExists(fullPath.toPortableString(), false);
}
}
}
} catch (Exception e) {
throw e;
} finally {
if (exporter != null) {
deleteTmpDirectory(tmpDirectory);
}
}
} finally {
if (exporter != null) {
try {
exporter.finished();
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
}
}
Aggregations