Hi Tharindu,
On Fri, May 1, 2009 at 8:05 AM, Tharindu Madushanka
<tharindufit(a)gmail.com>wrote;wrote:
Hi,
I have defined the class UserLoginEvent in package
org.xwiki.observation.event
Then in order to be notified I think we could change the LoginSubmitAction
class render() it the message is null we could notify the listener of a
successful login.
Index: xwiki-core/src/main/java/com/xpn/xwiki/web/LoginSubmitAction.java
===================================================================
--- xwiki-core/src/main/java/com/xpn/xwiki/web/LoginSubmitAction.java
(revision 19222)
+++ xwiki-core/src/main/java/com/xpn/xwiki/web/LoginSubmitAction.java
(working copy)
@@ -22,14 +22,25 @@
import javax.servlet.http.HttpServletResponse;
+import org.xwiki.observation.ObservationManager;
+import org.xwiki.observation.event.UserLoginEvent;
+
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
-public class LoginSubmitAction extends XWikiAction {
- public String render(XWikiContext context) throws XWikiException {
- String msg = (String)context.get("message");
- if(msg != null && !msg.trim().equals("")) {
+public class LoginSubmitAction extends XWikiAction
+{
+ public String render(XWikiContext context) throws XWikiException
+ {
+ String msg = (String) context.get("message");
+ if (msg != null && !msg.trim().equals("")) {
context.getResponse().setStatus(HttpServletResponse.SC_FORBIDDEN);
+ } else {
+ ObservationManager om = (ObservationManager)
Utils.getComponent(ObservationManager.class);
+ if (om != null) {
I don't think you need this check, if the component lookup fails, it will
throw an exception.
+ om.notify(new
UserLoginEvent(context.getDoc().getWikiName()
+ ":" + context.getDoc().getFullName()),
+ context.getDoc(), context);
UserLoginEvent, why does it require a document name in the constructor? And
even if you need it, I think context.getDoc().getFullName() already prepends
the wiki name (not sure).
And why do you need other parameters in the notify() method? can't you
simply use notify(Event event, Object source) ?
+ }
}
return "login";
}
Next thing is I am still not sure is how the listener are added. In
existing
save and delete I could not find how it has added listeners. to OM.
According to your JIRA issue:
http://jira.xwiki.org/jira/browse/XWIKI-3697you don't need to worry
about adding listeners. For an example, if I want to
be notified when a user logs into the system, I will have to implement the
EventListner inside my module and register it against OM, it's not upto you.
But when you do implement the XMPP integration, you will have to register
for this event :)
I think all you need now is UserLogoutEvent, SessionCreatedEvent event and
fire them at appropriate locations :)
Thanks.
- Asiri
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs