On Thu, Sep 13, 2012 at 11:59 AM, Paul Libbrecht <paul(a)hoplahup.net> wrote:
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.
Well I don't find the java API much more complex than the script API,
its pretty much the same things. The main differences are:
* you have to pass the context in most of the methods
* you save a document by doing xwiki.save(document) instead of document.save()
If you look at the api.* classes implementations you can see that most
of the methods just call the same methods and add context as parameter
(and sometimes not even).
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.
See
http://extensions.xwiki.org/xwiki/bin/view/Extension/Model+Module
for details and examples about references in general.
Now it depends on what is your input exactly, if what you get from the
user is the actual full name of the document as String then you will
not add much value when converting it on you side before calling
getDocument obviously.
paul
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs
--
Thomas Mortagne