tmf: Use Apache Common Compress for importing from archive
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / internal / tmf / ui / project / wizards / importtrace / FileSystemObjectImportStructureProvider.java
CommitLineData
f17bb886
MAL
1/*******************************************************************************
2 * Copyright (c) 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Marc-Andre Laperle - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace;
14
15import java.io.File;
16import java.io.InputStream;
17import java.util.ArrayList;
18import java.util.List;
f17bb886 19
6120dc63
MAL
20import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
21import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
f17bb886
MAL
22import org.eclipse.ui.wizards.datatransfer.IImportStructureProvider;
23
24/**
25 * An import provider that makes use of the IFileSystemObject abstraction
6120dc63 26 * instead of using plain file system objects (File, TarArchiveEntry, ZipArchiveEntry, etc)
f17bb886 27 */
f17bb886
MAL
28public class FileSystemObjectImportStructureProvider implements IImportStructureProvider {
29
30 private IImportStructureProvider fImportProvider;
31 private String fArchivePath;
32
ee9e8924
MK
33 /**
34 * Constructor
35 *
36 * @param importStructureProvider
37 * the {@link IImportStructureProvider}
38 * @param archivePath
39 * the path of the archive file
40 */
41 public FileSystemObjectImportStructureProvider(IImportStructureProvider importStructureProvider, String archivePath) {
f17bb886
MAL
42 fImportProvider = importStructureProvider;
43 fArchivePath = archivePath;
44 }
45
46 @Override
47 public List<IFileSystemObject> getChildren(Object element) {
48 @SuppressWarnings("rawtypes")
49 List children = fImportProvider.getChildren(((IFileSystemObject) element).getRawFileSystemObject());
50 List<IFileSystemObject> adapted = new ArrayList<>(children.size());
51 for (Object o : children) {
52 adapted.add(getIFileSystemObject(o));
53 }
537cd2b8 54
f17bb886
MAL
55 return adapted;
56 }
57
58 /**
59 * Get the IFileSystemObject corresponding to the specified raw object
60 *
61 * @param o
62 * the raw object
63 * @return the corresponding IFileSystemObject
64 */
65 public IFileSystemObject getIFileSystemObject(Object o) {
66 if (o == null) {
67 return null;
68 }
69
70 if (o instanceof File) {
71 return new FileFileSystemObject((File) o);
6120dc63
MAL
72 } else if (o instanceof TarArchiveEntry) {
73 return new TarFileSystemObject((TarArchiveEntry) o, fArchivePath);
74 } else if (o instanceof ZipArchiveEntry) {
75 return new ZipFileSystemObject((ZipArchiveEntry) o, fArchivePath);
f17bb886
MAL
76 } else if (o instanceof GzipEntry) {
77 return new GzipFileSystemObject((GzipEntry) o, fArchivePath);
78 }
79
80 throw new IllegalArgumentException("Object type not handled"); //$NON-NLS-1$
81 }
82
83 @Override
84 public InputStream getContents(Object fileSystemObject) {
85 return fImportProvider.getContents(((IFileSystemObject) fileSystemObject).getRawFileSystemObject());
86 }
87
88 @Override
89 public String getFullPath(Object element) {
90 return fImportProvider.getFullPath(((IFileSystemObject) element).getRawFileSystemObject());
91 }
92
93 @Override
94 public String getLabel(Object element) {
95 return fImportProvider.getLabel(((IFileSystemObject) element).getRawFileSystemObject());
96 }
97
98 @Override
99 public boolean isFolder(Object element) {
100 return fImportProvider.isFolder(((IFileSystemObject) element).getRawFileSystemObject());
101 }
102
103 /**
104 * Disposes of the resources associated with the provider.
105 */
106 public void dispose() {
107 }
108}
This page took 0.046431 seconds and 5 git commands to generate.