Thanks for sharing Thomas and Jérôme,
> However, I
wonder if this is the best practice:
There is no official best practice actually so
it's going to be my
personal point of view.
That's already good (and good to know).
- is it expensive to construct a context and xwiki
supposing this setup
code is run multiple times?
As far as I know there is not much overhead to
construct the api wrapper.
Not by creating the API wrapper itself but keep in mind that every
time you call some of the script API methods (like save and
getDocument in your example) you will have a right test behind the
scene for many of them.
This is a very important point.
Is there no way to still have the API luxury and disable rights' check?
If no, then indeed, it would be useful to migrate to the base classes but they seem to be
harder to work with.
If you are in a Java code where you know you can do
everything and
don't care about the rights you should use the com.xpn.xwiki.*
classes. Those class have the same level of retro compatibility than
the api.* classes so that should not be an issue.
I could attempt this but I had a much harder time to do that.
- is DocReference behaving much differently than
fullName if we have a
single wiki?
Yes in the sense it handles escaping properly. It matters if you don't have
control over document names, it matters less if you do have this control
(for example you generate the name automatically or clean user input with
defined rules). I try to use the reference (a.k.a new model) API as often as
possible, but I admit sometimes it feels just too much when you know you're
not having escaping issues or multiwiki issues. Those times I do things like
xwiki.getDocument("XWiki.XWikiPreferences") and just live with it happily :)
Of course I'm speaking about my experience of using XWiki for my own needs
as an API consumer, not about the development of the XWiki platform.
Not much to add here but I think I'm using document reference way more
than Jerome even wen I "control the name" ;)
When you do xwiki.getDocument("XWiki.XWikiPreferences") a resolver is
called to parse ir and resolve the current wiki to create the
DocumentReference so it's better to create a DocumentReference
directly when you know all the three parts.
So here's a simple question: how do you simply create a document reference with a
String?
I think the area of working with the base class is where I miss a tutorial.
paul