JDK-6226081 : URI should be able to relativize paths with partial roots
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 5.0
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-02-07
  • Updated: 2018-11-15
Description
A DESCRIPTION OF THE REQUEST :
At the moment, the relativize() method of URI will only  relativize URIs when one is a prefix of the other.  It would be useful, however to be able to do things like

    public static void main(String[] argv)
    {
        try
        {
            URI a = new URI("file:/c:/abc/def/myDocument/doc.xml");
            URI b = new URI("file:/c:/abc/def/images/subdir/image.png");
            
            URI c = a.relativize(b);
            
            System.err.println(c);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

If this returned a URI of ../images/subdir/image.png,  it would make my job implementing editors much easier

JUSTIFICATION :
Current relativize method is too limited.
###@###.### 2005-2-07 10:44:17 GMT