|
Lines 56-93
Link Here
|
| 56 |
} |
56 |
} |
| 57 |
|
57 |
|
| 58 |
/** |
58 |
/** |
| 59 |
* Adds the specified child to the internal collection of the parent's |
59 |
* Creates a new container tar entry with the specified name, iff it has |
| 60 |
* children. |
60 |
* not already been created. If the parent of the given element does not |
| 61 |
*/ |
61 |
* already exist it will be recursively created as well. |
| 62 |
protected void addToChildren(TarEntry parent, TarEntry child) { |
62 |
* @param pathname The path representing the container |
| 63 |
List childList = (List) children.get(parent); |
63 |
* @return The element represented by this pathname (it may have already existed) |
| 64 |
if (childList == null) { |
64 |
*/ |
| 65 |
childList = new ArrayList(); |
65 |
protected TarEntry createContainer(IPath pathname) { |
| 66 |
children.put(parent, childList); |
66 |
TarEntry existingEntry = (TarEntry) directoryEntryCache.get(pathname); |
| 67 |
} |
67 |
if (existingEntry != null) |
| 68 |
|
68 |
return existingEntry; |
| 69 |
childList.add(child); |
|
|
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Creates a new container tar entry with the specified name, iff it has not |
| 74 |
* already been created. |
| 75 |
*/ |
| 76 |
protected void createContainer(IPath pathname) { |
| 77 |
if (directoryEntryCache.containsKey(pathname)) |
| 78 |
return; |
| 79 |
|
69 |
|
| 80 |
TarEntry parent; |
70 |
TarEntry parent; |
| 81 |
if (pathname.segmentCount() == 1) |
71 |
if (pathname.segmentCount() == 1) |
| 82 |
parent = root; |
72 |
parent = root; |
| 83 |
else |
73 |
else |
| 84 |
parent = (TarEntry) directoryEntryCache.get(pathname |
74 |
parent = createContainer(pathname.removeLastSegments(1)); |
| 85 |
.removeLastSegments(1)); |
|
|
| 86 |
|
| 87 |
TarEntry newEntry = new TarEntry(pathname.toString()); |
75 |
TarEntry newEntry = new TarEntry(pathname.toString()); |
| 88 |
newEntry.setFileType(TarEntry.DIRECTORY); |
76 |
newEntry.setFileType(TarEntry.DIRECTORY); |
| 89 |
directoryEntryCache.put(pathname, newEntry); |
77 |
directoryEntryCache.put(pathname, newEntry); |
| 90 |
addToChildren(parent, newEntry); |
78 |
List childList = new ArrayList(); |
|
|
79 |
children.put(newEntry, childList); |
| 80 |
|
| 81 |
List parentChildList = (List) children.get(parent); |
| 82 |
parentChildList.add(newEntry); |
| 83 |
return newEntry; |
| 91 |
} |
84 |
} |
| 92 |
|
85 |
|
| 93 |
/** |
86 |
/** |
|
Lines 102-108
Link Here
|
| 102 |
parent = (TarEntry) directoryEntryCache.get(pathname |
95 |
parent = (TarEntry) directoryEntryCache.get(pathname |
| 103 |
.removeLastSegments(1)); |
96 |
.removeLastSegments(1)); |
| 104 |
|
97 |
|
| 105 |
addToChildren(parent, entry); |
98 |
List childList = (List) children.get(parent); |
|
|
99 |
childList.add(entry); |
| 106 |
} |
100 |
} |
| 107 |
|
101 |
|
| 108 |
/* |
102 |
/* |
|
Lines 183-203
Link Here
|
| 183 |
*/ |
177 |
*/ |
| 184 |
protected void initialize() { |
178 |
protected void initialize() { |
| 185 |
children = new HashMap(1000); |
179 |
children = new HashMap(1000); |
| 186 |
|
180 |
|
|
|
181 |
children.put(root, new ArrayList()); |
| 187 |
Enumeration entries = tarFile.entries(); |
182 |
Enumeration entries = tarFile.entries(); |
| 188 |
while (entries.hasMoreElements()) { |
183 |
while (entries.hasMoreElements()) { |
| 189 |
TarEntry entry = (TarEntry) entries.nextElement(); |
184 |
TarEntry entry = (TarEntry) entries.nextElement(); |
| 190 |
if (entry.getFileType() == TarEntry.FILE) { |
185 |
IPath path = new Path(entry.getName()).addTrailingSeparator(); |
| 191 |
IPath path = new Path(entry.getName()).addTrailingSeparator(); |
186 |
|
|
|
187 |
if (entry.getFileType() == TarEntry.DIRECTORY) |
| 188 |
createContainer(path); |
| 189 |
else |
| 190 |
{ |
| 191 |
// Ensure the container structure for all levels above this is initialized |
| 192 |
// Once we hit a higher-level container that's already added we need go no further |
| 192 |
int pathSegmentCount = path.segmentCount(); |
193 |
int pathSegmentCount = path.segmentCount(); |
| 193 |
|
194 |
createContainer(path.uptoSegment(pathSegmentCount - 1)); |
| 194 |
for (int i = 1; i < pathSegmentCount; i++) |
|
|
| 195 |
createContainer(path.uptoSegment(i)); |
| 196 |
createFile(entry); |
195 |
createFile(entry); |
| 197 |
} |
196 |
} |
| 198 |
} |
197 |
} |
| 199 |
} |
198 |
} |
| 200 |
|
199 |
|
| 201 |
/* |
200 |
/* |
| 202 |
* (non-Javadoc) Method declared on IImportStructureProvider |
201 |
* (non-Javadoc) Method declared on IImportStructureProvider |
| 203 |
*/ |
202 |
*/ |