|
Re: URIConverter and href? [message #430155 is a reply to message #430144] |
Tue, 12 May 2009 14:58 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------080008000504040903020303
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Ingrid,
Comments below.
Ingrid wrote:
> Hi
>
> I have a few questions regarding the URIConverter. I'm new to EMF so I
> hope you can understand what I mean.
>
> I have some XML/(XMI?) files containing a bunch of hrefs which demands
> the referenced files to be located in the same directory. I want to be
> able to translate the URIs in these hrefs into other URIs which the
> user has mapped himself using a ProjectMapping model.
Perhaps you'll want to look at this option too:
/**
* 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";
>
> We want to let the user map some different types e.g:
> config -> path to configurationfiles
> test -> path to testfiles
>
> I guess it could look something like this.
> href="config:/configfile" -> href="file:/C:/configuration/configfile"
> href="test:/testfile" -> href="file:/C:/Development/test/testfile"
>
> Is this possible to do using the URIConverter? Can I map "config:/" to
> "file:/C:/configuration/", or do I have to map
> "platform:/resource/config/" to "file:/C:/configuration/"?
It looks like former should do the trick.
>
> I tried to create a ResourceSet (for reading the mappings) and an
> URIConverter like this when the user maps the data:
> ---
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
> (Resource.Factory.Registry.DEFAULT_EXTENSION,new
> XMIResourceFactoryImpl());
>
> // Register the package to ensure it is available during loading.
> resourceSet.getPackageRegistry().put(ProjectMappingsPackage. eNS_URI,ProjectMappingsPackage.eINSTANCE);
>
> uriConverter = new ExtensibleURIConverterImpl();
> resourceSet.setURIConverter(uriConverter);
The resource set already has a URI converter so this part is redundant.
> ---
> uri1 = URI.createURI("platform:/resource/" + mapping.getName() + "/");
> uri2 = URI.createFileURI(mapping.getPath() + "/");
> uriConverter.getURIMap().put(uri1, uri2);
> URI testURI = URI.createURI("platform:/resource/config/configfile");
> System.out.println("TestURI: " + testURI.toString());
> System.out.println("Normalized URI: " + uriConverter.normalize(testURI));
>
>
> When I test this with normalize in the code, it works. But how do I
> get this to work for the XML-files?
Keep in mind that relative URIs are resolved long before the URI
converter seems them. The option I pointed out above can be used to
control the resolution process during load as well as the deresolution
process during save.
> Can I get some kind of global ResourceSet where I set the URIConverter
> so that the framework can find the mappings when reading the XML-files?
Yes there is a global URI map. You should use the extension point to
populate that, not change it programmatically.
>
> The setting of the URIConverter on the ResourceSet above doesn't do it
> anyway.
Monitor closely what actual URIs are passed to the URI converter keeping
in mind my comment about the fact that relative URIs are resolved
syntactically during loading long before the URI converter is used to
map them.
>
> Thanks for any help.
> /Ingrid Berggren
>
--------------080008000504040903020303
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Ingrid,<br>
<br>
Comments below.<br>
<br>
Ingrid wrote:
<blockquote
cite="mid:de32d70790dc156f32bf8b493dbb2eeb$1@www.eclipse.org"
type="cite">Hi
<br>
<br>
I have a few questions regarding the URIConverter. I'm new to EMF so I
hope you can understand what I mean.
<br>
<br>
I have some XML/(XMI?) files containing a bunch of hrefs which demands
the referenced files to be located in the same directory. I want to be
able to translate the URIs in these hrefs into other URIs which the
user has mapped himself using a ProjectMapping model.
<br>
</blockquote>
Perhaps you'll want to look at this option too:<small><br>
</small>
<blockquote><small>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02860 seconds