Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
Description
The UimaContext.getResourceURL() method is difficult to use correctly. It is tempting for users to write code such as:
URL url = getContext().getResourceURL(key);
FileReader fr = new FileReader(url.getPath());
which is not safe since the URL can contain spaces encoded as %20, and the url.getPath() does not automatically decode them.
We should add the alternative methods and appropriate JavaDoc comments guiding the user toward the appropriate method:
URI getResourceURI() – this works better because URI.getPath() does do decoding.
String getResourceFilePath() – if the URL is a "file:" URL, return its decoded path, otherwise throw an exception (e.g., for an "http" URL)
Additionally, it would be nice if we supported filenames (without the file: prefix) in the <fileUrl> descriptor element, for example:
<fileUrl>c:/program files/myproj/myfile.txt</fileUrl>
Currently this gives a MalformedUrlException, but it would be helpful for the framework to detect that exception and try appending "file:/" to see if that makes a valid URL.