use of org.xwiki.bridge.DocumentModelBridge in project xwiki-platform by xwiki.
the class DefaultWikiComponentManagerEventListener method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
if (source instanceof DocumentModelBridge) {
// Get the document reference
DocumentModelBridge document = (DocumentModelBridge) source;
DocumentReference documentReference = document.getDocumentReference();
if (event instanceof DocumentCreatedEvent || event instanceof DocumentUpdatedEvent) {
registerDocumentComponents(document.getDocumentReference());
} else if (event instanceof DocumentDeletedEvent) {
// Unregister components from the deleted document, if any
this.wikiComponentManagerEventListenerHelper.unregisterComponents(documentReference);
}
/* If we are at application startup time, we have to instanciate every document or object that we can find
* in the wiki */
} else if (event instanceof ApplicationReadyEvent || event instanceof WikiReadyEvent) {
// These 2 events are created when the database is ready. We register all wiki components.
registerAllDocumentComponents();
}
}
use of org.xwiki.bridge.DocumentModelBridge in project xwiki-platform by xwiki.
the class LinkCheckerEventListener method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
DocumentModelBridge doc = (DocumentModelBridge) source;
final String reference = this.serializer.serialize(doc.getDocumentReference());
Map<String, Map<String, LinkState>> states = this.linkStateManager.getLinkStates();
for (Map.Entry<String, Map<String, LinkState>> entry : states.entrySet()) {
Map<String, LinkState> state = entry.getValue();
state.remove(reference);
if (state.size() == 0) {
states.remove(entry.getKey());
}
}
}
use of org.xwiki.bridge.DocumentModelBridge in project xwiki-platform by xwiki.
the class LinkCheckerEventListenerTest method testOnEvent.
@Test
public void testOnEvent() throws Exception {
final DocumentModelBridge documentModelBridge = getMockery().mock(DocumentModelBridge.class);
final EntityReferenceSerializer serializer = getComponentManager().getInstance(EntityReferenceSerializer.TYPE_STRING);
final DocumentReference reference = new DocumentReference("wiki", "space", "page");
final LinkStateManager linkStateManager = getComponentManager().getInstance(LinkStateManager.class);
final Map<String, Map<String, LinkState>> states = new HashMap<String, Map<String, LinkState>>();
Map<String, LinkState> referenceStates1 = new HashMap<String, LinkState>();
referenceStates1.put("wiki1:space1.page1", new LinkState(200, System.currentTimeMillis()));
referenceStates1.put("wiki2:space2.page2", new LinkState(200, System.currentTimeMillis()));
states.put("url1", referenceStates1);
Map<String, LinkState> referenceStates2 = new HashMap<String, LinkState>();
referenceStates2.put("wiki1:space1.page1", new LinkState(200, System.currentTimeMillis()));
states.put("url2", referenceStates2);
getMockery().checking(new Expectations() {
{
oneOf(documentModelBridge).getDocumentReference();
will(returnValue(reference));
oneOf(serializer).serialize(reference);
will(returnValue("wiki1:space1.page1"));
oneOf(linkStateManager).getLinkStates();
will(returnValue(states));
}
});
this.listener.onEvent(new DocumentUpdatingEvent(), documentModelBridge, null);
Assert.assertEquals(1, states.size());
Assert.assertEquals(1, states.get("url1").size());
Assert.assertNull(states.get("url2"));
}
Aggregations