On Thu, Nov 24, 2016 at 12:09 PM, Pascal BASTIEN <pbasnews-xw...@yahoo.fr> wrote: >> > >> > I use this methods, >> hasParent(EntityReference expectedParent) and i noticed that >> I can not use string to set EntityReference. >> > Then i must use this before: "#set >> ($reference = >> $services.model.resolveSpace('xwiki:Encyclopédie'))" >> and "$doc.documentReference.hasParent($reference)" >> because >> $doc.documentReference.hasParent('xwiki:Encyclopédie') >> doesn't work. >> > Am I right? Anyway, I >> can understand that. >> >> There >> is one magic thing about Velocity in XWiki that you need to >> keep >> in mind: it automatically convert >> parameters to the right type (when >> there is >> a converter provided for that type). >> >> For example the converter for the type >> EntityReference understand the >> following >> syntax: [<entitytype>:]<entityreference> (the >> default entity >> type is "document" >> if you don't provide it) so the space with >> reference "xwiki:Encyclopédie" will >> be the string >> "space:xwiki:Encyclopédie" as in >> hasParent('space:xwiki:Encyclopédie'). > > Right :-) $doc.documentReference.hasParent('space:xwiki:Encyclopédie') work > well but I don't understand why we must use "xwiki" in space name.
You don't have to use "xwiki". "xwiki" is is the wiki in which the space is located, if you want the space "Encyclopédie" in the current wiki then just don't put the wiki as in $doc.documentReference.hasParent('space:Encyclopédie'). Keep it mind that we are talking about the space reference here, not the space name. > I suppose I must use all space path. > >> >> > >> > >> Another point about documentation >> http://extensions.xwiki.org/xwiki/bin/view/Extension/Model+Module#HScriptServiceAPI >> (because I spend a lot of time to identify my issue >> because the "x" characters: >> > >> Create a Document Reference: "#set ($reference = >> $services.model.createDocumentReference("wiki", >> ["space"], "page"))" >> > but >> > >> $doc.documentReference.spaceReferences.get(0) display >> "Space xwiki:Encyclopédie". >> > >> Reference use "xwiki" but createDocumentReference >> use "wiki"? >> > "wiki" >> is it a wiki name example? >> >> I don't really understand your example >> $services.model.createDocumentReference("wiki", >> ["space"], "page") >> have >> nothing to do with $doc.documentReference. It just means you >> are >> executing this script on main wiki >> ("xwiki"). >> >> > >> > Another question: >> > What is the difference between: >> $services.model.createDocumentReference and >> services.model.resolveDocument? >> > With >> resolveDocument the Page must exist? >> > >> Can I use CreateDocumentReference if target document >> exist? >> >> resolveDocument take >> a reference as a String and parse it (it's using >> a DocumentResolver component for this) and find >> what is not provided >> in the String (by >> default from the context) while >> createDocumentReference takes each element of >> the reference separately >> and know nothing >> about reference syntax. >> >> > > I mean: is it the same utility? > #set ($reference = $services.model.createDocumentReference("wiki", > ["space1","space2"], "page")) > #set ($reference = $services.model.resolveDocument("wiki:space1.space2.page)) Yes those two lines happen to produce the same result but they actually are two very different things. In practice the second one parse the script to find all elements and then end up calling the first API (it's not exactly the same API in but its internal version). There is use cases where you simply can't use the first API because all your script get in input is a single String with the reference and cases where you have separated elements and create a String directly would be a pain because then you have to deal yourself with escaping and use the right separators. > >> > >> > Last point: >> > I think these 2 simples examples missing >> in: >> http://extensions.xwiki.org/xwiki/bin/view/Extension/Model+Module#HScriptServiceAPI >> > #set ($reference = >> $services.model.resolveSpace('xwiki:MySpace')) >> > #set ($reference = >> $services.model.resolveSpace('xwiki:MySpace.MyPage')) >> > What do you think? >> >> Not sure people create space references that >> much but sure why not. > > Sorry I wanted to write: > #set ($reference = $services.model.resolveSpace('xwiki:MySpace')) > #set ($reference = $services.model.resolveDocument('xwiki:MySpace.MyPage')) > but mayb it is not necessary because you told me than xwiki automatically > convert parameters to the right type. There is other uses for DocumentReference that passing it as parameter but it's usually when you have a variable for which you don't know the value. > > _______________________________________________ > users mailing list > users@xwiki.org > http://lists.xwiki.org/mailman/listinfo/users -- Thomas Mortagne _______________________________________________ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users