Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » creating a URI containing Path Variables
creating a URI containing Path Variables [message #1250617] Wed, 19 February 2014 12:10 Go to next message
Kevin Milburn is currently offline Kevin MilburnFriend
Messages: 13
Registered: July 2012
Junior Member
I've been playing with some code utilising IPathVariableManager and have a small issue, the resolveURI function appears unusable (or I've missed something).

If I do this,
IPath p = new Path("${PROJECT_LOC}/file/in/project");
p = pathVariableManager.resolvePath(p);
everything works as expected, but I get a warning that resolve path is deprecated and should use resolveURI instead.

The snag is, how to create a URI which contains a path variable.

URI uri = new URI("${PROJECT_LOC}/file/in/project");
causes a java.net.URISyntaxException: Illegal character in path at index 1: ${project_loc}/file/in/project (adding file:/ just moves the error to index 7)

URI uri = new File("${PROJECT_LOC}/file/in/project").toURI();
creates a URI along the lines of c:/work/eclipse/$%7BPROJECT_LOC%7D/file/in/project, which is invalid and won't resovle.

Given that the resolveURI method exists, is a replacement for resolvePath and its javadoc implies it will do the required resoltion of variables, how do you create a URI containing the approriate value to pass to the method?
Re: creating a URI containing Path Variables [message #1250651 is a reply to message #1250617] Wed, 19 February 2014 12:57 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Kevin,

Comments below.

On 19/02/2014 1:10 PM, Kevin Milburn wrote:
> I've been playing with some code utilising IPathVariableManager and
> have a small issue, the resolveURI function appears unusable (or I've
> missed something).
>
> If I do this, IPath p = new Path("${PROJECT_LOC}/file/in/project");
> p = pathVariableManager.resolvePath(p);
> everything works as expected, but I get a warning that resolve path is
> deprecated and should use resolveURI instead.
That's kind of annoying... It appears that both implementations of
resolveURI only work with (i.e., return something useful for) relative
URIs , which can just as nicely be represented as paths...
>
> The snag is, how to create a URI which contains a path variable.
>
> URI uri = new URI("${PROJECT_LOC}/file/in/project");causes a
> java.net.URISyntaxException: Illegal character in path at index 1:
> ${project_loc}/file/in/project (adding file:/ just moves the error to
> index 7)
Looking at the implementation I imagine that you're supposed to pass in
new URI("$%7BPROJECT_LOC%7D/file/in/project")...
>
> URI uri = new File("${PROJECT_LOC}/file/in/project").toURI();creates a
> URI along the lines of
> c:/work/eclipse/$%7BPROJECT_LOC%7D/file/in/project, which is invalid
> and won't resovle.
>
> Given that the resolveURI method exists, is a replacement for
> resolvePath and its javadoc implies it will do the required resoltion
> of variables, how do you create a URI containing the approriate value
> to pass to the method?
I think that if you used this constructor, it would escape the braces
and it looks like

java.net.URI uri = new java.net.URI(null, "${x}/y", null);
System.out.println("###" + uri.getRawSchemeSpecificPart());
System.out.println("###" + uri.getSchemeSpecificPart());


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: creating a URI containing Path Variables [message #1250746 is a reply to message #1250651] Wed, 19 February 2014 14:59 Go to previous message
Kevin Milburn is currently offline Kevin MilburnFriend
Messages: 13
Registered: July 2012
Junior Member
Hi Ed

Thanks for the info, using the scheme-specific part achieves what I'm after, without me having to convert the string myself!

With correct escaping even the normal URI constructor would work, I'm sure I tred it before, but probably escaped too much as the resolve didn't work.

Thanks again..
Kevin



Previous Topic:How to convert an Editor to a View ?
Next Topic:DND - CNF dropAssistant doesn't get executed
Goto Forum:
  


Current Time: Fri Apr 26 17:45:05 GMT 2024

Powered by FUDForum. Page generated in 0.03319 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top