use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class XClassMigratorListener method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
XClassPropertyUpdatedEvent propertyEvent = (XClassPropertyUpdatedEvent) event;
XWikiDocument newDocument = (XWikiDocument) source;
XWikiDocument previousDocument = newDocument.getOriginalDocument();
PropertyClass newPropertyClass = (PropertyClass) newDocument.getXClass().getField(propertyEvent.getReference().getName());
PropertyClass previousPropertyClass = (PropertyClass) previousDocument.getXClass().getField(propertyEvent.getReference().getName());
if (newPropertyClass != null && previousPropertyClass != null) {
BaseProperty newProperty = newPropertyClass.newProperty();
BaseProperty previousProperty = previousPropertyClass.newProperty();
// New and previous class property generate different kind of properties
if (newProperty.getClass() != previousProperty.getClass()) {
try {
migrate(newPropertyClass);
} catch (QueryException e) {
this.logger.error("Failed to migrate XClass property [{}]", newPropertyClass.getReference(), e);
}
}
}
}
use of com.xpn.xwiki.doc.XWikiDocument 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;
}
use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class DocumentEventConverter method unserializeDeletdDocument.
private XWikiDocument unserializeDeletdDocument(Serializable remoteData, XWikiContext xcontext) throws XWikiException {
Map<String, Serializable> remoteDataMap = (Map<String, Serializable>) remoteData;
DocumentReference docReference = (DocumentReference) remoteDataMap.get(DOC_NAME);
XWikiDocument doc = new XWikiDocument(docReference);
XWikiDocument origDoc = new XWikiDocument(docReference);
// We have to get deleted document from the trash (hoping it is in the trash...)
XWiki xwiki = xcontext.getWiki();
XWikiRecycleBinStoreInterface store = xwiki.getRecycleBinStore();
XWikiDeletedDocument[] deletedDocuments = store.getAllDeletedDocuments(origDoc, xcontext, true);
if (deletedDocuments != null && deletedDocuments.length > 0) {
long index = deletedDocuments[0].getId();
origDoc = store.restoreFromRecycleBin(index, xcontext, true);
}
doc.setOriginalDocument(origDoc);
return doc;
}
use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class DefaultAuthorExecutor method before.
@Override
public AutoCloseable before(DocumentReference authorReference) {
DefaultAuthorExecutorContext suContext;
XWikiContext xwikiContext = this.xcontextProvider.get();
if (xwikiContext != null) {
suContext = new DefaultAuthorExecutorContext();
// Make sure to have the right secure document
suContext.currentSecureDocument = (XWikiDocument) xwikiContext.get(XWikiDocument.CKEY_SDOC);
XWikiDocument secureDocument = new XWikiDocument(new DocumentReference(authorReference != null ? authorReference.getWikiReference().getName() : "xwiki", "SUSpace", "SUPage"));
secureDocument.setContentAuthorReference(authorReference);
secureDocument.setAuthorReference(authorReference);
secureDocument.setCreatorReference(authorReference);
xwikiContext.put(XWikiDocument.CKEY_SDOC, secureDocument);
// Make sure to disable XWikiContext#dropPermission hack
suContext.xwikiContextDropPermissionHack = xwikiContext.remove(XWikiConstant.DROPPED_PERMISSIONS);
// Make sure to disable Document#dropPermission hack
ExecutionContext econtext = this.execution.getContext();
if (econtext != null) {
suContext.documentDropPermissionHack = econtext.getProperty(XWikiConstant.DROPPED_PERMISSIONS);
econtext.removeProperty(XWikiConstant.DROPPED_PERMISSIONS);
}
} else {
suContext = null;
}
return suContext;
}
use of com.xpn.xwiki.doc.XWikiDocument 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