Thank you very much, Matthias - but I cannot figure out how to use it.
I have added the following code to my Class Sheet of the project class to
examine the functionality.
What I try is to print the variable content on save and update of a project
document, but there is no output visible.
Could you please give me a hint? Thanks in advance!
{{groovy}}
import org.xwiki.observation.*
import org.xwiki.observation.event.*
import com.xpn.xwiki.web.*
import com.xpn.xwiki.*
import com.xpn.xwiki.doc.XWikiDocument;
import org.xwiki.component.annotation.Component;
import org.xwiki.component.annotation.Requirement;
import org.xwiki.component.manager.ComponentLookupException;
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.observation.EventListener;
import org.xwiki.observation.ObservationManager;
import org.xwiki.observation.event.DocumentSaveEvent;
import org.xwiki.observation.event.Event;
class ProjectCreatedEventListener implements EventListener
{
def xwiki
def context
ProjectCreatedEventListener(xwiki, context)
{
this.xwiki = xwiki
this.context = context
}
String getName()
{
// The unique name of this event listener
return "projectcreated"
}
List<Event> getEvents()
{
// The list of events this listener listens to
return Arrays.asList(new DocumentSaveEvent())
}
// Called by the Observation Manager when an event matches the list of
events returned
// by getEvents()
void onEvent(Event event, Object source, Object data)
{
XWikiDocument document = (XWikiDocument) source;
String wikiName =
document.getDocumentReference().getWikiReference().getName();
println wikiName;
}
}
// Register against the Observation Manager
def observation = Utils.getComponent(ObservationManager.class)
observation.removeListener("projectcreated")
def listener = new ProjectCreatedEventListener(xwiki, xcontext)
observation.addListener(listener)
{{/groovy}}
--
View this message in context:
http://xwiki.475771.n2.nabble.com/How-to-set-a-properties-value-on-a-newly-…
Sent from the XWiki- Dev mailing list archive at
Nabble.com.