Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Persistence of non-containment cross references with spaces
Persistence of non-containment cross references with spaces [message #718490] Wed, 24 August 2011 13:52 Go to next message
Nidhi  is currently offline Nidhi Friend
Messages: 92
Registered: December 2009
Member

Hi,

I am referring an EObject from one ecore to another. This is a non-containment reference. The persistence looks like this:

<... href="/Test%20Me/Pro1.tst#_4wyTYc4HEeCaneWx28f2tg"/>

How can I have a persistence where space is not replaced by "%20".

Thanks a lot for any help!

Best Regards,
Nidhi
Re: Persistence of non-containment cross references with spaces [message #718574 is a reply to message #718490] Wed, 24 August 2011 17:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Nidhi,

The URI that's used will be based exactly on the one on the
Resource.getURI of the resource containing the object, so you'd need to
change that resource's URI, which is probably a bad idea. Alternatively
you could use OPTION_URI_HANDLER to take control over how the deresolved
URI is constructed during serialization.



On 24/08/2011 6:52 AM, Nidhi wrote:
> Hi,
>
> I am referring an EObject from one ecore to another. This is a
> non-containment reference. The persistence looks like this:
>
> <... href="/Test%20Me/Pro1.tst#_4wyTYc4HEeCaneWx28f2tg"/>
>
> How can I have a persistence where space is not replaced by "%20".
>
> Thanks a lot for any help!
>
> Best Regards,
> Nidhi


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Persistence of non-containment cross references with spaces [message #718676 is a reply to message #718574] Thu, 25 August 2011 03:03 Go to previous messageGo to next message
Nidhi  is currently offline Nidhi Friend
Messages: 92
Registered: December 2009
Member

Hi Ed,

Thanks for the pointer.
In my ResourceFactoryImpl -> createResource , I add the following
result.getDefaultLoadOptions().put(XMLResource.OPTION_URI_HANDLER, new MyURIHandler());


And in the MyURIHandler, I added the following method
          
          public void setBaseURI(URI uri)
	  {
	    baseURI = uri;
	    baseURI = URI.createURI(URI.decode(baseURI.toString()));
	    resolve = uri != null && uri.isHierarchical() && !uri.isRelative();
	  }

However, the persistence still has the escape characters (%20) for spaces.

Best Regards,
Nidhi

[Updated on: Thu, 25 August 2011 03:04]

Report message to a moderator

Re: Persistence of non-containment cross references with spaces [message #718708 is a reply to message #718676] Thu, 25 August 2011 06:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Nidhi,

There's OPTION_SKIP_ESCAPE_URI but it's true by default. Note that I've
already explained that the containing resource's URI will be used and
very likely that's been encoded. You've looked into that?



On 24/08/2011 8:03 PM, Nidhi wrote:
> Hi Ed,
>
> Thanks for the pointer.
> In my ResourceFactoryImpl -> createResource , I add the following
> result.getDefaultLoadOptions().put(XMLResource.OPTION_URI_HANDLER, new
> MyURIHandler());
>
> And in the MyURIHandler, I added the following
> methodhttp://www.eclipse.org/forums/index.php/r/frm_id/108/
> public void setBaseURI(URI uri)
> {
> baseURI = uri;
> baseURI = URI.createURI(URI.decode(baseURI.toString()));
> resolve = uri != null && uri.isHierarchical() &&
> !uri.isRelative();
> }
>
> However, the persistence still has the escape characters (%20) for
> spaces.
>
> Best Regards,
> Nidhi
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Persistence of non-containment cross references with spaces [message #741072 is a reply to message #718708] Wed, 19 October 2011 06:44 Go to previous messageGo to next message
Nidhi  is currently offline Nidhi Friend
Messages: 92
Registered: December 2009
Member

Hi Ed,

By containing resource did you mean the resource that has the non-containment reference to another resource or the other resource being referred to itself.

In any case for both the resources the URI is created using
URI uri = URI.createPlatformResourceURI(getFullPath().toOSString(), false);


What I see is that even if the actual element being referred to is not encoded, its path still is if it has spaces. So now this is what I get:

<bpmnActivity href="../A%209/processes/P%209/bpmn/P 9.bpmn#_uJAVMfohEeCclpLNrG3JWg"/>


If you see "P 9.bpmn" is referred properly but it was contained in a folder "P 9" which is encoded.

Best regards,
Nidhi

[Updated on: Wed, 19 October 2011 07:16]

Report message to a moderator

Re: Persistence of non-containment cross references with spaces [message #741109 is a reply to message #741072] Wed, 19 October 2011 07:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Nidhi,

Comments below.

On 19/10/2011 8:44 AM, Nidhi wrote:
> Hi Ed,
>
> By containing resource did you mean the resource that has the
> non-containment reference to another resource or the other resource
> being referred to itself.
If you have a reference to some object x, the URI of x.eResource (x's
containing resource), will be used.
>
> In the first case, the resource containing the reference, it's URI is
> not encoded as I pass the option OPTION_SKIP_ESCAPE_URI with true as
> the value while saving the resource. I also do the same thing for
> resource being referred to.
Escaping has to do with XML escaping, i.e., using &gt; in place of >.
>
> Thanks a lot, am really confused what is going wrong even after
> setting this option true explicitly whenever I am saving the resource.
Look at what the other methods (resolve) are doing. You might want to
decode there. Be forewarned that spaces in URIs are a bad idea and that
reading the result may work poorly.
>
> Best regards,
> Nidhi


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Persistence of non-containment cross references with spaces [message #741130 is a reply to message #741109] Wed, 19 October 2011 07:53 Go to previous messageGo to next message
Nidhi  is currently offline Nidhi Friend
Messages: 92
Registered: December 2009
Member

Hi Ed,

Thanks for the pointers. Exactly its a bad idea but removing "%20" in the URI is needed by another component trying to consume the persistence.

I checked the containing resource URI, and now use the following API to avoid encoding:

URI uri = URI.createPlatformResourceURI(getFullPath().toOSString(), false);


What I see is that even if the actual element being referred to is not encoded, its path still is if it has spaces. So now this is what I get:

<bpmnActivity href="../A%209/processes/P%209/bpmn/P 9.bpmn#_uJAVMfohEeCclpLNrG3JWg"/>


If you see "P 9.bpmn" is referred properly but it was contained in a folder "P 9" which is encoded.

Best regards,
Nidhi
Re: Persistence of non-containment cross references with spaces [message #741146 is a reply to message #741130] Wed, 19 October 2011 08:17 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Nidhi,

Have you set breakpoints in the handler's resolve and deresolve methods
to see what's going in and what's coming out? Have you looked in the
resource set and actually confirmed that all the resources have the URIs
you're hoping (and they they don't have a URI based on demand loading
from a previously serialized version that uses %20)?

On 19/10/2011 9:53 AM, Nidhi wrote:
> Hi Ed,
>
> Thanks for the pointers. Exactly its a bad idea but removing "%20" in
> the URI is needed by another component trying to consume the persistence.
>
> I checked the containing resource URI, and now use the following API
> to avoid encoding:
>
> URI uri = URI.createPlatformResourceURI(getFullPath().toOSString(),
> false);
> What I see is that even if the actual element being referred to is not
> encoded, its path still is if it has spaces. So now this is what I get:
>
> <bpmnActivity href="../A%209/processes/P%209/bpmn/P
> 9.bpmn#_uJAVMfohEeCclpLNrG3JWg"/>
>
> If you see "P 9.bpmn" is referred properly but it was contained in a
> folder "P 9" which is encoded.
>
> Best regards,
> Nidhi


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO]Legacy mode switched off
Next Topic:Deserializing a serialized meta model that contains cross references
Goto Forum:
  


Current Time: Tue Apr 16 06:52:42 GMT 2024

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

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

Back to the top