Note that using relative references means that all code that accepts  
an EntityReference must check that it's valid and throw some exception  
if not, whereas before there was no need for any check and no  
exception throwing....

In most cases it's not possible for the code to run the normalizer  
since it wouldn't know which normalizer to use (the default one, the  
current one, etc?). It's the calling code that would know which  
normalizer to use...

My status:
* I have implemented the normalizer code (both Default normalizer and  
current normalizer)
* I'm now going to start re-implementing the entity reference  
factories and serializers
* I'm looking at existing code to see how the code would need to be  
adapted and I'm finding that in several cases it's going to be hard.  
Just to illustrate this take this code:

     public String getAttachmentURL(AttachmentReference  
attachmentReference, boolean isFullURL)
     {
         String url;
         if (isFullURL) {
             XWikiContext xcontext = getContext();
             url =  
xcontext 
.getURLFactory().createAttachmentURL(attachmentReference.getName(),
                  
attachmentReference 
.getDocumentReference().getLastSpaceReference().getName(),
                 attachmentReference.getDocumentReference().getName(),
                 "download", null,  
attachmentReference.getDocumentReference().getWikiReference().getName(),
                 xcontext).toString();
         } else {
             url =  
getAttachmentURL 
(this 
.entityReferenceSerializer 
.serialize(attachmentReference.getDocumentReference()),
                 attachmentReference.getName());
         }
         return url;
     }

There's now no guarantee that the passed reference has a non null  
attachment name, space name or wiki name. The code would need to  
verify this (or createAttachmentURL() would need to check it but  
that's the same). What should it do if it finds a null name? It cannot  
guess if it should use the current normalizer or the default normalizer.

The only solution I can see would be to check if the passed reference  
is absolute (using AttachmentReference.isAbsolute() for ex) and throw  
an InvalidEntityReference exception if it's not absolute.

But that's going to be a pain probably...

I'm still hesitating...

WDYT?

Thanks
-Vincent

On Dec 31, 2009, at 12:39 PM, Vincent Massol wrote:

> Hi devs,
>
> I'm almost done with my entity reference refactoring and I've just  
> realized I have missed something I think. So far the implementation  
> only supports Absolute references (i.e the entity reference factory  
> always return a reference with all parts filled - you choose to use  
> a default factory or a current entity depending on how you wish to  
> resolve the names when they have not been provided in the passed  
> reference string).
>
> I now think we must also support relative references (i.e. when some  
> parts can be null) and that it's up to the user of the api to decide  
> if they want to convert a relative reference to an absolute one or  
> not.
>
> Here's a use case: renaming of documents. For exemple documents have  
> links specified as a string representing the target doc name. If we  
> don't have relative references then we need to decide if we want to  
> use the default serializer (all parts printed including wiki name)  
> or the compact serializer (only parts different from context  
> reference printed). This doesn't support printing only what the user  
> had decided to fill. For ex a user might have specified voluntarily  
> the space and page name and right now with my implementation he'll  
> get only the page name specified if the new space is the same as the  
> space for the current doc.
>
> So here's my proposal:
>
> * Entity Reference Factory leaves parts to null when not specified  
> in the string representation.
> * We add a EntityReference.getAbsoluteReference(EntityReference  
> base) method to return an absolute reference. It's resolved against  
> the passed base reference (i.e. parts not specified are taken from it)
>
> WDYT?
>
> I'm going to start refactoring my code to do this later today so  
> please let me know if you see any pb with it.
>
> Thanks
> -Vincent
>
>

_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to