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();
}
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);
}
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;
}
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());
}
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());
}
Aggregations