How to obtain Resource URI's in-project relative path (for use in Xtext IGenerator IFileSystemAccess [message #1230878] |
Mon, 13 January 2014 04:45  |
Eclipse User |
|
|
|
Given an org.eclipse.emf.common.util.URI uri = "platform:/resource/MYPROJECT/some/sub/dir/myfile.ext" (IS-A URI$Hierachical), what is the correct API to obtain "some/sub/dir/myfile.ext" (note WITHOUT the MYPROJECT/) ?
This is in the context of an Xtext org.eclipse.xtext.generator.IGenerator, which has (only) an IResource as input (no base IProject), and where I'd like to obtain something like "some/sub/dir/myfile.ext" to use it as String fileName to pass into an (Xtext) org.eclipse.xtext.generator.IFileSystemAccess.generateFile().
Thank you!
|
|
|
|
Re: How to obtain Resource URI's in-project relative path (for use in Xtext IGenerator IFileSystemAc [message #1231226 is a reply to message #1230919] |
Tue, 14 January 2014 00:22  |
Eclipse User |
|
|
|
Michael,
Alternatively you might create a Path and use that the trim the first
segment. I'm not so keen on filling the URI class with infrequently
used utilities. It's unusual to want the project relative path. You
might take the approach like I did with Xcore or determining the root
of the file system access once:
URI uri = ((IFileSystemAccessExtension2)fsa).getURI(".");
And using URI.deresolve or URI.replacePrefix to produce URIs relative to
that root.
On 13/01/2014 12:25 PM, Michael Vorburger wrote:
> I've been able to "muddle" it like this, but this String
> manipulation-based approach is more of a workaround really:
>
> if (!uri.isPlatformResource())
> throw new IllegalArgumentException("Not a Platform
> Resource URI: " + uri.toString());
> String sURI = uri.toPlatformString(true);
> String withoutProject = sURI.substring(sURI.indexOf('/', 1) + 1);
>
>
> Is there a better way to do this? If there isn't, is it worthwhile to
> open a (low prio) bugzilla requesting an API for this?
|
|
|
Powered by
FUDForum. Page generated in 0.14173 seconds