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;
}
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();
}
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;
}
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;
}
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"));
}
Aggregations