Search in sources :

Example 26 with XWikiDocument

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);
            }
        }
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) QueryException(org.xwiki.query.QueryException) XClassPropertyUpdatedEvent(com.xpn.xwiki.internal.event.XClassPropertyUpdatedEvent) BaseProperty(com.xpn.xwiki.objects.BaseProperty) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass)

Example 27 with XWikiDocument

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;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) AbstractActionExecutionEvent(org.xwiki.bridge.event.AbstractActionExecutionEvent) ActionExecutedEvent(org.xwiki.bridge.event.ActionExecutedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) ActionExecutingEvent(org.xwiki.bridge.event.ActionExecutingEvent)

Example 28 with XWikiDocument

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;
}
Also used : Serializable(java.io.Serializable) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiRecycleBinStoreInterface(com.xpn.xwiki.store.XWikiRecycleBinStoreInterface) XWiki(com.xpn.xwiki.XWiki) XWikiDeletedDocument(com.xpn.xwiki.doc.XWikiDeletedDocument) Map(java.util.Map) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 29 with XWikiDocument

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;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ExecutionContext(org.xwiki.context.ExecutionContext) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 30 with XWikiDocument

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;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) EntityReference(org.xwiki.model.reference.EntityReference) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)869 DocumentReference (org.xwiki.model.reference.DocumentReference)469 BaseObject (com.xpn.xwiki.objects.BaseObject)318 Test (org.junit.Test)284 XWikiContext (com.xpn.xwiki.XWikiContext)232 XWikiException (com.xpn.xwiki.XWikiException)178 ArrayList (java.util.ArrayList)99 XWiki (com.xpn.xwiki.XWiki)97 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)86 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)71 Document (com.xpn.xwiki.api.Document)48 EntityReference (org.xwiki.model.reference.EntityReference)48 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)41 Date (java.util.Date)41 IOException (java.io.IOException)40 HashMap (java.util.HashMap)33 QueryException (org.xwiki.query.QueryException)27 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)25 ParseGroovyFromString (com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString)23 IncludeServletAsString (com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString)23