Lines 25-30
Link Here
|
25 |
import java.lang.reflect.Constructor; |
25 |
import java.lang.reflect.Constructor; |
26 |
import java.lang.reflect.InvocationTargetException; |
26 |
import java.lang.reflect.InvocationTargetException; |
27 |
import java.util.HashMap; |
27 |
import java.util.HashMap; |
|
|
28 |
import java.util.Iterator; |
28 |
|
29 |
|
29 |
/** |
30 |
/** |
30 |
* This class manages all the Archive Handlers that correspond to the archive file that the system |
31 |
* This class manages all the Archive Handlers that correspond to the archive file that the system |
Lines 40-45
Link Here
|
40 |
public static final String VIRTUAL_SEPARATOR = "#virtual#/"; //$NON-NLS-1$ |
41 |
public static final String VIRTUAL_SEPARATOR = "#virtual#/"; //$NON-NLS-1$ |
41 |
public static final String VIRTUAL_CANONICAL_SEPARATOR = "#virtual#"; //$NON-NLS-1$ |
42 |
public static final String VIRTUAL_CANONICAL_SEPARATOR = "#virtual#"; //$NON-NLS-1$ |
42 |
public static final String VIRTUAL_FOLDER_SEPARATOR = "/"; //$NON-NLS-1$ |
43 |
public static final String VIRTUAL_FOLDER_SEPARATOR = "/"; //$NON-NLS-1$ |
|
|
44 |
public static final String EXTENSION_SEPARATOR = "."; //$NON-NLS-1$ |
43 |
|
45 |
|
44 |
// the singleton instance |
46 |
// the singleton instance |
45 |
protected static ArchiveHandlerManager _instance = new ArchiveHandlerManager(); |
47 |
protected static ArchiveHandlerManager _instance = new ArchiveHandlerManager(); |
Lines 116-122
Link Here
|
116 |
} |
118 |
} |
117 |
else |
119 |
else |
118 |
{ |
120 |
{ |
119 |
if (_handlerTypes.containsKey(getExtension(file))) |
121 |
if (getRegisteredExtension(file)!=null) |
120 |
{ |
122 |
{ |
121 |
return true; |
123 |
return true; |
122 |
} |
124 |
} |
Lines 136-141
Link Here
|
136 |
*/ |
138 |
*/ |
137 |
public boolean isRegisteredArchive(String filename) |
139 |
public boolean isRegisteredArchive(String filename) |
138 |
{ |
140 |
{ |
|
|
141 |
return getRegisteredExtension(filename) == null?false:true; |
142 |
//the code below doesn't support extension like fool.tar.gz, |
143 |
//changed to compare file name against registered extensions |
144 |
/* |
139 |
if (_handlerTypes.containsKey(getExtension(filename))) |
145 |
if (_handlerTypes.containsKey(getExtension(filename))) |
140 |
{ |
146 |
{ |
141 |
return true; |
147 |
return true; |
Lines 144-156
Link Here
|
144 |
{ |
150 |
{ |
145 |
return false; |
151 |
return false; |
146 |
} |
152 |
} |
|
|
153 |
*/ |
147 |
} |
154 |
} |
|
|
155 |
|
156 |
/** |
157 |
* check if the file extension is registered archive type. |
158 |
* notice here, the getExtension method does't work for name like fool.tar.gz |
159 |
* @param file the file to check |
160 |
* @return extension or null |
161 |
*/ |
162 |
protected String getRegisteredExtension(File file) |
163 |
{ |
164 |
String fileName = file.getName(); |
165 |
return getRegisteredExtension(fileName); |
166 |
|
167 |
} |
168 |
/** |
169 |
* check if the file extension is registered archive type. |
170 |
* notice here, the getExtension method does't work for name like fool.tar.gz |
171 |
* @param fileName the file name to check |
172 |
* @return extension or null |
173 |
*/ |
174 |
protected String getRegisteredExtension(String fileName) |
175 |
{ |
176 |
Iterator itor = _handlerTypes.keySet().iterator(); |
177 |
while(itor.hasNext()) |
178 |
{ |
179 |
String ext = ((String)itor.next()).toLowerCase(); |
180 |
if (fileName.endsWith(EXTENSION_SEPARATOR + ext)) |
181 |
{ |
182 |
return ext; |
183 |
} |
184 |
|
185 |
} |
186 |
return null; |
187 |
} |
188 |
|
148 |
/** |
189 |
/** |
149 |
* @param file the file whose extension we are computing. |
190 |
* @param file the file whose extension we are computing. |
150 |
* @return the extension of <code>file</code>. "Extension" is |
191 |
* @return the extension of <code>file</code>. "Extension" is |
151 |
* defined as any letters in the filename after the last ".". |
192 |
* defined as any letters in the filename after the last ".". |
152 |
* Returns "" if there is no extension. |
193 |
* Returns "" if there is no extension. |
153 |
*/ |
194 |
*/ |
|
|
195 |
/* |
154 |
protected String getExtension(File file) |
196 |
protected String getExtension(File file) |
155 |
{ |
197 |
{ |
156 |
String filename = file.getName(); |
198 |
String filename = file.getName(); |
Lines 158-163
Link Here
|
158 |
if (i == -1) return ""; //$NON-NLS-1$ |
200 |
if (i == -1) return ""; //$NON-NLS-1$ |
159 |
return filename.substring(i+1).toLowerCase(); |
201 |
return filename.substring(i+1).toLowerCase(); |
160 |
} |
202 |
} |
|
|
203 |
*/ |
204 |
|
161 |
|
205 |
|
162 |
/** |
206 |
/** |
163 |
* @param filename the name of the file whose extension we are computing. |
207 |
* @param filename the name of the file whose extension we are computing. |
Lines 165-176
Link Here
|
165 |
* defined as any letters in the filename after the last ".". |
209 |
* defined as any letters in the filename after the last ".". |
166 |
* Returns "" if there is no extension. |
210 |
* Returns "" if there is no extension. |
167 |
*/ |
211 |
*/ |
|
|
212 |
/* |
168 |
protected String getExtension(String filename) |
213 |
protected String getExtension(String filename) |
169 |
{ |
214 |
{ |
170 |
int i = filename.lastIndexOf("."); //$NON-NLS-1$ |
215 |
int i = filename.lastIndexOf("."); //$NON-NLS-1$ |
171 |
if (i == -1) return ""; //$NON-NLS-1$ |
216 |
if (i == -1) return ""; //$NON-NLS-1$ |
172 |
return filename.substring(i+1).toLowerCase(); |
217 |
return filename.substring(i+1).toLowerCase(); |
173 |
} |
218 |
} |
|
|
219 |
*/ |
174 |
|
220 |
|
175 |
/** |
221 |
/** |
176 |
* Given the absolute path to a virtual object, returns that object |
222 |
* Given the absolute path to a virtual object, returns that object |
Lines 212-219
Link Here
|
212 |
} |
258 |
} |
213 |
else { |
259 |
else { |
214 |
// find registered handler based on file's extension |
260 |
// find registered handler based on file's extension |
215 |
String ext = getExtension(file); |
261 |
String ext = getRegisteredExtension(file); |
216 |
if (!_handlerTypes.containsKey(ext)) |
262 |
if (ext == null) |
217 |
{ |
263 |
{ |
218 |
//System.out.println("Unknown archive file type: " + ext); |
264 |
//System.out.println("Unknown archive file type: " + ext); |
219 |
return null; |
265 |
return null; |