use of com.xpn.xwiki.objects.BaseObject 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.objects.BaseObject in project xwiki-platform by xwiki.
the class EditorWikiComponent method initialize.
private void initialize(XWikiDocument editorDocument) throws WikiComponentException {
this.authorReference = editorDocument.getAuthorReference();
BaseObject editorObject = editorDocument.getXObject(EDITOR_CLASS_REFERENCE);
if (editorObject != null) {
initialize(editorObject);
} else {
throw new WikiComponentException(String.format("The document [%s] is missing the XWiki.EditorClass object.", editorDocument.getDocumentReference()));
}
}
use of com.xpn.xwiki.objects.BaseObject 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();
}
use of com.xpn.xwiki.objects.BaseObject 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.objects.BaseObject in project xwiki-platform by xwiki.
the class SendMailConfigClassDocumentConfigurationSourceTest method getPropertyWhenSendMailConfigClassXObjectExists.
@Test
public void getPropertyWhenSendMailConfigClassXObjectExists() throws Exception {
ConverterManager converterManager = this.mocker.getInstance(ConverterManager.class);
when(converterManager.convert(String.class, "value")).thenReturn("value");
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");
BaseProperty property = mock(BaseProperty.class);
when(property.toText()).thenReturn("value");
BaseObject object = mock(BaseObject.class);
when(object.getField("key")).thenReturn(property);
XWikiDocument document = mock(XWikiDocument.class);
when(document.getXObject(classReference)).thenReturn(object);
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("value", this.mocker.getComponentUnderTest().getProperty("key", "defaultValue"));
}
Aggregations