MCPcopy Create free account
hub / github.com/GateNLP/gate-core / toURL

Method toURL

src/main/java/gate/creole/ResourceReference.java:248–284  ·  view source on GitHub ↗

Creates a java.net.URL URL instance that can be used to access the underlying resource. It should be noted that the result is not guaranteed to be valid long term and should never be persisted. If you want persistent access then store the ResourceReference instance instead. @return

()

Source from the content-addressed store, hash-verified

246 * if an I/O exception occurs.
247 */
248 public URL toURL() throws IOException {
249
250 // if the URI scheme is anything but creole then let java handle the
251 // conversion to a URL as it already knows how to do that
252 if(!uri.getScheme().equals("creole")) return uri.toURL();
253
254 try {
255 // create a URI that should point to the base of the plugin in which this
256 // resource resides
257 URI base = new URI("creole", uri.getAuthority(), "/", null, null);
258
259 for(Plugin plugin : Gate.getCreoleRegister().getPlugins()) {
260 // go through each plugin we know about until....
261
262 if(plugin.getBaseURI().equals(base)) {
263 // ... we find one with the base URI we are expecting and then
264
265 // create a new URL using the base URL of the plugin and the path from
266 // the URI we know points to the resource
267 String path = uri.getPath();
268 if(path.startsWith("/")) {
269 // strip off leading slash
270 path = path.substring(1);
271 }
272 return new URL(plugin.getBaseURL(), path);
273 }
274 }
275
276 // TODO if we can't find the plugin should we try loading it?
277
278 } catch(URISyntaxException e) {
279 // this is impossible so ignore it
280 log.debug("An impossible exception case happened, how?", e);
281 }
282
283 throw new IOException("Unable to locate URI: " + uri);
284 }
285
286 public URI toURI() {
287 return uri;

Callers 15

openStreamMethod · 0.95
openConnectionMethod · 0.95
loadObjectFromUriMethod · 0.95
testAnnicIndexingMethod · 0.80
testCreateFromURLMethod · 0.80
testSaveRestoreMethod · 0.80
testSimpleMethod · 0.80
testMultipleLrsMethod · 0.80
testDeleteMethod · 0.80

Calls 5

getCreoleRegisterMethod · 0.95
equalsMethod · 0.65
getPluginsMethod · 0.65
getBaseURIMethod · 0.45
getBaseURLMethod · 0.45

Tested by 11

testAnnicIndexingMethod · 0.64
testCreateFromURLMethod · 0.64
testSaveRestoreMethod · 0.64
testSimpleMethod · 0.64
testMultipleLrsMethod · 0.64
testDeleteMethod · 0.64
testDSRMethod · 0.64
testConfigUpdatingMethod · 0.64