Hi All,
-I’m writing a plugin for page events listener module that sync with custom system.
In other words, Whenever page copy events happened, I needed info about that copied page
(for example, page property that I created before copied. Once page is copied, it didn’t carry along add-ons page property that you created).
-EventListener triggers when copying page with children or hierarchy.
-However, when copying page without children or hierarchy, it falls into the category of page creation events. I needed to differentiate between create and copy though technically, they are the same.
Code Sample below:
package com.linn.aung;
import com.atlassian.confluence.event.events.content.ContentEvent;
import com.atlassian.confluence.event.events.content.page.PageCopyEvent;
import com.atlassian.confluence.event.events.content.page.PageCreateEvent;
import com.atlassian.confluence.event.events.content.page.PageViewEvent;
import com.atlassian.confluence.event.events.content.pagehierarchy.CopyPageHierarchyFinishEvent;
import com.atlassian.confluence.event.events.content.pagehierarchy.CopyPageHierarchyStartEvent;
import com.atlassian.confluence.pages.Page;
import com.atlassian.event.Event;
import com.atlassian.event.EventListener;
import org.apache.log4j.Logger;
public class PageListener implements EventListener{
private static final Logger log = Logger.getLogger(PageListener.class);
private Class[] handledClasses = new Class[]{
ContentEvent.class,
PageViewEvent.class,
PageCreateEvent.class,
PageCopyEvent.class,
CopyPageHierarchyStartEvent.class,
CopyPageHierarchyFinishEvent.class
};
public void handleEvent(Event event) {
if (event instanceof PageCreateEvent) {
PageCreateEvent pageCreateEvent = (PageCreateEvent) event;
Page currentPage = pageCreateEvent.getPage();
String pageTitle = currentPage.getTitle();
log.warn("-----here page created-----");
log.warn(pageTitle);
}
else if(event instanceof CopyPageHierarchyStartEvent) {
CopyPageHierarchyStartEvent copyStart = (CopyPageHierarchyStartEvent) event;
Page destinationPage = copyStart.getDestination();
String pageTitle = destinationPage.getTitle();
log.warn("-----here page copy start-----");
log.warn(pageTitle);
}
else if(event instanceof PageCopyEvent) {
PageCopyEvent pageCopyEvent = (PageCopyEvent) event;
Page currentPage = pageCopyEvent.getPage();
String pageTitle = currentPage.getTitle();
log.warn("-----here page copied----");
log.warn(pageTitle);
}
else if(event instanceof CopyPageHierarchyFinishEvent) {
CopyPageHierarchyFinishEvent copyFinish = (CopyPageHierarchyFinishEvent) event;
Page destinationPage = copyFinish.getDestination();
String pageTitle = destinationPage.getTitle();
log.warn("-----here page copy finish-----");
log.warn(pageTitle);
}
}
public Class[] getHandledEventClasses() {
return handledClasses;
}
}
