Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to obtain Resource URI's in-project relative path (for use in Xtext IGenerator IFileSystemAccess
How to obtain Resource URI's in-project relative path (for use in Xtext IGenerator IFileSystemAccess [message #1230878] Mon, 13 January 2014 09:45 Go to next message
Michael Vorburger is currently offline Michael VorburgerFriend
Messages: 103
Registered: July 2009
Senior Member
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 #1230919 is a reply to message #1230878] Mon, 13 January 2014 11:25 Go to previous messageGo to next message
Michael Vorburger is currently offline Michael VorburgerFriend
Messages: 103
Registered: July 2009
Senior Member
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?
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 05:22 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
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?


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Initialize Xcore/XTextResourceFactory
Next Topic:Mapping Model:InstanceType Name or Extending Model
Goto Forum:
  


Current Time: Thu Mar 28 09:16:51 GMT 2024

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

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

Back to the top