Hi Paul,

On 09/12/2012 11:47 PM, Paul Libbrecht wrote:
hello fellow developers,

at Curriki, we are starting to process XWiki objects in the background using 
subclasses of AbstractXWikiRunnable.

Currently I do the following:
                
                // setup
                 XWikiContext xcontext = (XWikiContext) 
Utils.getComponent(Execution.class).getContext()
                         .getProperty(XWikiContext.EXECUTIONCONTEXT_KEY);
                 Context context = new Context(xcontext);
                 XWiki xwiki = new com.xpn.xwiki.api.XWiki(context.getXWiki(), 
xcontext);

                 // fetch background info
                 Document d = xwiki.getDocument(DOCNAME_x);

                Object obj = d.getObject("DOCNAME_class");
                // modify something

                // save
                 d.save("comment");

However, I wonder if this is the best practice:

- 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.

- is it preferrable to work with the com.xpn.xwiki.* classes?

Now I tend to prefer working as much as possible with api.* classes rather than internal classes, for no specific reason other than the fact they are proper APIs vs. de facto APIs and that I'm sure I have the same behavior as when writing scripts.

- 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.

That was my 2 cents, hope it helped having perspective on what others do,
Jerome


Thanks in advance.

Paul
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs


--
Peace,
—Jerome

_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to