Search in sources :

Example 16 with XWikiDocument

use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.

the class ObjectsOfTypeTreeNode method getXObjectReferences.

private List<ObjectReference> getXObjectReferences(DocumentReference documentReference, DocumentReference classReference) throws Exception {
    XWikiContext xcontext = this.xcontextProvider.get();
    XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext);
    List<ObjectReference> objectReferences = new ArrayList<ObjectReference>();
    List<BaseObject> objects = document.getXObjects(classReference);
    if (objects != null) {
        for (BaseObject object : objects) {
            // Yes, the list of objects can contain null values..
            if (object != null) {
                objectReferences.add(object.getReference());
            }
        }
    }
    return objectReferences;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ObjectReference(org.xwiki.model.reference.ObjectReference) ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 17 with XWikiDocument

use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.

the class TranslationsTreeNode method getChildCount.

@Override
protected int getChildCount(DocumentReference documentReference) throws Exception {
    XWikiContext xcontext = this.xcontextProvider.get();
    XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext);
    return document.getTranslationLocales(xcontext).size();
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext)

Example 18 with XWikiDocument

use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.

the class AttachmentsTreeNode method getChildCount.

@Override
protected int getChildCount(DocumentReference documentReference) throws Exception {
    int count = 0;
    if (showAddAttachment(documentReference)) {
        count++;
    }
    XWikiContext xcontext = this.xcontextProvider.get();
    XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext);
    count += document.getAttachmentList().size();
    return count;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext)

Example 19 with XWikiDocument

use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.

the class AttachmentsTreeNode method getChildren.

@Override
protected List<String> getChildren(DocumentReference documentReference, int offset, int limit) throws Exception {
    List<String> children = new ArrayList<String>();
    if (offset == 0 && showAddAttachment(documentReference)) {
        children.add("addAttachment:" + this.defaultEntityReferenceSerializer.serialize(documentReference));
    }
    XWikiContext xcontext = this.xcontextProvider.get();
    XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext);
    List<XWikiAttachment> attachments = document.getAttachmentList();
    for (XWikiAttachment attachment : subList(attachments, offset, limit)) {
        children.add(serialize(attachment.getReference()));
    }
    return children;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment)

Example 20 with XWikiDocument

use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.

the class SendMailConfigClassDocumentConfigurationSourceTest method getPropertyWhenNoSendMailConfigClassXObject.

@Test
public void getPropertyWhenNoSendMailConfigClassXObject() throws Exception {
    Cache<Object> cache = mock(Cache.class);
    CacheManager cacheManager = this.mocker.getInstance(CacheManager.class);
    when(cacheManager.createNewCache(any(CacheConfiguration.class))).thenReturn(cache);
    WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wiki");
    LocalDocumentReference classReference = new LocalDocumentReference("Mail", "SendMailConfigClass");
    XWikiDocument document = mock(XWikiDocument.class);
    when(document.getXObject(classReference)).thenReturn(null);
    DocumentReference documentReference = new DocumentReference("wiki", "Mail", "MailConfig");
    XWiki xwiki = mock(XWiki.class);
    when(xwiki.getDocument(eq(documentReference), any(XWikiContext.class))).thenReturn(document);
    XWikiContext xcontext = mock(XWikiContext.class);
    when(xcontext.getWiki()).thenReturn(xwiki);
    Provider<XWikiContext> xcontextProvider = this.mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    when(xcontextProvider.get()).thenReturn(xcontext);
    assertEquals("defaultValue", this.mocker.getComponentUnderTest().getProperty("key", "defaultValue"));
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) CacheManager(org.xwiki.cache.CacheManager) XWiki(com.xpn.xwiki.XWiki) XWikiContext(com.xpn.xwiki.XWikiContext) BaseObject(com.xpn.xwiki.objects.BaseObject) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) Test(org.junit.Test)

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