Creating href [message #656556] |
Sat, 26 February 2011 13:08  |
Eclipse User |
|
|
|
I have a template resource at the workspace level so UI preferences are defined as per user. However, this resource contains proxy references to resources in the project(s) that the user has created.
Currently, all href are being set the uri of the main container template resource when it is saved.
So, is there a way I can change the contained href to point to each individual project when the template resource is saved?
/workspace/user_resource.xmi
href=/workspace/projectA/myResources/resource1.xmi
|
|
|
|
|
Re: Creating href [message #656846 is a reply to message #656580] |
Mon, 28 February 2011 13:55   |
Eclipse User |
|
|
|
The method below, it seems to do what I need. However, resourceSet.getURIConverter().exists(uri, null) return false if I add the URI map before the template resource in the plugin is loaded.
.....
...
resourceSet.getURIConverter().getURIMap().putAll(computePlat formPluginToPlatformResourceMap());
if (resourceSet.getURIConverter().exists(uri, null)) {
try {
timelineResource = resourceSet.getResource(uri, true);
.....
...
//-----------------------
public static Map<URI, URI> computePlatformPluginToPlatformResourceMap() {
Map<URI, URI> result = new HashMap<URI, URI>();
IWorkspaceRoot root = EcorePlugin.getWorkspaceRoot();
if (root != null) {
IProject[] projects = root.getProjects();
if (projects != null) {
for (IProject project : projects) {
if (project.isOpen()) {
URI platformPluginURI = URI.createPlatformPluginURI("plugin_ID/datafiles" + "/", false);
URI platformResourceURI = URI.createPlatformResourceURI(project.getName() + "/", true);
result.put(platformPluginURI, platformResourceURI);
}
}
}
}
return result;
}
//----
In summary, the template.xmi containig a relative href="datafiles/myresource1.xmi#S_AVAIL"/ and when it is loaded from the plugin, the href is change to the location of the template.xmi resource (ie. platform:/plugin/plugin_location/datafiles/myresource1.xmi#S _AVAIL ").
However, that template is then saved into the user workspace as user.xmi and there is when I need the href to be converted from platform:/plugin/ to platform:/resource/project_id/
I tried to set the URIMap in the resourceset before I save it, but it doesn't affect anything. Any suggestion will be greatly appreciated!
|
|
|
Re: Creating href [message #656854 is a reply to message #656846] |
Mon, 28 February 2011 14:13   |
Eclipse User |
|
|
|
AJ,
Comments below.
AJ wrote:
> The method below, it seems to do what I need. However,
> resourceSet.getURIConverter().exists(uri, null) return false
Kind of losing context here given your posting is appearing as a new
top-level thread...
For which URI?
> if I add the URI map before the template resource in the plugin is
> loaded.
>
> ....
> ..
> resourceSet.getURIConverter().getURIMap().putAll(computePlat
> formPluginToPlatformResourceMap());
> if (resourceSet.getURIConverter().exists(uri, null)) {
> try {
> timelineResource = resourceSet.getResource(uri, true);
> ....
> ..
>
> //-----------------------
> public static Map<URI, URI>
> computePlatformPluginToPlatformResourceMap() {
> Map<URI, URI> result = new HashMap<URI, URI>();
> IWorkspaceRoot root = EcorePlugin.getWorkspaceRoot();
> if (root != null) {
> IProject[] projects = root.getProjects();
> if (projects != null) {
> for (IProject project : projects) {
> if (project.isOpen()) {
> URI platformPluginURI =
> URI.createPlatformPluginURI("plugin_ID/datafiles" + "/", false);
> URI platformResourceURI =
> URI.createPlatformResourceURI(project.getName() + "/", true);
> result.put(platformPluginURI,
> platformResourceURI);
> }
> }
> }
> }
> return result;
> }
This is intended for redirecting URIs pointing at the installed IDE's
plugins to their equivalent in the workspace...
> //----
>
>
> In summary, the template.xmi containig a relative
> href="datafiles/myresource1.xmi#S_AVAIL"/ and when it is loaded from
> the plugin, the href is change to the location of the template.xmi
> resource (ie.
> platform:/plugin/plugin_location/datafiles/myresource1.xmi#S _AVAIL ").
If that URI is relative it is expected to exist in the plugins.
> However, that template is then saved into the user workspace as
> user.xmi and there is when I need the href to be converted from
> platform:/plugin/ to platform:/resource/project_id/
How is it that installed plugins should have data files that point into
the workspace? A workspace could be empty...
>
> I tried to set the URIMap in the resourceset before I save it, but it
> doesn't affect anything. Any suggestion will be greatly appreciated!
The map won't affect the URIs used when saving. The logical URIs on the
resources themselves will always be used.
Maybe taking a step back will help. How is it that an installed
plug-in's data files should be pointing into the workspace? Of course
you can do that with a platform:/resource URI, but you have relative
URIs. How does it end up that way?
|
|
|
|
Re: Creating href [message #657085 is a reply to message #656878] |
Tue, 01 March 2011 10:00  |
Eclipse User |
|
|
|
AJ,
Comments below.
AJ wrote:
> Hi Ed,
>
> Yes, let's step back. I hope I can now formulate my question/problem
> better.
>
> I have resource loaded from the user workspace and it contains
> no-containment references to resources that might or might not exist
> in a user's project.
Sounds pretty fuzzy.
>
> These hrefs look like this:
>
> <profile href="project:/Resources/resouceA.xmi#ALL_AVAIL"/>
So this is a scheme you've synthesized instead of using
platform:/resource/<project>....?
>
> Is there a mechanism where I can resolve in runtime my "project/..."
> scheme to "platform:/resource/current_project/..." and convert it back
> to "project/..." when the resource is saved?
You could look into using
/**
* A {@link URIHandler} value that will be used to control how URIs
are {@link URI#resolve(URI) resolved} during load
* and {@link URI#deresolve(URI) deresolved} during save.
* @see URI
* @see URIHandler
* @see XMLHelper#resolve(URI, URI)
* @see XMLHelper#deresolve(URI)
* @see URIHandlerImpl
*/
String OPTION_URI_HANDLER = "URI_HANDLER";
>
> Can it be done via URIConverter or URIHandler?
The URIConverter supports folder remapping... It's not clear to me why
you need your own scheme?
>
> Thank again, Ed!
|
|
|
Powered by
FUDForum. Page generated in 0.17087 seconds