[xwiki-users] Generating a DocumentReference
Hi, I am looking for a way to create a document reference without the “hassle” of worrying about the WikiName. In a listener, I get a document name which I use for input in a query. The result is a list of documentNames in the format [space.docname]. I need to transform this into a DocumentReference. I can do this without using the wiki, but this gives me “wiki” as the default Wiki. I gate get the wiki from (e.g.) the context, but this means I have to do - as far as I know - one of the two following creations: 1 - documentReferenceResolver ( wikiName + “:” + docFullName) Where docFullName is in the format [space.docname] 2 - new DocumentReference ( wikiName, spaceName, docName) In this case, I will have to split the fullName string in order to get access to the spaceName and the docName. If I use a query that delivers me only the pageName, I have the problem of not being able to resolve the spaceName. I am fairly sure I miss something essential here. Could someone help me out? I’m also fine with any answer that gives me a XWikiDocument :-) With kind regards, Peter
It all depend why you need a DocumentReference. * if you are in Velocity and need to pass a DocumentReference to a method then you can directly pass the string and it will be converted to DocumentReference automatically based on the current context * otherwise for this use case you are usually supposed to use a resolver: ** in Velocity: $services.model.resolveDocumet($docString) ** in java: the "current" DocumentReferenceResolver<String> in your case See http://extensions.xwiki.org/xwiki/bin/view/Extension/Model+Module#HResolving... for more detail about resolvers. On Wed, Aug 5, 2015 at 8:00 PM, Peter Huisman <[email protected]> wrote:
Hi,
I am looking for a way to create a document reference without the “hassle” of worrying about the WikiName. In a listener, I get a document name which I use for input in a query. The result is a list of documentNames in the format [space.docname]. I need to transform this into a DocumentReference. I can do this without using the wiki, but this gives me “wiki” as the default Wiki. I gate get the wiki from (e.g.) the context, but this means I have to do - as far as I know - one of the two following creations:
1 - documentReferenceResolver ( wikiName + “:” + docFullName)
Where docFullName is in the format [space.docname]
2 - new DocumentReference ( wikiName, spaceName, docName)
In this case, I will have to split the fullName string in order to get access to the spaceName and the docName. If I use a query that delivers me only the pageName, I have the problem of not being able to resolve the spaceName.
I am fairly sure I miss something essential here. Could someone help me out? I’m also fine with any answer that gives me a XWikiDocument :-)
With kind regards,
Peter _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
participants (2)
-
Peter Huisman -
Thomas Mortagne