Lines 19-24
Link Here
|
19 |
import java.io.File; |
19 |
import java.io.File; |
20 |
import java.util.Iterator; |
20 |
import java.util.Iterator; |
21 |
import java.io.FileNotFoundException; |
21 |
import java.io.FileNotFoundException; |
|
|
22 |
import java.io.IOException; |
22 |
|
23 |
|
23 |
/** Mapper from FileObject -> URL. |
24 |
/** Mapper from FileObject -> URL. |
24 |
* Should be registered in lookup. |
25 |
* Should be registered in lookup. |
Lines 45-52
Link Here
|
45 |
static { |
46 |
static { |
46 |
result = Lookup.getDefault().lookup(new Lookup.Template (URLMapper.class)); |
47 |
result = Lookup.getDefault().lookup(new Lookup.Template (URLMapper.class)); |
47 |
} |
48 |
} |
48 |
|
49 |
|
49 |
|
|
|
50 |
/** Find a good URL for this file object which works according to type: |
50 |
/** Find a good URL for this file object which works according to type: |
51 |
* -inside this VM |
51 |
* -inside this VM |
52 |
* - inside this machine |
52 |
* - inside this machine |
Lines 83-90
Link Here
|
83 |
* @return a suitable URL, or null |
83 |
* @return a suitable URL, or null |
84 |
*/ |
84 |
*/ |
85 |
public abstract URL getURL(FileObject fo, int type); |
85 |
public abstract URL getURL(FileObject fo, int type); |
86 |
|
86 |
|
|
|
87 |
/** Find an array of FileObjects for this url |
88 |
* Can find only FileObjects from FileSystems, that are present |
89 |
* in Repository. There is no guarantee that any FileObject will be |
90 |
* returned. But it should be guaranteed that |
91 |
* <code>fo.equals(findFileObject (findURL (fo, INTERNAL))[0])</code> |
92 |
* @return a suitable arry of FileObjects, or null |
93 |
*/ |
94 |
public static FileObject[] findFileObject(URL url) { |
95 |
/** first basic implementation */ |
96 |
FileObject[] retVal = geFileObjectBasicImpl(url); |
97 |
if (retVal != null) return retVal; |
98 |
|
99 |
/** secondly registered URLMappers are asked to resolve URL */ |
100 |
Iterator instances = result.allInstances().iterator(); |
101 |
while (instances.hasNext()) { |
102 |
URLMapper mapper = (URLMapper) instances.next(); |
103 |
retVal = mapper.getFileObject(url); |
104 |
if (retVal != null) return retVal; |
105 |
} |
106 |
|
107 |
return retVal; |
108 |
} |
109 |
|
110 |
/** Get an array of FileObjects for this url |
111 |
* @return a suitable arry of FileObjects, or null |
112 |
*/ |
113 |
public abstract FileObject[] getFileObject (URL url); |
87 |
|
114 |
|
|
|
115 |
|
88 |
/*** Basic impl. for JarFileSystem, LocalFileSystem, MultiFileSystem */ |
116 |
/*** Basic impl. for JarFileSystem, LocalFileSystem, MultiFileSystem */ |
89 |
private static URL getURLBasicImpl(FileObject fo, int type) { |
117 |
private static URL getURLBasicImpl(FileObject fo, int type) { |
90 |
if (fo == null) return null; |
118 |
if (fo == null) return null; |
Lines 139-145
Link Here
|
139 |
} |
167 |
} |
140 |
|
168 |
|
141 |
return retURL; |
169 |
return retURL; |
142 |
} |
170 |
} |
|
|
171 |
|
172 |
private static FileObject[] geFileObjectBasicImpl(URL url) { |
173 |
String prot = url.getProtocol(); |
174 |
|
175 |
if (prot.equals("nbfs")) { //// NOI18N |
176 |
FileObject retVal = FileURL.decodeURL(url); |
177 |
return (retVal == null) ? null : new FileObject[] {retVal}; |
178 |
} |
179 |
|
180 |
if (prot.equals("jar")) { //// NOI18N |
181 |
try { |
182 |
URLConnection ucon = url.openConnection(); |
183 |
if (ucon != null && ucon instanceof JarURLConnection) { |
184 |
URL jarURL = ((JarURLConnection) ucon).getJarFileURL(); |
185 |
String systemName = new File(jarURL.getFile()).getCanonicalPath(); |
186 |
FileSystem fs = Repository.getDefault().findFileSystem(systemName); |
187 |
if (fs != null && fs instanceof JarFileSystem) { |
188 |
FileObject retVal = fs.findResource(((JarURLConnection) ucon).getEntryName()); |
189 |
return (retVal == null) ? null : new FileObject[] {retVal}; |
190 |
} |
191 |
} |
192 |
} catch (IOException iox) { |
193 |
return null; |
194 |
} |
195 |
return null; |
196 |
} |
197 |
|
198 |
if (prot.equals("file")) { //// NOI18N |
199 |
try { |
200 |
File f = new File(url.getFile()).getCanonicalFile(); |
201 |
FileObject[] foRes = FileUtil.fromFile(f); |
202 |
if (foRes != null && foRes.length > 0) |
203 |
return foRes; |
204 |
} catch (IOException iox) { |
205 |
return null; |
206 |
} |
207 |
return null; |
208 |
} |
209 |
|
210 |
return null; |
211 |
} |
212 |
|
143 |
} |
213 |
} |
144 |
|
214 |
|
145 |
|
215 |
|