use of com.xpn.xwiki.XWiki in project xwiki-platform by xwiki.
the class AbstractAnnotationRESTResource method setUpDocuments.
/**
* Helper function to prepare the XWiki documents and translations on the context and velocity context. <br>
* TODO: check how this code could be written only once (not duplicate the prepareDocuments function in XWiki)
*
* @param docName the full name of the document to prepare context for
* @param language the language of the document
* @throws XWikiException if anything goes wrong accessing documents
*/
private void setUpDocuments(String docName, String language) throws XWikiException {
XWikiContext context = xcontextProvider.get();
XWiki xwiki = context.getWiki();
// prepare the messaging tools and set them on context
xwiki.prepareResources(context);
XWikiDocument doc = xwiki.getDocument(docName, context);
// setup the xwiki context
context.put("doc", doc);
context.put("cdoc", doc);
XWikiDocument tdoc = doc.getTranslatedDocument(language, context);
context.put("tdoc", tdoc);
// and render the xwikivars to have all the variables set ($has*, $blacklistedSpaces, etc)
context.getWiki().renderTemplate("xwikivars.vm", context);
}
use of com.xpn.xwiki.XWiki in project xwiki-platform by xwiki.
the class AbstractAnnotationRESTResource method updateContext.
/**
* Helper method to make sure that the context is set to the right document and database name.
*
* @param wiki the REST wikiName path parameter
* @param space the REST spaceName path parameter
* @param page the REST pageName path parameter
*/
protected void updateContext(DocumentReference documentReference) {
try {
// Set the database to the current wiki.
XWikiContext deprecatedContext = (XWikiContext) execution.getContext().getProperty("xwikicontext");
deprecatedContext.setWikiId(documentReference.getWikiReference().getName());
// Set the document to the current document.
XWiki xwiki = deprecatedContext.getWiki();
XWikiDocument currentDocument = xwiki.getDocument(documentReference, deprecatedContext);
deprecatedContext.setDoc(currentDocument);
} catch (Exception e) {
// Just log it.
getLogger().error("Failed to update the context for page [{}].", documentReference, e);
}
}
use of com.xpn.xwiki.XWiki in project xwiki-platform by xwiki.
the class DefaultModelBridge method findDocument.
private XWikiDocument findDocument(EntityReference entityReference) throws EventStreamException {
XWikiContext context = contextProvider.get();
XWiki xwiki = context.getWiki();
try {
return xwiki.getDocument(entityReference, context);
} catch (XWikiException e) {
throw new EventStreamException(String.format("Unable to retrieve the given document [%s] in the current context.", entityReference), e);
}
}
use of com.xpn.xwiki.XWiki in project xwiki-platform by xwiki.
the class DefaultModelBridgeTest method testAuthorReference.
@Test
public void testAuthorReference() throws Exception {
XWikiContext context = mock(XWikiContext.class);
XWiki xwiki = mock(XWiki.class);
XWikiDocument document = mock(XWikiDocument.class);
DocumentReference authorReference = mock(DocumentReference.class);
EntityReference entityReference = mock(EntityReference.class);
when(this.contextProvider.get()).thenReturn(context);
when(context.getWiki()).thenReturn(xwiki);
when(xwiki.getDocument(entityReference, context)).thenReturn(document);
when(document.getAuthorReference()).thenReturn(authorReference);
DocumentReference result = this.mocker.getComponentUnderTest().getAuthorReference(entityReference);
assertEquals(authorReference, result);
}
use of com.xpn.xwiki.XWiki 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