Uploaded image for project: 'UIMA'
  1. UIMA
  2. UIMA-132

Provide better support for filenames with spaces in resource URL

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 2.1
    • Core Java Framework
    • 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.

      Attachments

        Activity

          People

            alally Adam P. Lally
            alally Adam P. Lally
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: