On Feb 17, 2010, at 10:45 AM, Jerome Velociter wrote:

>> Hi,
>> 
>> I'd like to suggest the following strategy for now:
>> 
>> * We modify all our vm files to use references (by using the
>> ModelScriptService, see below)
>> * We introduce APIs taking References in api.* (ex: api.Document,
>> api.XWiki)
>> * We _don't_ deprecate existing APIs in api.*. This means we allow users
>> to use the older string APIs for ease of use
> 
> Hello Vincent,
> 
> Before I can make up my mind, I would like to know:
> 
> * What will be the strategy for velocity code in wiki pages (here you
> mention only .vm pages - will the strategy be voted again for wiki pages?)
> 
> * Considering we use the same strategy for wiki pages, and since we do not
> deprecate the old APIs that manipulate strings, what will be the
> 'recommanded' way of say getting a document ? (the one we would advertise
> on xwiki.org code examples for example)

The decision to deprecate string-based APIs is open. I thought it was a bit 
early to do so before we have a proper full-fledged API from velocity. Maybe 
we'll do it in the future if we're happy about the referenced-based API.

The pb with the string based-api is that it's error-prone and that alone would 
be a good reason to deprecate it relatively quickly once we have moved our code 
to use the referenced-based APIs.

For ex:

#set ($var = .....)
$xwiki.getDocument("Main.${var}")

Has a high chance of being wrong. If var contains a "." or ":" and it's not 
escaped then it'll be wrong.

Thanks
-Vincent

> Thanks,
> Jerome
> 
> 
>> 
>> FYI here's what I've started adding in ModelScriptService:
>> 
>> @Component("model")
>> public class ModelScriptService implements ScriptService
>> {
>>    @Requirement
>>    private ComponentManager componentManager;
>> 
>>    public DocumentReference createDocumentReference(String wiki, String
>> space, String page, String hint)
>>    {
>>        EntityReference reference = null;
>>        if (!StringUtils.isEmpty(wiki)) {
>>            reference = new EntityReference(wiki, EntityType.WIKI);
>>        }
>>        if (!StringUtils.isEmpty(space)) {
>>            reference = new EntityReference(space, EntityType.SPACE,
>> reference);
>>        }
>>        if (!StringUtils.isEmpty(page)) {
>>            reference = new EntityReference(page, EntityType.DOCUMENT,
>> reference);
>>        }
>> 
>>        DocumentReference documentReference;
>>        try {
>>            documentReference =
>> this.componentManager.lookup(DocumentReferenceResolver.class,
>> hint).resolve(reference);
>>        } catch (ComponentLookupException e) {
>>            documentReference = null;
>>        }
>>        return documentReference;
>>    }
>> 
>>    public DocumentReference resolveDocument(String stringRepresentation,
>> String hint)
>>    {
>>        DocumentReference result;
>>        try {
>>            result =
>> this.componentManager.lookup(DocumentReferenceResolver.class,
>> hint).resolve(
>>                stringRepresentation);
>>        } catch (ComponentLookupException e) {
>>            result = null;
>>        }
>>        return result;
>>    }
>> 
>>    public String serialize(EntityReference reference, String hint)
>>    {
>>        String result;
>>        try {
>>            result = (String)
>> this.componentManager.lookup(EntityReferenceSerializer.class,
>> hint).serialize(reference);
>>        } catch (ComponentLookupException e) {
>>            result = null;
>>        }
>>        return result;
>>    }
>> }
>> 
>> Thanks
>> -Vincent
>> _______________________________________________
>> devs mailing list
>> [email protected]
>> http://lists.xwiki.org/mailman/listinfo/devs
>> 
> 
> 
> _______________________________________________
> devs mailing list
> [email protected]
> http://lists.xwiki.org/mailman/listinfo/devs

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

Reply via email to