Search in sources :

Example 11 with XWikiDocument

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());
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiComponent(org.xwiki.component.wiki.WikiComponent) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 12 with XWikiDocument

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();
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException)

Example 13 with XWikiDocument

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);
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException) EditException(org.xwiki.edit.EditException) WikiComponentException(org.xwiki.component.wiki.WikiComponentException) EditException(org.xwiki.edit.EditException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 14 with XWikiDocument

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();
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 15 with XWikiDocument

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();
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)869 DocumentReference (org.xwiki.model.reference.DocumentReference)469 BaseObject (com.xpn.xwiki.objects.BaseObject)318 Test (org.junit.Test)284 XWikiContext (com.xpn.xwiki.XWikiContext)232 XWikiException (com.xpn.xwiki.XWikiException)178 ArrayList (java.util.ArrayList)99 XWiki (com.xpn.xwiki.XWiki)97 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)86 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)71 Document (com.xpn.xwiki.api.Document)48 EntityReference (org.xwiki.model.reference.EntityReference)48 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)41 Date (java.util.Date)41 IOException (java.io.IOException)40 HashMap (java.util.HashMap)33 QueryException (org.xwiki.query.QueryException)27 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)25 ParseGroovyFromString (com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString)23 IncludeServletAsString (com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString)23