use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class WikiSkinUtils method getSkinDocument.
public XWikiDocument getSkinDocument(String skin) {
XWikiContext xcontext = this.xcontextProvider.get();
if (xcontext != null) {
DocumentReference skinReference = this.currentMixedDocumentReferenceResolver.resolve(skin);
XWiki xwiki = xcontext.getWiki();
if (xwiki != null && xwiki.getStore() != null) {
XWikiDocument doc;
try {
doc = xwiki.getDocument(skinReference, xcontext);
} catch (XWikiException e) {
this.logger.error("Faied to get document [{}]", skinReference, e);
return null;
}
if (!doc.isNew()) {
return doc;
}
}
}
return null;
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class AbstractXWikiStore method getExecutionXContext.
/**
* @param inputxcontext the XWikiContext given as input to the API
* @return the {@link XWikiContext} located in the {@link ExecutionContext} if any
*/
protected XWikiContext getExecutionXContext(XWikiContext inputxcontext, boolean savewiki) {
// If not a component return input context
if (this.readonlyxcontextProvider == null) {
return inputxcontext;
}
XWikiContext xcontext = this.readonlyxcontextProvider.get();
// If no context can be found return input context
if (xcontext == null) {
return inputxcontext;
}
if (inputxcontext != null && xcontext != inputxcontext) {
LOGGER.warn("ExecutionContext and passed XWikiContext argument mismatched, for data safety," + " the XWikiContext from the ExecutionContext has been used.", new Exception("Stack trace"));
// Make sure to use the wiki expected by the called for the API
if (savewiki && !Objects.equals(inputxcontext.getWikiReference(), xcontext.getWikiReference())) {
xcontext.put(PREVIOUS_WIKI, xcontext.getWikiReference());
xcontext.setWikiReference(inputxcontext.getWikiReference());
}
}
return xcontext;
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class XClassMigratorListener method migrate.
private void migrate(PropertyClass newPropertyClass) throws QueryException {
ClassPropertyReference propertyReference = newPropertyClass.getReference();
EntityReference classReference = propertyReference.extractReference(EntityType.DOCUMENT);
EntityReference wikiReference = propertyReference.extractReference(EntityType.WIKI);
// Get all document containing object of modified class
Query query = this.queryManager.createQuery("from doc.object(" + this.localSerializer.serialize(classReference) + ") as obj", Query.XWQL);
query.setWiki(wikiReference.getName());
List<String> documents = query.execute();
if (!documents.isEmpty()) {
XWikiContext xcontext = this.xcontextProvider.get();
String currentWikiId = xcontext.getWikiId();
try {
// Switch to class wiki to be safer
xcontext.setWikiId(wikiReference.getName());
for (String documentName : documents) {
try {
migrate(newPropertyClass, documentName, xcontext);
} catch (XWikiException e) {
this.logger.error("Failed to migrate property [{}] in document [{}]", propertyReference, documentName, xcontext);
}
}
} finally {
// Restore context wiki
xcontext.setWikiId(currentWikiId);
}
}
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class AbstractXWikiEventConverter method getXWikiStubContext.
/**
* @return a stub XWikiContext, null if none can be generated (XWiki has never been accessed yet)
*/
private XWikiContext getXWikiStubContext() {
ExecutionContext context = this.execution.getContext();
XWikiContext xcontext = (XWikiContext) context.getProperty(XWikiContext.EXECUTIONCONTEXT_KEY);
if (xcontext == null) {
xcontext = this.stubContextProvider.createStubContext();
if (xcontext != null) {
xcontext.declareInExecutionContext(context);
}
}
return xcontext;
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class ActionExecutionEventConverter method toRemote.
@Override
public boolean toRemote(LocalEventData localEvent, RemoteEventData remoteEvent) {
if (localEvent.getEvent() instanceof ActionExecutedEvent || localEvent.getEvent() instanceof ActionExecutingEvent) {
AbstractActionExecutionEvent event = (AbstractActionExecutionEvent) localEvent.getEvent();
if (this.actions.contains(event.getActionName())) {
// fill the remote event
remoteEvent.setEvent(event);
remoteEvent.setSource(serializeXWikiDocument((XWikiDocument) localEvent.getSource()));
remoteEvent.setData(serializeXWikiContext((XWikiContext) localEvent.getData()));
}
return true;
}
return false;
}
Aggregations