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
()
| 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; |