Skip to main content



      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 04:45 Go to next message
Eclipse UserFriend
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 06:25 Go to previous messageGo to next message
Eclipse UserFriend
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 00:22 Go to previous message
Eclipse UserFriend
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?
Previous Topic:Initialize Xcore/XTextResourceFactory
Next Topic:Mapping Model:InstanceType Name or Extending Model
Goto Forum:
  


Current Time: Tue Jul 15 03:01:16 EDT 2025

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

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

Back to the top