On Wed, May 30, 2012 at 6:21 PM, Thomas Mortagne
<thomas.mortagne(a)xwiki.com> wrote:
On Wed, May 30, 2012 at 4:46 PM, Jeremie BOUSQUET
<jeremie.bousquet(a)gmail.com> wrote:
Hello,
I'm wondering if I'm on the good path ...
I'm trying to move out some "old core" api usage, and replace them
using the DocumentAccessBridge (3.5.1), in a java component.
Considering a very simple use-case : setting property value of an
object. Here the document containing object is not in same space as
the class.
1- With old core:
XWikiDocument doc = context.getWiki().getDocument("Prefs.Document", context);
BaseObject obj = serverDoc.getObject("Code.Class");
obj.set("property", value, context);
2- With DAB, using deprecated method:
dab.setProperty("Prefs.Document", "Code.Class", "property",
value);
3- With DAB, using non-deprecated methods:
SpaceReference prefsSpaceRef = new SpaceReference(new
EntityReference("Prefs", EntityType.SPACE));
DocumentReference prefsDocRef = new DocumentReference("Document",
prefsSpaceRef);
SpaceReference codeSpaceRef = new SpaceReference(new
EntityReference("Code", EntityType.SPACE));
DocumentReference classDocRef = new DocumentReference("Class",
codeSpaceRef);
dab.setProperty(prefsDocRef, classDocRef, "property", value);
Did you tested that ? Having a null WikiReference is actually
forbidden in SpaceReference. DocumentReference is supposed to be a
valid and complete document reference which mean including the wiki
reference.
Sorry, I was thinking at the script service, which allows you to pass
null but resolves the created entity reference. So yes, you need to
pass a non-null wiki name.
Thanks,
Marius
Questions:
a- the code with 3- is, IMO, quite verbose compared to the others. Is
it really the best way to do this ? Of course I could store the
SpaceReference objects to factorize their use and simplify the code.
I'd better be sure before recoding all this ...
b- what's the best practice, for a component, to properly manage the
targeted wiki, in order to be single/multi-wiki/workspaces proof ?
Here I didn't bother specifying the targeted wiki, if I do it will add
more "*Reference" creations.
c- is there any facility method to convert an oldish xwiki document
reference (as "wiki:Space.Page" or "Space.Page") to a
DocumentReference ?
By the way, is the bridge API representative of the future new xwiki
data model that will replace old core, or is it only representative of
the current bridge api ?
Thanks,
Jeremie
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users
--
Thomas Mortagne
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users