[xwiki-users] access another document with groovy
Hello I have a little question and I couldn't find an answer on the internet... In a groovy part, I can create list the attachments of the current document with this : {{groovy}} list = doc.getAttachmentList(); print(list); {{/groovy}} how can I access the documents of another page in the same way? On a different page of the wiki I tried {{groovy}} list = XWiki.WebHome.getAttachmentList(); print(list); {{/groovy}} to get a list of the attachments on XWiki.WebHome, but it didn't work... Do you have any clue? Thank you very much ! Adrien
On Mon, Nov 10, 2014 at 5:02 PM, Adrien Moi <[email protected]> wrote:
Hello
I have a little question and I couldn't find an answer on the internet...
In a groovy part, I can create list the attachments of the current document with this : {{groovy}} list = doc.getAttachmentList(); print(list); {{/groovy}}
how can I access the documents of another page in the same way? On a different page of the wiki I tried {{groovy}} list = XWiki.WebHome.getAttachmentList(); print(list); {{/groovy}} to get a list of the attachments on XWiki.WebHome, but it didn't work...
Do you have any clue?
See http://platform.xwiki.org/xwiki/bin/view/SRD/xwiki xwiki.getDocument('XWiki.WebHome').getAttachmentList() Hope this helps, Marius
Thank you very much !
Adrien
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
In Groovy, you should take a look at the other binding API like `xwiki` in order to get a document. `xwiki`gives you an object of type `com.xpn.xwiki.api.XWiki`; this object has a `getDocument` method (you can find these informations in the API documentation [1]). For the use of this `getDocument`, you probably want to use references with `service.model` binding API. To resume in your example (not tested, just from memory) {{groovy}} def yourDocReference = service.model.createDocumentReference('xwiki', 'XWiki', 'WebHome') def yourDoc = xwiki.getDocument(yourDocReference) def list = yourDoc.getAttachmentList() {{/groovy}} Hope this helps ----- [1] http://platform.xwiki.org/xwiki/bin/view/DevGuide/API On Mon, Nov 10, 2014 at 04:02:32PM +0100, Adrien Moi wrote:
Hello
I have a little question and I couldn't find an answer on the internet...
In a groovy part, I can create list the attachments of the current document with this : {{groovy}} list = doc.getAttachmentList(); print(list); {{/groovy}}
how can I access the documents of another page in the same way? On a different page of the wiki I tried {{groovy}} list = XWiki.WebHome.getAttachmentList(); print(list); {{/groovy}} to get a list of the attachments on XWiki.WebHome, but it didn't work...
Do you have any clue?
Thank you very much !
Adrien
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Jean Simard [email protected] Research engineer at XWiki SAS http://www.xwiki.com Committer on the XWiki.org project http://www.xwiki.org
On Mon, Nov 10, 2014 at 4:17 PM, Jean SIMARD <[email protected]> wrote:
In Groovy, you should take a look at the other binding API like `xwiki` in order to get a document. `xwiki`gives you an object of type `com.xpn.xwiki.api.XWiki`; this object has a `getDocument` method (you can find these informations in the API documentation [1]).
For the use of this `getDocument`, you probably want to use references with `service.model` binding API.
To resume in your example (not tested, just from memory)
{{groovy}}
def yourDocReference = service.model.createDocumentReference('xwiki', 'XWiki', 'WebHome')
This service is more for script languages like Velocity which can't create object but in Groovy it's actually better to directly do def yourDocReference = new DocumentReference('xwiki', 'XWiki', 'WebHome')
def yourDoc = xwiki.getDocument(yourDocReference) def list = yourDoc.getAttachmentList() {{/groovy}}
Hope this helps
----- [1] http://platform.xwiki.org/xwiki/bin/view/DevGuide/API On Mon, Nov 10, 2014 at 04:02:32PM +0100, Adrien Moi wrote:
Hello
I have a little question and I couldn't find an answer on the internet...
In a groovy part, I can create list the attachments of the current document with this : {{groovy}} list = doc.getAttachmentList(); print(list); {{/groovy}}
how can I access the documents of another page in the same way? On a different page of the wiki I tried {{groovy}} list = XWiki.WebHome.getAttachmentList(); print(list); {{/groovy}} to get a list of the attachments on XWiki.WebHome, but it didn't work...
Do you have any clue?
Thank you very much !
Adrien
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Jean Simard [email protected] Research engineer at XWiki SAS http://www.xwiki.com Committer on the XWiki.org project http://www.xwiki.org _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
Date: Mon, 10 Nov 2014 16:23:33 +0100 From: [email protected] To: [email protected] Subject: Re: [xwiki-users] access another document with groovy
def yourDocReference = new DocumentReference('xwiki', 'XWiki', 'WebHome')
def yourDoc = xwiki.getDocument(yourDocReference) def list = yourDoc.getAttachmentList()
I tied it on my xwiki and when I type : {{groovy}} def yourDocReference = new DocumentReference('xwiki','XWiki','WebHome'); def yourDoc = xwiki.getDocument(yourDocReference); list=yourDoc.getAttachmentList(); println(list); {{/groovy}} I get this error.... Caused by: javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1677.groovy: 1: unable to resolve class DocumentReference @ line 1, column 24. def yourDocReference = new DocumentReference('xwiki','XWiki','WebHome'); did I miss anything?
That's because you did not imported the class, either you use the complete org.xwiki.model.reference.DocumentReference name, the String based API as suggested by Marius or you import org.xwiki.model.reference.DocumentReference at the beginning of your script. On Mon, Nov 10, 2014 at 5:51 PM, Adrien Moi <[email protected]> wrote:
Date: Mon, 10 Nov 2014 16:23:33 +0100 From: [email protected] To: [email protected] Subject: Re: [xwiki-users] access another document with groovy
def yourDocReference = new DocumentReference('xwiki', 'XWiki', 'WebHome')
def yourDoc = xwiki.getDocument(yourDocReference) def list = yourDoc.getAttachmentList()
I tied it on my xwiki and when I type : {{groovy}} def yourDocReference = new DocumentReference('xwiki','XWiki','WebHome'); def yourDoc = xwiki.getDocument(yourDocReference); list=yourDoc.getAttachmentList(); println(list); {{/groovy}} I get this error.... Caused by: javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1677.groovy: 1: unable to resolve class DocumentReference @ line 1, column 24. def yourDocReference = new DocumentReference('xwiki','XWiki','WebHome');
did I miss anything?
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
participants (4)
-
Adrien Moi -
Jean SIMARD -
Marius Dumitru Florea -
Thomas Mortagne