use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class UntypedRecordableEventDescriptorComponentBuilderTest method testBuildComponent.
@Test
public void testBuildComponent() throws Exception {
BaseObject baseObject = mock(BaseObject.class);
XWikiDocument parentDocument = mock(XWikiDocument.class);
DocumentReference documentReference = mock(DocumentReference.class);
when(baseObject.getOwnerDocument()).thenReturn(parentDocument);
when(parentDocument.getDocumentReference()).thenReturn(documentReference);
// Ensure that the user rights are correctly checked
when(this.authorizationManager.hasAccess(any(), any(), any())).thenReturn(true);
List<WikiComponent> result = this.mocker.getComponentUnderTest().buildComponents(baseObject);
assertEquals(1, result.size());
}
use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class EditorWikiComponent method getDescriptor.
@Override
public EditorDescriptor getDescriptor() {
try {
XWikiContext xcontext = this.xcontextProvider.get();
XWikiDocument editorDocument = xcontext.getWiki().getDocument(this.getDocumentReference(), xcontext);
XWikiDocument translatedEditorDocument = editorDocument.getTranslatedDocument(xcontext);
this.descriptorBuilder.setName(translatedEditorDocument.getRenderedTitle(Syntax.PLAIN_1_0, xcontext));
this.descriptorBuilder.setDescription(translatedEditorDocument.getRenderedContent(Syntax.PLAIN_1_0, xcontext));
} catch (XWikiException e) {
this.logger.warn("Failed to read the editor name and description. Root cause: " + ExceptionUtils.getRootCauseMessage(e));
}
return this.descriptorBuilder.build();
}
use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class EditorWikiComponent method render.
@Override
protected String render() throws EditException {
try {
XWikiContext xcontext = this.xcontextProvider.get();
XWikiDocument editorDocument = xcontext.getWiki().getDocument(this.getDocumentReference(), xcontext);
BaseObject editorObject = editorDocument.getXObject(EDITOR_CLASS_REFERENCE);
String editorCode = editorObject.getStringValue("code");
// Make sure the editor code is executed with the rights of the editor document author.
XWikiDocument sdoc = editorDocument;
// the data that has been put on the script context).
return xcontext.getDoc().getRenderedContent(editorCode, editorDocument.getSyntax().toIdString(), false, sdoc, xcontext);
} catch (Exception e) {
throw new EditException("Failed to render the editor code.", e);
}
}
use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class DocumentTreeNode method getParent.
@Override
protected EntityReference getParent(DocumentReference documentReference) throws Exception {
XWikiContext xcontext = this.xcontextProvider.get();
XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext);
DocumentReference parentReference = document.getParentReference();
// The parent document must be on the same space.
if (parentReference != null && parentReference.getParent().equals(documentReference.getParent())) {
return parentReference;
}
return documentReference.getParent();
}
use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class ObjectTreeNode method getChildCount.
private int getChildCount(ObjectReference objectReference) throws Exception {
XWikiContext xcontext = this.xcontextProvider.get();
XWikiDocument document = xcontext.getWiki().getDocument(objectReference.getParent(), xcontext);
BaseObject object = document.getXObject(objectReference);
return object == null ? 0 : object.getPropertyList().size();
}
Aggregations