use of com.xpn.xwiki.XWikiException 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.XWikiException 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.XWikiException in project xwiki-platform by xwiki.
the class ActionExecutionEventConverter method fromRemote.
@Override
public boolean fromRemote(RemoteEventData remoteEvent, LocalEventData localEvent) {
if (remoteEvent.getEvent() instanceof ActionExecutedEvent || remoteEvent.getEvent() instanceof ActionExecutingEvent) {
// fill the local event
XWikiContext xcontext = unserializeXWikiContext(remoteEvent.getData());
try {
if (xcontext != null) {
localEvent.setSource(unserializeDocument(remoteEvent.getSource()));
localEvent.setData(xcontext);
localEvent.setEvent((Event) remoteEvent.getEvent());
}
} catch (XWikiException e) {
this.logger.error("Failed to convert remote event [{}]", remoteEvent, e);
}
return true;
}
return false;
}
use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.
the class DocumentEventConverter method fromRemote.
@Override
public boolean fromRemote(RemoteEventData remoteEvent, LocalEventData localEvent) {
if (EVENTS.contains(remoteEvent.getEvent().getClass())) {
// fill the local event
XWikiContext xcontext = unserializeXWikiContext(remoteEvent.getData());
try {
if (xcontext != null) {
localEvent.setData(xcontext);
localEvent.setEvent((Event) remoteEvent.getEvent());
if (remoteEvent.getEvent() instanceof DocumentDeletedEvent) {
localEvent.setSource(unserializeDeletdDocument(remoteEvent.getSource(), xcontext));
} else {
localEvent.setSource(unserializeDocument(remoteEvent.getSource()));
}
}
} catch (XWikiException e) {
this.logger.error("Failed to convert remote event [{}]", remoteEvent, e);
}
return true;
}
return false;
}
use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.
the class AbstractSheetBinder method bind.
private boolean bind(DocumentModelBridge document, String sheetReferenceString) {
EntityReference sheetBindingClassReference = this.relativeReferenceResolver.resolve(getSheetBindingClass(), EntityType.DOCUMENT);
List<BaseObject> sheetBindingObjects = ((XWikiDocument) document).getXObjects(sheetBindingClassReference);
if (sheetBindingObjects != null) {
for (BaseObject sheetBindingObject : sheetBindingObjects) {
// The list of XWiki objects can contain null values due to a design flaw in the old XWiki core.
if (sheetBindingObject != null) {
String boundSheetStringRef = sheetBindingObject.getStringValue(SHEET_PROPERTY);
if (StringUtils.equals(boundSheetStringRef, sheetReferenceString)) {
return false;
}
}
}
}
try {
BaseObject sheetBindingObject = ((XWikiDocument) document).newXObject(sheetBindingClassReference, getXWikiContext());
sheetBindingObject.setStringValue(SHEET_PROPERTY, sheetReferenceString);
} catch (XWikiException e) {
String docStringReference = this.defaultEntityReferenceSerializer.serialize(document.getDocumentReference());
this.logger.warn("Failed to bind sheet [{}] to document [{}].", sheetReferenceString, docStringReference);
return false;
}
return true;
}
Aggregations