Search in sources :

Example 31 with DocumentReference

use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.

the class DocumentTreeNode method getParent.

@Override
protected EntityReference getParent(DocumentReference documentReference) throws Exception {
    XWikiContext xcontext = this.xcontextProvider.get();
    XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext);
    DocumentReference parentReference = document.getParentReference();
    // The parent document must be on the same space.
    if (parentReference != null && parentReference.getParent().equals(documentReference.getParent())) {
        return parentReference;
    }
    return documentReference.getParent();
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 32 with DocumentReference

use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.

the class SpaceTreeNode method getChildDocumentsCount.

@Override
protected int getChildDocumentsCount(SpaceReference spaceReference) throws QueryException {
    List<String> constraints = new ArrayList<String>();
    Map<String, Object> parameters = new HashMap<String, Object>();
    // Include only the documents that either don't have a parent document or that have a parent document in a
    // different space. Note that in Oracle the empty string is stored as null.
    String hasNoParent = "doc.parent = '' or doc.parent is null";
    String hasParentOutsideSpace = "doc.parent like '%.%' and doc.parent not like :absoluteRef and doc.parent not like :localRef";
    constraints.add(String.format("((%s) or (%s))", hasNoParent, hasParentOutsideSpace));
    DocumentReference absoluteReference = this.explicitDocumentReferenceResolver.resolve(String.valueOf('%'), spaceReference);
    parameters.put(PARAMETER_ABSOLUTE_REFERENCE, this.defaultEntityReferenceSerializer.serialize(absoluteReference));
    parameters.put(PARAMETER_LOCAL_REFERENCE, this.localEntityReferenceSerializer.serialize(absoluteReference));
    return getChildDocumentsCount(spaceReference, constraints, parameters);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 33 with DocumentReference

use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.

the class DocumentReferenceResolverFilter method filterResults.

@Override
public List<?> filterResults(@SuppressWarnings("rawtypes") List results) {
    String defaultDocumentName = this.defaultEntityReferenceProvider.getDefaultReference(EntityType.DOCUMENT).getName();
    List<DocumentReference> documentReferences = new ArrayList<DocumentReference>();
    for (Object result : results) {
        String reference = (String) ((Object[]) result)[0];
        boolean terminal = toBoolean(((Object[]) result)[1]);
        if (terminal) {
            documentReferences.add(this.currentDocumentReferenceResolver.resolve(reference));
        } else {
            SpaceReference spaceReference = this.currentSpaceReferenceResolver.resolve(reference);
            documentReferences.add(new DocumentReference(defaultDocumentName, spaceReference));
        }
    }
    return documentReferences;
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) ArrayList(java.util.ArrayList) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 34 with DocumentReference

use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.

the class LegacyEventDispatcherTest method testLegacyDocumentUpdateEventGetsDispatched.

@Test
public void testLegacyDocumentUpdateEventGetsDispatched() throws Exception {
    this.registerListenerWithLegacyEvent(new DocumentUpdateEvent());
    this.om.notify(new DocumentUpdatedEvent(new DocumentReference("wiki", "space", "name")), null);
    // The notification is synchronous, so the following assertion will only be tested
    // once all matching event listeners have been notified.
    Assert.assertNotNull("Should have been notified by legacy event dispatcher", this.receivedEvent);
    Assert.assertEquals("Wrong event filter", "wiki:space.name", ((FilterableEvent) this.receivedEvent).getEventFilter().getFilter());
}
Also used : DocumentUpdateEvent(org.xwiki.observation.event.DocumentUpdateEvent) FilterableEvent(org.xwiki.observation.event.FilterableEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 35 with DocumentReference

use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.

the class LegacyEventDispatcherTest method testLegacyDocumentDeleteEventGetsDispatched.

@Test
public void testLegacyDocumentDeleteEventGetsDispatched() throws Exception {
    this.registerListenerWithLegacyEvent(new DocumentDeleteEvent());
    this.om.notify(new DocumentDeletedEvent(new DocumentReference("wiki", "space", "name")), null);
    // The notification is synchronous, so the following assertion will only be tested
    // once all matching event listeners have been notified.
    Assert.assertNotNull("Should have been notified by legacy event dispatcher", this.receivedEvent);
    Assert.assertEquals("Wrong event filter", "wiki:space.name", ((FilterableEvent) this.receivedEvent).getEventFilter().getFilter());
}
Also used : DocumentDeleteEvent(org.xwiki.observation.event.DocumentDeleteEvent) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) FilterableEvent(org.xwiki.observation.event.FilterableEvent) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

DocumentReference (org.xwiki.model.reference.DocumentReference)1324 Test (org.junit.Test)711 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)482 BaseObject (com.xpn.xwiki.objects.BaseObject)250 XWikiContext (com.xpn.xwiki.XWikiContext)186 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)157 ArrayList (java.util.ArrayList)128 WikiReference (org.xwiki.model.reference.WikiReference)127 XWikiException (com.xpn.xwiki.XWikiException)121 EntityReference (org.xwiki.model.reference.EntityReference)113 SpaceReference (org.xwiki.model.reference.SpaceReference)96 XWiki (com.xpn.xwiki.XWiki)82 HashMap (java.util.HashMap)54 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)52 Expectations (org.jmock.Expectations)50 Before (org.junit.Before)50 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)46 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)45 AttachmentReference (org.xwiki.model.reference.AttachmentReference)44 Date (java.util.Date)42