Accessing Document XObject from Java API

Hi,

(Hopefully, I’ve got the nomenclature correct…)

I’m writing an extension that needs to check whether a Document has an xobject attached as that object (of a particular type of xclass) acts as a flag for performing additional functionality that the extension provides.

The extension is currently using an injected reference to the XWikiContext via a provider…

@Inject
private Provider<XWikiContext> xwikiContextProvider;

…and uses that to access the Document XObjects…

final XWikiContext xwikiContext = xwikiContextProvider.get();
final XWiki wiki = xwikiContext.getWiki();
final XWikiDocument document = wiki.getDocument(docRef, xwikiContext);
final BaseObject object = document.getXObject(FLAG_OBJECT);

FLAG_OBJECT is a LocalDocumentReference that refers to the xclass name.

However, this creates a dependency on the oldcore so I was wondering whether there is a new way to do this?

My extension is actually an AuthorizationSettler so that API gives me EntityReferences. I was wondering whether there’s a way to access xobjects via Document/Entity References? I found documentation on a PageObjectReferenceResolver but couldn’t quite work out how to use it.

Thanks in advance,
Alex

There is no real alternative to BaseObject but you can take a look at https://extensions.xwiki.org/xwiki/bin/view/Extension/Model%20Bridge%20API.

You have org.xwiki.bridge.DocumentAccessBridge#getProperty and org.xwiki.bridge.DocumentAccessBridge#setProperty but it’s very basic compared to what you can do with BaseObject (but maybe it’s enough for your use case). Honestly, DocumentAccessBridge is not really cleaner than oldcore on the long run, but it can help if depending on oldcore cause a technical problem.

That’s what org.xwiki.bridge.DocumentAccessBridge#getProperty is manipulating.

Thanks @tmortagne once again for your help, I’ll take a look at the bridge.

Cheers