[xwiki-users] Groovy Notification Tutorial

2012-06-04 Thread Stéphanie
Hello everyone, 

In the Groovy Notification Tutorial
(http://platform.xwiki.org/xwiki/bin/view/DevGuide/GroovyNotificationTutorial),
there is a field source that is an Object. To have the full name of the
source, we have to write : source.fullName.

For what I'm doing, I just want to have the space of the source. I've tried
different things, but no one seems to work. Do you have an idea of how I can
have only the space of the source ?

Thanks,
Stéphanie

--
View this message in context: 
http://xwiki.475771.n2.nabble.com/Groovy-Notification-Tutorial-tp7579341.html
Sent from the XWiki- Users mailing list archive at Nabble.com.
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


Re: [xwiki-users] Groovy Notification Tutorial

2012-06-04 Thread Jeremie BOUSQUET
source is an XWikiDocument (inner document of a Document from XWiki
api) as can be seen here, in the sample :
http://extensions.xwiki.org/xwiki/bin/view/Extension/Observation+Module+Local

I think source.space might work (was deprecated, didn't check if it's
still there).
Or something like
source.getDocumentReference().getLastSpaceReference().getName()

Jerem

2012/6/4 Stéphanie stephanie.roull...@gmail.com:
 Hello everyone,

 In the Groovy Notification Tutorial
 (http://platform.xwiki.org/xwiki/bin/view/DevGuide/GroovyNotificationTutorial),
 there is a field source that is an Object. To have the full name of the
 source, we have to write : source.fullName.

 For what I'm doing, I just want to have the space of the source. I've tried
 different things, but no one seems to work. Do you have an idea of how I can
 have only the space of the source ?

 Thanks,
 Stéphanie

 --
 View this message in context: 
 http://xwiki.475771.n2.nabble.com/Groovy-Notification-Tutorial-tp7579341.html
 Sent from the XWiki- Users mailing list archive at Nabble.com.
 ___
 users mailing list
 users@xwiki.org
 http://lists.xwiki.org/mailman/listinfo/users
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


Re: [xwiki-users] groovy notification

2008-11-25 Thread Jerome Velociter
Dan Svoboda wrote:
 I tried changing newdoc.getAttachments() to  
 newdoc.newDocument(context).getAttachmentList().

 I've stripped down the class to remove dependance on getting values  
 out of the context; i.e I've provided string literals for sender, cc,  
 etc. I've also changed the rule to DocChangeRule(this), and removed  
 the test for the change coming from a space's Blog so that any  
 document save event would trigger email.

 Still no joy.

 The only clue in the log is when calling the notify method from a  
 velocity script:

 [WARNING] Cannot retrieve method notify from object of class  
 BlogMailNotificationGroovyClass due to security restrictions.

This looks to me very likely to be linked with the security 
configuration of the servlet container.
In which environment does your wiki run in ?

Jerome


 Dan

 Here's the revised class:

 /* Groovy Class #* */

 import com.xpn.xwiki.api.XWiki;
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.notify.XWikiDocChangeNotificationInterface;
 import com.xpn.xwiki.notify.DocObjectChangedRule;
 import com.xpn.xwiki.notify.XWikiNotificationRule;
 import com.xpn.xwiki.doc.XWikiDocument;

 public class BlogMailNotificationGroovyClass implements \

 XWikiDocChangeNotificationInterface

 {
  def xwiki;
  def rule;
  def name;

  public void initClasses(XWikiContext context)
  {
  this.xwiki = context.getWiki();
  // listen to notifications
  this.rule = DocChangeRule(this);
   
 context.getWiki().getNotificationManager().addGeneralRule(rule);
  }

  public void notify(XWikiNotificationRule rule, XWikiDocument  
 newdoc, \
 XWikiDocument olddoc, int event, XWikiContext  
 context)
  {

  def ms = xwiki.getPlugin(mailsender);
  def nb = ms.sendHtmlMessage(XWiki.Admin, \
 [EMAIL PROTECTED], \
 [EMAIL PROTECTED], \
 [EMAIL PROTECTED], \
 subject, \
 newdoc.getRenderedContent(), \
 newdoc.getContent(), \
  
 newdoc.newDocument(context).getAttachmentList());
  }
 }

 /* *# */



 Ok, I have another idea. Did you try sending the mail without  
 attachments ?

 This because what you pass the plugin API are XWikiAttachments
 (http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwiki/doc/XWikiAttachment.html
  
 ),
 while it expects com.xpn.xwiki.api.Attachment (see the plugin API  
 here
 http://code.xwiki.org/xwiki/bin/view/Plugins/MailSenderPlugin).
 If you want to have the proper wrapped attachments to pass the plugin,
 you should use newdoc.newDocument(context).getAttachmentList()

 Hope this helps,
 Jerome.

 Daniel Svoboda wrote:
 Thanks for the replies.

 I had already found that bug. If I take the conditional completely  
 out
 of the class, it still doesn't send an email.

 Dan

 It is probably due to the following :

 if(newdoc.getSpace().substring(lastFour) == Blog) {

 in Java, if you have the following :

 String st1 = Blog;
 String st2 = new String(Blog);

 then st1 == st2 will always return false, as the objects are not the
 same. What you want is to compare their values, using  
 st1.equals(st2),
 which will return true.
 You can read here to find out more
 http://www.unix.com.ua/orelly/java/langref/ch04_09.htm (especially
 this
 sentence : Because the == operator determines if two objects are  
 the
 same object, it is not appropriate for comparisons that need to
 determine if two objects have the same contents. For example, if you
 need to know whether two String objects contain the same sequences  
 of
 characters, the == operator is inappropriate. You should use the
 equals() method)

 Anyway, their is even simpler for you. What you want to do is  
 check if
 the space name finishes by Blog. For this the appropriate method  
 is
 String#endsWith
 (http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#endsWith(java.lang.String
  
 )
 )
 As in :

 if(newdoc.getSpace().endsWith(Blog)) {

 Hope this helps and fixes your issue,

 Regards,
 Jerome

 Daniel Svoboda wrote:
 Yes. The problem is that no mail gets sent, which is the purpose of
 the notification. I reread my initial post, and now I understand  
 your
 confusion. I didn't explicitly state that the class wasn't working.

 I'm using XWiki Enterprise manager 1.3 with platform version 1.5.2.

 Dan


 Do you actually encounter a problem, besides the error in the  
 logs ?
 I believe those logs are generated when you call
 getRenderedContent on
 your blog article, so I maintain they have nothing to do with your
 notification class.
 Which version of XWiki Enterprise are you using ?

 Jerome.

 Dan Svoboda wrote:
 Hi,

 See below

 Dan Svoboda wrote:
 Hi,

 I'm trying to use the notification system to trigger the
 

Re: [xwiki-users] groovy notification

2008-11-24 Thread Jerome Velociter
Ok, I have another idea. Did you try sending the mail without attachments ?

This because what you pass the plugin API are XWikiAttachments 
(http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwiki/doc/XWikiAttachment.html),
 
while it expects com.xpn.xwiki.api.Attachment (see the plugin API here 
http://code.xwiki.org/xwiki/bin/view/Plugins/MailSenderPlugin).
If you want to have the proper wrapped attachments to pass the plugin, 
you should use newdoc.newDocument(context).getAttachmentList()

Hope this helps,
Jerome.

Daniel Svoboda wrote:
 Thanks for the replies.

 I had already found that bug. If I take the conditional completely out  
 of the class, it still doesn't send an email.

 Dan

 It is probably due to the following :

 if(newdoc.getSpace().substring(lastFour) == Blog) {

 in Java, if you have the following :

 String st1 = Blog;
 String st2 = new String(Blog);

 then st1 == st2 will always return false, as the objects are not the
 same. What you want is to compare their values, using st1.equals(st2),
 which will return true.
 You can read here to find out more
 http://www.unix.com.ua/orelly/java/langref/ch04_09.htm (especially  
 this
 sentence : Because the == operator determines if two objects are the
 same object, it is not appropriate for comparisons that need to
 determine if two objects have the same contents. For example, if you
 need to know whether two String objects contain the same sequences of
 characters, the == operator is inappropriate. You should use the
 equals() method)

 Anyway, their is even simpler for you. What you want to do is check if
 the space name finishes by Blog. For this the appropriate method is
 String#endsWith
 (http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#endsWith(java.lang.String)
  
 )
 As in :

 if(newdoc.getSpace().endsWith(Blog)) {

 Hope this helps and fixes your issue,

 Regards,
 Jerome

 Daniel Svoboda wrote:
 Yes. The problem is that no mail gets sent, which is the purpose of
 the notification. I reread my initial post, and now I understand your
 confusion. I didn't explicitly state that the class wasn't working.

 I'm using XWiki Enterprise manager 1.3 with platform version 1.5.2.

 Dan


 Do you actually encounter a problem, besides the error in the logs ?
 I believe those logs are generated when you call  
 getRenderedContent on
 your blog article, so I maintain they have nothing to do with your
 notification class.
 Which version of XWiki Enterprise are you using ?

 Jerome.

 Dan Svoboda wrote:
 Hi,

 See below

 Dan Svoboda wrote:
 Hi,

 I'm trying to use the notification system to trigger the  
 sending of
 email whenever a comment is added to a blog article. I'm
 patterning my
 groovy class after the pircbot example on the xwiki snippets  
 site.

 My system is xwiki workspaces as a virtual xwiki under xem. The
 platform version is 1.5.2.

 Here's my groovy class  
 (XWSNotify.BlogMailNotificationGroovyClass):

 /* Groovy Class #* */

 import com.xpn.xwiki.api.XWiki;
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.notify.XWikiDocChangeNotificationInterface;
 import com.xpn.xwiki.notify.DocObjectChangedRule;
 import com.xpn.xwiki.notify.XWikiNotificationRule;
 import com.xpn.xwiki.doc.XWikiDocument;

 public class BlogMailNotificationGroovyClass implements \

 XWikiDocChangeNotificationInterface

 {
   def xwiki;
   def rule;
   def name;

   public void initClasses(XWikiContext context)
   {
   this.xwiki = context.getWiki();
   // listen to notifications
   this.rule = DocObjectChangedRule(this);

 context.getWiki().getNotificationManager().addGeneralRule(rule);
   }

   public void notify(XWikiNotificationRule rule, XWikiDocument
 newdoc, \
  XWikiDocument olddoc, int event,  
 XWikiContext
 context)
   {
   def length = newdoc.getSpace().length();
   def lastFour = length - 4;
   if(newdoc.getSpace().substring(lastFour) == Blog) {

   def ms = xwiki.getPlugin(mailsender);
   def nb = ms.sendHtmlMessage(context.getUser(),
 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
 , \
  context.get(ccrecipients),
 context.get(bccrecipients), \
  context.get(subject),
 newdoc.getRenderedContent(), \
  newdoc.getContent(),
 newdoc.getAttachments());
   }
   }
 }

 /* *# */

 Here's a velocity script I'm using to initialize/test:

 #set($sc =
 $context.getContext().getEngineContext().getServletContext())
 $sc.getAttribute(blgmailnotif)br/
 #set($blgmlnotif =
 $
 xwiki
 .parseGroovyFromPage 
 (XWSNotify.BlogMailNotificationGroovyClass))
 #set($ok = $sc.setAttribute(blgmailnotif, $blgmlnotif))
 #set($blgmailnotif = $sc.getAttribute(blgmailnotif))
 $sc.getAttribute(blgmailnotif)br/
 #set($ok = $blgmlnotif.initClasses($context))
 #set($ok = $blgmlnotif.notify($blgmlnotif.rule,$newdoc,$newdoc,
 3,$context))

 Here's the output from the velocity script:

 [EMAIL PROTECTED]
 [EMAIL 

Re: [xwiki-users] groovy notification

2008-11-24 Thread Jerome Velociter
BTW, your snippet is interesting, maybe you can consider publishing it 
as a FAQ entry How to send blog posts by email or a code snippet on 
code.xwiki.org once you get it working properly :)

Jerome.

Jerome Velociter wrote:
 Ok, I have another idea. Did you try sending the mail without attachments ?

 This because what you pass the plugin API are XWikiAttachments 
 (http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwiki/doc/XWikiAttachment.html),
  
 while it expects com.xpn.xwiki.api.Attachment (see the plugin API here 
 http://code.xwiki.org/xwiki/bin/view/Plugins/MailSenderPlugin).
 If you want to have the proper wrapped attachments to pass the plugin, 
 you should use newdoc.newDocument(context).getAttachmentList()

 Hope this helps,
 Jerome.

 Daniel Svoboda wrote:
 Thanks for the replies.

 I had already found that bug. If I take the conditional completely out  
 of the class, it still doesn't send an email.

 Dan

 It is probably due to the following :

 if(newdoc.getSpace().substring(lastFour) == Blog) {

 in Java, if you have the following :

 String st1 = Blog;
 String st2 = new String(Blog);

 then st1 == st2 will always return false, as the objects are not the
 same. What you want is to compare their values, using st1.equals(st2),
 which will return true.
 You can read here to find out more
 http://www.unix.com.ua/orelly/java/langref/ch04_09.htm (especially  
 this
 sentence : Because the == operator determines if two objects are the
 same object, it is not appropriate for comparisons that need to
 determine if two objects have the same contents. For example, if you
 need to know whether two String objects contain the same sequences of
 characters, the == operator is inappropriate. You should use the
 equals() method)

 Anyway, their is even simpler for you. What you want to do is check if
 the space name finishes by Blog. For this the appropriate method is
 String#endsWith
 (http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#endsWith(java.lang.String)
  
 )
 As in :

 if(newdoc.getSpace().endsWith(Blog)) {

 Hope this helps and fixes your issue,

 Regards,
 Jerome

 Daniel Svoboda wrote:
 Yes. The problem is that no mail gets sent, which is the purpose of
 the notification. I reread my initial post, and now I understand your
 confusion. I didn't explicitly state that the class wasn't working.

 I'm using XWiki Enterprise manager 1.3 with platform version 1.5.2.

 Dan


 Do you actually encounter a problem, besides the error in the logs ?
 I believe those logs are generated when you call  
 getRenderedContent on
 your blog article, so I maintain they have nothing to do with your
 notification class.
 Which version of XWiki Enterprise are you using ?

 Jerome.

 Dan Svoboda wrote:
 Hi,

 See below

 Dan Svoboda wrote:
 Hi,

 I'm trying to use the notification system to trigger the  
 sending of
 email whenever a comment is added to a blog article. I'm
 patterning my
 groovy class after the pircbot example on the xwiki snippets  
 site.

 My system is xwiki workspaces as a virtual xwiki under xem. The
 platform version is 1.5.2.

 Here's my groovy class  
 (XWSNotify.BlogMailNotificationGroovyClass):

 /* Groovy Class #* */

 import com.xpn.xwiki.api.XWiki;
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.notify.XWikiDocChangeNotificationInterface;
 import com.xpn.xwiki.notify.DocObjectChangedRule;
 import com.xpn.xwiki.notify.XWikiNotificationRule;
 import com.xpn.xwiki.doc.XWikiDocument;

 public class BlogMailNotificationGroovyClass implements \

 XWikiDocChangeNotificationInterface

 {
   def xwiki;
   def rule;
   def name;

   public void initClasses(XWikiContext context)
   {
   this.xwiki = context.getWiki();
   // listen to notifications
   this.rule = DocObjectChangedRule(this);

 context.getWiki().getNotificationManager().addGeneralRule(rule);
   }

   public void notify(XWikiNotificationRule rule, XWikiDocument
 newdoc, \
  XWikiDocument olddoc, int event,  
 XWikiContext
 context)
   {
   def length = newdoc.getSpace().length();
   def lastFour = length - 4;
   if(newdoc.getSpace().substring(lastFour) == Blog) {

   def ms = xwiki.getPlugin(mailsender);
   def nb = ms.sendHtmlMessage(context.getUser(),
 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
 , \
  context.get(ccrecipients),
 context.get(bccrecipients), \
  context.get(subject),
 newdoc.getRenderedContent(), \
  newdoc.getContent(),
 newdoc.getAttachments());
   }
   }
 }

 /* *# */

 Here's a velocity script I'm using to initialize/test:

 #set($sc =
 $context.getContext().getEngineContext().getServletContext())
 $sc.getAttribute(blgmailnotif)br/
 #set($blgmlnotif =
 $
 xwiki
 .parseGroovyFromPage 
 (XWSNotify.BlogMailNotificationGroovyClass))
 #set($ok = $sc.setAttribute(blgmailnotif, $blgmlnotif))
 #set($blgmailnotif = $sc.getAttribute(blgmailnotif))
 

Re: [xwiki-users] groovy notification

2008-11-24 Thread Dan Svoboda
I tried changing newdoc.getAttachments() to  
newdoc.newDocument(context).getAttachmentList().

I've stripped down the class to remove dependance on getting values  
out of the context; i.e I've provided string literals for sender, cc,  
etc. I've also changed the rule to DocChangeRule(this), and removed  
the test for the change coming from a space's Blog so that any  
document save event would trigger email.

Still no joy.

The only clue in the log is when calling the notify method from a  
velocity script:

[WARNING] Cannot retrieve method notify from object of class  
BlogMailNotificationGroovyClass due to security restrictions.

Dan

Here's the revised class:

/* Groovy Class #* */

import com.xpn.xwiki.api.XWiki;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.notify.XWikiDocChangeNotificationInterface;
import com.xpn.xwiki.notify.DocObjectChangedRule;
import com.xpn.xwiki.notify.XWikiNotificationRule;
import com.xpn.xwiki.doc.XWikiDocument;

public class BlogMailNotificationGroovyClass implements \
   
XWikiDocChangeNotificationInterface

{
 def xwiki;
 def rule;
 def name;

 public void initClasses(XWikiContext context)
 {
 this.xwiki = context.getWiki();
 // listen to notifications
 this.rule = DocChangeRule(this);
  
context.getWiki().getNotificationManager().addGeneralRule(rule);
 }

 public void notify(XWikiNotificationRule rule, XWikiDocument  
newdoc, \
XWikiDocument olddoc, int event, XWikiContext  
context)
 {

 def ms = xwiki.getPlugin(mailsender);
 def nb = ms.sendHtmlMessage(XWiki.Admin, \
[EMAIL PROTECTED], \
[EMAIL PROTECTED], \
[EMAIL PROTECTED], \
subject, \
newdoc.getRenderedContent(), \
newdoc.getContent(), \
 
newdoc.newDocument(context).getAttachmentList());
 }
}

/* *# */



 Ok, I have another idea. Did you try sending the mail without  
 attachments ?

 This because what you pass the plugin API are XWikiAttachments
 (http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwiki/doc/XWikiAttachment.html
  
 ),
 while it expects com.xpn.xwiki.api.Attachment (see the plugin API  
 here
 http://code.xwiki.org/xwiki/bin/view/Plugins/MailSenderPlugin).
 If you want to have the proper wrapped attachments to pass the plugin,
 you should use newdoc.newDocument(context).getAttachmentList()

 Hope this helps,
 Jerome.

 Daniel Svoboda wrote:
 Thanks for the replies.

 I had already found that bug. If I take the conditional completely  
 out
 of the class, it still doesn't send an email.

 Dan

 It is probably due to the following :

 if(newdoc.getSpace().substring(lastFour) == Blog) {

 in Java, if you have the following :

 String st1 = Blog;
 String st2 = new String(Blog);

 then st1 == st2 will always return false, as the objects are not the
 same. What you want is to compare their values, using  
 st1.equals(st2),
 which will return true.
 You can read here to find out more
 http://www.unix.com.ua/orelly/java/langref/ch04_09.htm (especially
 this
 sentence : Because the == operator determines if two objects are  
 the
 same object, it is not appropriate for comparisons that need to
 determine if two objects have the same contents. For example, if you
 need to know whether two String objects contain the same sequences  
 of
 characters, the == operator is inappropriate. You should use the
 equals() method)

 Anyway, their is even simpler for you. What you want to do is  
 check if
 the space name finishes by Blog. For this the appropriate method  
 is
 String#endsWith
 (http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#endsWith(java.lang.String
  
 )
 )
 As in :

 if(newdoc.getSpace().endsWith(Blog)) {

 Hope this helps and fixes your issue,

 Regards,
 Jerome

 Daniel Svoboda wrote:
 Yes. The problem is that no mail gets sent, which is the purpose of
 the notification. I reread my initial post, and now I understand  
 your
 confusion. I didn't explicitly state that the class wasn't working.

 I'm using XWiki Enterprise manager 1.3 with platform version 1.5.2.

 Dan


 Do you actually encounter a problem, besides the error in the  
 logs ?
 I believe those logs are generated when you call
 getRenderedContent on
 your blog article, so I maintain they have nothing to do with your
 notification class.
 Which version of XWiki Enterprise are you using ?

 Jerome.

 Dan Svoboda wrote:
 Hi,

 See below

 Dan Svoboda wrote:
 Hi,

 I'm trying to use the notification system to trigger the
 sending of
 email whenever a comment is added to a blog article. I'm
 patterning my
 groovy class after the pircbot example on the xwiki snippets
 site.

 My system is xwiki workspaces as a virtual xwiki under xem. The
 platform 

Re: [xwiki-users] groovy notification

2008-11-24 Thread Dan Svoboda

I found something else that was incorrect, but correcting it didn't  
help:

newdoc.getRenderedContent() needs to be  
newdoc.getRenderedContent(context)

Dan

 I tried changing newdoc.getAttachments() to  
 newdoc.newDocument(context).getAttachmentList().

 I've stripped down the class to remove dependance on getting values  
 out of the context; i.e I've provided string literals for sender,  
 cc, etc. I've also changed the rule to DocChangeRule(this), and  
 removed the test for the change coming from a space's Blog so that  
 any document save event would trigger email.

 Still no joy.

 The only clue in the log is when calling the notify method from a  
 velocity script:

 [WARNING] Cannot retrieve method notify from object of class  
 BlogMailNotificationGroovyClass due to security restrictions.

 Dan

 Here's the revised class:

 /* Groovy Class #* */

 import com.xpn.xwiki.api.XWiki;
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.notify.XWikiDocChangeNotificationInterface;
 import com.xpn.xwiki.notify.DocObjectChangedRule;
 import com.xpn.xwiki.notify.XWikiNotificationRule;
 import com.xpn.xwiki.doc.XWikiDocument;

 public class BlogMailNotificationGroovyClass implements \
   
 XWikiDocChangeNotificationInterface

 {
 def xwiki;
 def rule;
 def name;

 public void initClasses(XWikiContext context)
 {
 this.xwiki = context.getWiki();
 // listen to notifications
 this.rule = DocChangeRule(this);
  
 context.getWiki().getNotificationManager().addGeneralRule(rule);
 }

 public void notify(XWikiNotificationRule rule, XWikiDocument  
 newdoc, \
XWikiDocument olddoc, int event, XWikiContext  
 context)
 {

 def ms = xwiki.getPlugin(mailsender);
 def nb = ms.sendHtmlMessage(XWiki.Admin, \
[EMAIL PROTECTED], \
[EMAIL PROTECTED], \
[EMAIL PROTECTED], \
subject, \
newdoc.getRenderedContent(), \
newdoc.getContent(), \
 
 newdoc.newDocument(context).getAttachmentList());
 }
 }

 /* *# */



 Ok, I have another idea. Did you try sending the mail without  
 attachments ?

 This because what you pass the plugin API are XWikiAttachments
 (http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwiki/doc/XWikiAttachment.html
  
 ),
 while it expects com.xpn.xwiki.api.Attachment (see the plugin API  
 here
 http://code.xwiki.org/xwiki/bin/view/Plugins/MailSenderPlugin).
 If you want to have the proper wrapped attachments to pass the  
 plugin,
 you should use newdoc.newDocument(context).getAttachmentList()

 Hope this helps,
 Jerome.

 Daniel Svoboda wrote:
 Thanks for the replies.

 I had already found that bug. If I take the conditional completely  
 out
 of the class, it still doesn't send an email.

 Dan

 It is probably due to the following :

 if(newdoc.getSpace().substring(lastFour) == Blog) {

 in Java, if you have the following :

 String st1 = Blog;
 String st2 = new String(Blog);

 then st1 == st2 will always return false, as the objects are not  
 the
 same. What you want is to compare their values, using  
 st1.equals(st2),
 which will return true.
 You can read here to find out more
 http://www.unix.com.ua/orelly/java/langref/ch04_09.htm (especially
 this
 sentence : Because the == operator determines if two objects are  
 the
 same object, it is not appropriate for comparisons that need to
 determine if two objects have the same contents. For example, if  
 you
 need to know whether two String objects contain the same  
 sequences of
 characters, the == operator is inappropriate. You should use the
 equals() method)

 Anyway, their is even simpler for you. What you want to do is  
 check if
 the space name finishes by Blog. For this the appropriate  
 method is
 String#endsWith
 (http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#endsWith(java.lang.String
  
 )
 )
 As in :

 if(newdoc.getSpace().endsWith(Blog)) {

 Hope this helps and fixes your issue,

 Regards,
 Jerome

 Daniel Svoboda wrote:
 Yes. The problem is that no mail gets sent, which is the purpose  
 of
 the notification. I reread my initial post, and now I understand  
 your
 confusion. I didn't explicitly state that the class wasn't  
 working.

 I'm using XWiki Enterprise manager 1.3 with platform version  
 1.5.2.

 Dan


 Do you actually encounter a problem, besides the error in the  
 logs ?
 I believe those logs are generated when you call
 getRenderedContent on
 your blog article, so I maintain they have nothing to do with  
 your
 notification class.
 Which version of XWiki Enterprise are you using ?

 Jerome.

 Dan Svoboda wrote:
 Hi,

 See below

 Dan Svoboda wrote:
 Hi,

 I'm trying to use the notification system to trigger the
 sending of
 email 

Re: [xwiki-users] groovy notification

2008-11-22 Thread Daniel Svoboda
Yes. The problem is that no mail gets sent, which is the purpose of  
the notification. I reread my initial post, and now I understand your  
confusion. I didn't explicitly state that the class wasn't working.

I'm using XWiki Enterprise manager 1.3 with platform version 1.5.2.

Dan


 Do you actually encounter a problem, besides the error in the logs ?
 I believe those logs are generated when you call getRenderedContent on
 your blog article, so I maintain they have nothing to do with your
 notification class.
 Which version of XWiki Enterprise are you using ?

 Jerome.

 Dan Svoboda wrote:
 Hi,

 See below

 Dan Svoboda wrote:
 Hi,

 I'm trying to use the notification system to trigger the sending of
 email whenever a comment is added to a blog article. I'm  
 patterning my
 groovy class after the pircbot example on the xwiki snippets site.

 My system is xwiki workspaces as a virtual xwiki under xem. The
 platform version is 1.5.2.

 Here's my groovy class (XWSNotify.BlogMailNotificationGroovyClass):

 /* Groovy Class #* */

 import com.xpn.xwiki.api.XWiki;
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.notify.XWikiDocChangeNotificationInterface;
 import com.xpn.xwiki.notify.DocObjectChangedRule;
 import com.xpn.xwiki.notify.XWikiNotificationRule;
 import com.xpn.xwiki.doc.XWikiDocument;

 public class BlogMailNotificationGroovyClass implements \

 XWikiDocChangeNotificationInterface

 {
def xwiki;
def rule;
def name;

public void initClasses(XWikiContext context)
{
this.xwiki = context.getWiki();
// listen to notifications
this.rule = DocObjectChangedRule(this);

 context.getWiki().getNotificationManager().addGeneralRule(rule);
}

public void notify(XWikiNotificationRule rule, XWikiDocument
 newdoc, \
   XWikiDocument olddoc, int event, XWikiContext
 context)
{
def length = newdoc.getSpace().length();
def lastFour = length - 4;
if(newdoc.getSpace().substring(lastFour) == Blog) {

def ms = xwiki.getPlugin(mailsender);
def nb = ms.sendHtmlMessage(context.getUser(),
 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
 , \
   context.get(ccrecipients),
 context.get(bccrecipients), \
   context.get(subject),
 newdoc.getRenderedContent(), \
   newdoc.getContent(),
 newdoc.getAttachments());
}
}
 }

 /* *# */

 Here's a velocity script I'm using to initialize/test:

 #set($sc =  
 $context.getContext().getEngineContext().getServletContext())
 $sc.getAttribute(blgmailnotif)br/
 #set($blgmlnotif =
 $ 
 xwiki 
 .parseGroovyFromPage(XWSNotify.BlogMailNotificationGroovyClass))
 #set($ok = $sc.setAttribute(blgmailnotif, $blgmlnotif))
 #set($blgmailnotif = $sc.getAttribute(blgmailnotif))
 $sc.getAttribute(blgmailnotif)br/
 #set($ok = $blgmlnotif.initClasses($context))
 #set($ok = $blgmlnotif.notify($blgmlnotif.rule,$newdoc,$newdoc,
 3,$context))

 Here's the output from the velocity script:

 [EMAIL PROTECTED]
 [EMAIL PROTECTED]

 So, the groovy class gets initialized to a new reference  
 successfully
 each time parseGroovyFromPage is called.

 Here's what appears in the log after running the velocity script:

 [ERROR] Left side ($request.title) of '!=' operation has null  
 value.
 Operation not possible.  [line 53, column 43]
 [WARNING] Cannot retrieve method notify from object of class
 BlogMailNotificationGroovyClass due to security restrictions.

 If I alter the velocity script to:

 #set($sc =  
 $context.getContext().getEngineContext().getServletContext())
 $sc.getAttribute(blgmailnotif)br/

 Here's what appears in the log:

 [ERROR] Left side ($request.title) of '!=' operation has null  
 value.
 Operation not possible.  [line 53, column 43]

 So, the [WARNING] is the only log entry pertaining to the groovy  
 class.

 If I add a comment to a Blog article (with or without the
 BlogMailNotificationGroovyClass initialized), the following  
 appears in
 the log:

 [ERROR] Left side ($index) of addition operation has null value.
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null 

Re: [xwiki-users] groovy notification

2008-11-22 Thread Jerome Velociter
It is probably due to the following :

if(newdoc.getSpace().substring(lastFour) == Blog) {

in Java, if you have the following :

String st1 = Blog;
String st2 = new String(Blog);

then st1 == st2 will always return false, as the objects are not the 
same. What you want is to compare their values, using st1.equals(st2), 
which will return true.
You can read here to find out more 
http://www.unix.com.ua/orelly/java/langref/ch04_09.htm (especially this 
sentence : Because the == operator determines if two objects are the 
same object, it is not appropriate for comparisons that need to 
determine if two objects have the same contents. For example, if you 
need to know whether two String objects contain the same sequences of 
characters, the == operator is inappropriate. You should use the 
equals() method)

Anyway, their is even simpler for you. What you want to do is check if 
the space name finishes by Blog. For this the appropriate method is 
String#endsWith 
(http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#endsWith(java.lang.String))
 
As in :

if(newdoc.getSpace().endsWith(Blog)) {

Hope this helps and fixes your issue,

Regards,
Jerome

Daniel Svoboda wrote:
 Yes. The problem is that no mail gets sent, which is the purpose of  
 the notification. I reread my initial post, and now I understand your  
 confusion. I didn't explicitly state that the class wasn't working.

 I'm using XWiki Enterprise manager 1.3 with platform version 1.5.2.

 Dan


 Do you actually encounter a problem, besides the error in the logs ?
 I believe those logs are generated when you call getRenderedContent on
 your blog article, so I maintain they have nothing to do with your
 notification class.
 Which version of XWiki Enterprise are you using ?

 Jerome.

 Dan Svoboda wrote:
 Hi,

 See below

 Dan Svoboda wrote:
 Hi,

 I'm trying to use the notification system to trigger the sending of
 email whenever a comment is added to a blog article. I'm  
 patterning my
 groovy class after the pircbot example on the xwiki snippets site.

 My system is xwiki workspaces as a virtual xwiki under xem. The
 platform version is 1.5.2.

 Here's my groovy class (XWSNotify.BlogMailNotificationGroovyClass):

 /* Groovy Class #* */

 import com.xpn.xwiki.api.XWiki;
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.notify.XWikiDocChangeNotificationInterface;
 import com.xpn.xwiki.notify.DocObjectChangedRule;
 import com.xpn.xwiki.notify.XWikiNotificationRule;
 import com.xpn.xwiki.doc.XWikiDocument;

 public class BlogMailNotificationGroovyClass implements \

 XWikiDocChangeNotificationInterface

 {
def xwiki;
def rule;
def name;

public void initClasses(XWikiContext context)
{
this.xwiki = context.getWiki();
// listen to notifications
this.rule = DocObjectChangedRule(this);

 context.getWiki().getNotificationManager().addGeneralRule(rule);
}

public void notify(XWikiNotificationRule rule, XWikiDocument
 newdoc, \
   XWikiDocument olddoc, int event, XWikiContext
 context)
{
def length = newdoc.getSpace().length();
def lastFour = length - 4;
if(newdoc.getSpace().substring(lastFour) == Blog) {

def ms = xwiki.getPlugin(mailsender);
def nb = ms.sendHtmlMessage(context.getUser(),
 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
 , \
   context.get(ccrecipients),
 context.get(bccrecipients), \
   context.get(subject),
 newdoc.getRenderedContent(), \
   newdoc.getContent(),
 newdoc.getAttachments());
}
}
 }

 /* *# */

 Here's a velocity script I'm using to initialize/test:

 #set($sc =  
 $context.getContext().getEngineContext().getServletContext())
 $sc.getAttribute(blgmailnotif)br/
 #set($blgmlnotif =
 $ 
 xwiki 
 .parseGroovyFromPage(XWSNotify.BlogMailNotificationGroovyClass))
 #set($ok = $sc.setAttribute(blgmailnotif, $blgmlnotif))
 #set($blgmailnotif = $sc.getAttribute(blgmailnotif))
 $sc.getAttribute(blgmailnotif)br/
 #set($ok = $blgmlnotif.initClasses($context))
 #set($ok = $blgmlnotif.notify($blgmlnotif.rule,$newdoc,$newdoc,
 3,$context))

 Here's the output from the velocity script:

 [EMAIL PROTECTED]
 [EMAIL PROTECTED]

 So, the groovy class gets initialized to a new reference  
 successfully
 each time parseGroovyFromPage is called.

 Here's what appears in the log after running the velocity script:

 [ERROR] Left side ($request.title) of '!=' operation has null  
 value.
 Operation not possible.  [line 53, column 43]
 [WARNING] Cannot retrieve method notify from object of class
 BlogMailNotificationGroovyClass due to security restrictions.

 If I alter the velocity script to:

 #set($sc =  
 $context.getContext().getEngineContext().getServletContext())
 $sc.getAttribute(blgmailnotif)br/

 Here's what appears in the log:

 [ERROR] Left side ($request.title) of '!=' operation has null  
 value.
 Operation not possible.  [line 53, 

Re: [xwiki-users] groovy notification

2008-11-22 Thread Vincent Massol

On Nov 22, 2008, at 4:30 PM, Jerome Velociter wrote:

 It is probably due to the following :

 if(newdoc.getSpace().substring(lastFour) == Blog) {

 in Java, if you have the following :

 String st1 = Blog;
 String st2 = new String(Blog);

 then st1 == st2 will always return false

OT
This statement is not quite correct... In order for JVM to be  
performant there's a pool of reusable string objects and if the string  
created as the same content as one of the strings in the pool that  
string object will be returned (and thus both of your strings will  
point to the same object in memory).

There's even an intern() method to force your string content to be  
interned in that pool.

Try this to convince yourself:

 String st1 = Blog.intern();
 String st2 = new String(Blog).intern();
 assertSame(st1, st2);

This is AFAIR. You can google for Java String intern.
/OT

Of course what Jerome says is correct, you should always check for  
equality use equals() and not ==

Thanks
-Vincent

 , as the objects are not the
 same. What you want is to compare their values, using st1.equals(st2),
 which will return true.
 You can read here to find out more
 http://www.unix.com.ua/orelly/java/langref/ch04_09.htm (especially  
 this
 sentence : Because the == operator determines if two objects are the
 same object, it is not appropriate for comparisons that need to
 determine if two objects have the same contents. For example, if you
 need to know whether two String objects contain the same sequences of
 characters, the == operator is inappropriate. You should use the
 equals() method)

 Anyway, their is even simpler for you. What you want to do is check if
 the space name finishes by Blog. For this the appropriate method is
 String#endsWith
 (http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#endsWith(java.lang.String)
  
 )
 As in :

 if(newdoc.getSpace().endsWith(Blog)) {

 Hope this helps and fixes your issue,

 Regards,
 Jerome

 Daniel Svoboda wrote:
 Yes. The problem is that no mail gets sent, which is the purpose of
 the notification. I reread my initial post, and now I understand your
 confusion. I didn't explicitly state that the class wasn't working.

 I'm using XWiki Enterprise manager 1.3 with platform version 1.5.2.

 Dan


 Do you actually encounter a problem, besides the error in the logs ?
 I believe those logs are generated when you call  
 getRenderedContent on
 your blog article, so I maintain they have nothing to do with your
 notification class.
 Which version of XWiki Enterprise are you using ?

 Jerome.

 Dan Svoboda wrote:
 Hi,

 See below

 Dan Svoboda wrote:
 Hi,

 I'm trying to use the notification system to trigger the  
 sending of
 email whenever a comment is added to a blog article. I'm
 patterning my
 groovy class after the pircbot example on the xwiki snippets  
 site.

 My system is xwiki workspaces as a virtual xwiki under xem. The
 platform version is 1.5.2.

 Here's my groovy class  
 (XWSNotify.BlogMailNotificationGroovyClass):

 /* Groovy Class #* */

 import com.xpn.xwiki.api.XWiki;
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.notify.XWikiDocChangeNotificationInterface;
 import com.xpn.xwiki.notify.DocObjectChangedRule;
 import com.xpn.xwiki.notify.XWikiNotificationRule;
 import com.xpn.xwiki.doc.XWikiDocument;

 public class BlogMailNotificationGroovyClass implements \

 XWikiDocChangeNotificationInterface

 {
   def xwiki;
   def rule;
   def name;

   public void initClasses(XWikiContext context)
   {
   this.xwiki = context.getWiki();
   // listen to notifications
   this.rule = DocObjectChangedRule(this);

 context.getWiki().getNotificationManager().addGeneralRule(rule);
   }

   public void notify(XWikiNotificationRule rule, XWikiDocument
 newdoc, \
  XWikiDocument olddoc, int event,  
 XWikiContext
 context)
   {
   def length = newdoc.getSpace().length();
   def lastFour = length - 4;
   if(newdoc.getSpace().substring(lastFour) == Blog) {

   def ms = xwiki.getPlugin(mailsender);
   def nb = ms.sendHtmlMessage(context.getUser(),
 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
 , \
  context.get(ccrecipients),
 context.get(bccrecipients), \
  context.get(subject),
 newdoc.getRenderedContent(), \
  newdoc.getContent(),
 newdoc.getAttachments());
   }
   }
 }

 /* *# */

 Here's a velocity script I'm using to initialize/test:

 #set($sc =
 $context.getContext().getEngineContext().getServletContext())
 $sc.getAttribute(blgmailnotif)br/
 #set($blgmlnotif =
 $
 xwiki
 .parseGroovyFromPage 
 (XWSNotify.BlogMailNotificationGroovyClass))
 #set($ok = $sc.setAttribute(blgmailnotif, $blgmlnotif))
 #set($blgmailnotif = $sc.getAttribute(blgmailnotif))
 $sc.getAttribute(blgmailnotif)br/
 #set($ok = $blgmlnotif.initClasses($context))
 #set($ok = $blgmlnotif.notify($blgmlnotif.rule,$newdoc,$newdoc,
 3,$context))

 Here's 

Re: [xwiki-users] groovy notification

2008-11-22 Thread Jerome Velociter
Vincent Massol wrote:
 On Nov 22, 2008, at 4:30 PM, Jerome Velociter wrote:

 It is probably due to the following :

 if(newdoc.getSpace().substring(lastFour) == Blog) {

 in Java, if you have the following :

 String st1 = Blog;
 String st2 = new String(Blog);

 then st1 == st2 will always return false

 OT
 This statement is not quite correct... In order for JVM to be  
 performant there's a pool of reusable string objects and if the string  
 created as the same content as one of the strings in the pool that  
 string object will be returned (and thus both of your strings will  
 point to the same object in memory).

 From what I understand, when using new we deliberately state that the 
String should not be interned, thus the object are not going to be the 
same any case.

Strings can be automatically interned by the JVM (without calling 
.intern()) only when initialized not using new :

String st1 = Blog;
String st2 = Blog;

and then can potentially be considered as same.

Anyway, I'm discovering this :) I read that from 
http://mindprod.com/jgloss/interned.html#NEW

Jerome.



 There's even an intern() method to force your string content to be  
 interned in that pool.

 Try this to convince yourself:

  String st1 = Blog.intern();
  String st2 = new String(Blog).intern();
  assertSame(st1, st2);

 This is AFAIR. You can google for Java String intern.
 /OT

 Of course what Jerome says is correct, you should always check for  
 equality use equals() and not ==

 Thanks
 -Vincent

 , as the objects are not the
 same. What you want is to compare their values, using st1.equals(st2),
 which will return true.
 You can read here to find out more
 http://www.unix.com.ua/orelly/java/langref/ch04_09.htm (especially  
 this
 sentence : Because the == operator determines if two objects are the
 same object, it is not appropriate for comparisons that need to
 determine if two objects have the same contents. For example, if you
 need to know whether two String objects contain the same sequences of
 characters, the == operator is inappropriate. You should use the
 equals() method)

 Anyway, their is even simpler for you. What you want to do is check if
 the space name finishes by Blog. For this the appropriate method is
 String#endsWith
 (http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#endsWith(java.lang.String)
  
 )
 As in :

 if(newdoc.getSpace().endsWith(Blog)) {

 Hope this helps and fixes your issue,

 Regards,
 Jerome

 Daniel Svoboda wrote:
 Yes. The problem is that no mail gets sent, which is the purpose of
 the notification. I reread my initial post, and now I understand your
 confusion. I didn't explicitly state that the class wasn't working.

 I'm using XWiki Enterprise manager 1.3 with platform version 1.5.2.

 Dan


 Do you actually encounter a problem, besides the error in the logs ?
 I believe those logs are generated when you call  
 getRenderedContent on
 your blog article, so I maintain they have nothing to do with your
 notification class.
 Which version of XWiki Enterprise are you using ?

 Jerome.

 Dan Svoboda wrote:
 Hi,

 See below

 Dan Svoboda wrote:
 Hi,

 I'm trying to use the notification system to trigger the  
 sending of
 email whenever a comment is added to a blog article. I'm
 patterning my
 groovy class after the pircbot example on the xwiki snippets  
 site.

 My system is xwiki workspaces as a virtual xwiki under xem. The
 platform version is 1.5.2.

 Here's my groovy class  
 (XWSNotify.BlogMailNotificationGroovyClass):

 /* Groovy Class #* */

 import com.xpn.xwiki.api.XWiki;
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.notify.XWikiDocChangeNotificationInterface;
 import com.xpn.xwiki.notify.DocObjectChangedRule;
 import com.xpn.xwiki.notify.XWikiNotificationRule;
 import com.xpn.xwiki.doc.XWikiDocument;

 public class BlogMailNotificationGroovyClass implements \

 XWikiDocChangeNotificationInterface

 {
   def xwiki;
   def rule;
   def name;

   public void initClasses(XWikiContext context)
   {
   this.xwiki = context.getWiki();
   // listen to notifications
   this.rule = DocObjectChangedRule(this);

 context.getWiki().getNotificationManager().addGeneralRule(rule);
   }

   public void notify(XWikiNotificationRule rule, XWikiDocument
 newdoc, \
  XWikiDocument olddoc, int event,  
 XWikiContext
 context)
   {
   def length = newdoc.getSpace().length();
   def lastFour = length - 4;
   if(newdoc.getSpace().substring(lastFour) == Blog) {

   def ms = xwiki.getPlugin(mailsender);
   def nb = ms.sendHtmlMessage(context.getUser(),
 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
 , \
  context.get(ccrecipients),
 context.get(bccrecipients), \
  context.get(subject),
 newdoc.getRenderedContent(), \
  newdoc.getContent(),
 newdoc.getAttachments());
   }
   }
 }

 /* *# */

 Here's a velocity script I'm 

Re: [xwiki-users] groovy notification

2008-11-22 Thread Daniel Svoboda
Thanks for the replies.

I had already found that bug. If I take the conditional completely out  
of the class, it still doesn't send an email.

Dan

 It is probably due to the following :

 if(newdoc.getSpace().substring(lastFour) == Blog) {

 in Java, if you have the following :

 String st1 = Blog;
 String st2 = new String(Blog);

 then st1 == st2 will always return false, as the objects are not the
 same. What you want is to compare their values, using st1.equals(st2),
 which will return true.
 You can read here to find out more
 http://www.unix.com.ua/orelly/java/langref/ch04_09.htm (especially  
 this
 sentence : Because the == operator determines if two objects are the
 same object, it is not appropriate for comparisons that need to
 determine if two objects have the same contents. For example, if you
 need to know whether two String objects contain the same sequences of
 characters, the == operator is inappropriate. You should use the
 equals() method)

 Anyway, their is even simpler for you. What you want to do is check if
 the space name finishes by Blog. For this the appropriate method is
 String#endsWith
 (http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#endsWith(java.lang.String)
  
 )
 As in :

 if(newdoc.getSpace().endsWith(Blog)) {

 Hope this helps and fixes your issue,

 Regards,
 Jerome

 Daniel Svoboda wrote:
 Yes. The problem is that no mail gets sent, which is the purpose of
 the notification. I reread my initial post, and now I understand your
 confusion. I didn't explicitly state that the class wasn't working.

 I'm using XWiki Enterprise manager 1.3 with platform version 1.5.2.

 Dan


 Do you actually encounter a problem, besides the error in the logs ?
 I believe those logs are generated when you call  
 getRenderedContent on
 your blog article, so I maintain they have nothing to do with your
 notification class.
 Which version of XWiki Enterprise are you using ?

 Jerome.

 Dan Svoboda wrote:
 Hi,

 See below

 Dan Svoboda wrote:
 Hi,

 I'm trying to use the notification system to trigger the  
 sending of
 email whenever a comment is added to a blog article. I'm
 patterning my
 groovy class after the pircbot example on the xwiki snippets  
 site.

 My system is xwiki workspaces as a virtual xwiki under xem. The
 platform version is 1.5.2.

 Here's my groovy class  
 (XWSNotify.BlogMailNotificationGroovyClass):

 /* Groovy Class #* */

 import com.xpn.xwiki.api.XWiki;
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.notify.XWikiDocChangeNotificationInterface;
 import com.xpn.xwiki.notify.DocObjectChangedRule;
 import com.xpn.xwiki.notify.XWikiNotificationRule;
 import com.xpn.xwiki.doc.XWikiDocument;

 public class BlogMailNotificationGroovyClass implements \

 XWikiDocChangeNotificationInterface

 {
   def xwiki;
   def rule;
   def name;

   public void initClasses(XWikiContext context)
   {
   this.xwiki = context.getWiki();
   // listen to notifications
   this.rule = DocObjectChangedRule(this);

 context.getWiki().getNotificationManager().addGeneralRule(rule);
   }

   public void notify(XWikiNotificationRule rule, XWikiDocument
 newdoc, \
  XWikiDocument olddoc, int event,  
 XWikiContext
 context)
   {
   def length = newdoc.getSpace().length();
   def lastFour = length - 4;
   if(newdoc.getSpace().substring(lastFour) == Blog) {

   def ms = xwiki.getPlugin(mailsender);
   def nb = ms.sendHtmlMessage(context.getUser(),
 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
 , \
  context.get(ccrecipients),
 context.get(bccrecipients), \
  context.get(subject),
 newdoc.getRenderedContent(), \
  newdoc.getContent(),
 newdoc.getAttachments());
   }
   }
 }

 /* *# */

 Here's a velocity script I'm using to initialize/test:

 #set($sc =
 $context.getContext().getEngineContext().getServletContext())
 $sc.getAttribute(blgmailnotif)br/
 #set($blgmlnotif =
 $
 xwiki
 .parseGroovyFromPage 
 (XWSNotify.BlogMailNotificationGroovyClass))
 #set($ok = $sc.setAttribute(blgmailnotif, $blgmlnotif))
 #set($blgmailnotif = $sc.getAttribute(blgmailnotif))
 $sc.getAttribute(blgmailnotif)br/
 #set($ok = $blgmlnotif.initClasses($context))
 #set($ok = $blgmlnotif.notify($blgmlnotif.rule,$newdoc,$newdoc,
 3,$context))

 Here's the output from the velocity script:

 [EMAIL PROTECTED]
 [EMAIL PROTECTED]

 So, the groovy class gets initialized to a new reference
 successfully
 each time parseGroovyFromPage is called.

 Here's what appears in the log after running the velocity script:

 [ERROR] Left side ($request.title) of '!=' operation has null
 value.
 Operation not possible.  [line 53, column 43]
 [WARNING] Cannot retrieve method notify from object of class
 BlogMailNotificationGroovyClass due to security restrictions.

 If I alter the velocity script to:

 #set($sc =
 $context.getContext().getEngineContext().getServletContext())
 

Re: [xwiki-users] groovy notification

2008-11-21 Thread Dan Svoboda
Hi,

See below

Dan Svoboda wrote:
 Hi,

 I'm trying to use the notification system to trigger the sending of
 email whenever a comment is added to a blog article. I'm patterning my
 groovy class after the pircbot example on the xwiki snippets site.

 My system is xwiki workspaces as a virtual xwiki under xem. The
 platform version is 1.5.2.

 Here's my groovy class (XWSNotify.BlogMailNotificationGroovyClass):

 /* Groovy Class #* */

 import com.xpn.xwiki.api.XWiki;
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.notify.XWikiDocChangeNotificationInterface;
 import com.xpn.xwiki.notify.DocObjectChangedRule;
 import com.xpn.xwiki.notify.XWikiNotificationRule;
 import com.xpn.xwiki.doc.XWikiDocument;

 public class BlogMailNotificationGroovyClass implements \

 XWikiDocChangeNotificationInterface

 {
 def xwiki;
 def rule;
 def name;

 public void initClasses(XWikiContext context)
 {
 this.xwiki = context.getWiki();
 // listen to notifications
 this.rule = DocObjectChangedRule(this);

 context.getWiki().getNotificationManager().addGeneralRule(rule);
 }

 public void notify(XWikiNotificationRule rule, XWikiDocument
 newdoc, \
XWikiDocument olddoc, int event, XWikiContext
 context)
 {
 def length = newdoc.getSpace().length();
 def lastFour = length - 4;
 if(newdoc.getSpace().substring(lastFour) == Blog) {

 def ms = xwiki.getPlugin(mailsender);
 def nb = ms.sendHtmlMessage(context.getUser(), [EMAIL PROTECTED]
 , \
context.get(ccrecipients),
 context.get(bccrecipients), \
context.get(subject),
 newdoc.getRenderedContent(), \
newdoc.getContent(),
 newdoc.getAttachments());
 }
 }
 }

 /* *# */

 Here's a velocity script I'm using to initialize/test:

 #set($sc =  
 $context.getContext().getEngineContext().getServletContext())
 $sc.getAttribute(blgmailnotif)br/
 #set($blgmlnotif =
 $ 
 xwiki 
 .parseGroovyFromPage(XWSNotify.BlogMailNotificationGroovyClass))
 #set($ok = $sc.setAttribute(blgmailnotif, $blgmlnotif))
 #set($blgmailnotif = $sc.getAttribute(blgmailnotif))
 $sc.getAttribute(blgmailnotif)br/
 #set($ok = $blgmlnotif.initClasses($context))
 #set($ok = $blgmlnotif.notify($blgmlnotif.rule,$newdoc,$newdoc,
 3,$context))

 Here's the output from the velocity script:

 [EMAIL PROTECTED]
 [EMAIL PROTECTED]

 So, the groovy class gets initialized to a new reference successfully
 each time parseGroovyFromPage is called.

 Here's what appears in the log after running the velocity script:

 [ERROR] Left side ($request.title) of '!=' operation has null value.
 Operation not possible.  [line 53, column 43]
 [WARNING] Cannot retrieve method notify from object of class
 BlogMailNotificationGroovyClass due to security restrictions.

 If I alter the velocity script to:

 #set($sc =  
 $context.getContext().getEngineContext().getServletContext())
 $sc.getAttribute(blgmailnotif)br/

 Here's what appears in the log:

 [ERROR] Left side ($request.title) of '!=' operation has null value.
 Operation not possible.  [line 53, column 43]

 So, the [WARNING] is the only log entry pertaining to the groovy  
 class.

 If I add a comment to a Blog article (with or without the
 BlogMailNotificationGroovyClass initialized), the following appears in
 the log:

 [ERROR] Left side ($index) of addition operation has null value.
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.
 Operation not possible.  [line 20, column 25]

 The number of lines corresponds to the number of comments present in
 the Blog article. There's nothing in the log pertaining to the groovy
 class.

Indeed, this has nothing to do with your groovy notification. This is
generated by the velocity engine.
Is your skin customized ? Is the blog application modified ? (The log
says that somewhere a variable $index is trying to add something to
null. Might be the pagination of blog articles ?)

Jerome.

I can't find a variable $index in any arithmetical expression in any  
velocity script anywhere on the site.

The 

Re: [xwiki-users] groovy notification

2008-11-21 Thread Jerome Velociter
Do you actually encounter a problem, besides the error in the logs ?
I believe those logs are generated when you call getRenderedContent on 
your blog article, so I maintain they have nothing to do with your 
notification class.
Which version of XWiki Enterprise are you using ?

Jerome.

Dan Svoboda wrote:
 Hi,

 See below

 Dan Svoboda wrote:
 Hi,

 I'm trying to use the notification system to trigger the sending of  
 email whenever a comment is added to a blog article. I'm patterning my  
 groovy class after the pircbot example on the xwiki snippets site.

 My system is xwiki workspaces as a virtual xwiki under xem. The  
 platform version is 1.5.2.

 Here's my groovy class (XWSNotify.BlogMailNotificationGroovyClass):

 /* Groovy Class #* */

 import com.xpn.xwiki.api.XWiki;
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.notify.XWikiDocChangeNotificationInterface;
 import com.xpn.xwiki.notify.DocObjectChangedRule;
 import com.xpn.xwiki.notify.XWikiNotificationRule;
 import com.xpn.xwiki.doc.XWikiDocument;

 public class BlogMailNotificationGroovyClass implements \

 XWikiDocChangeNotificationInterface

 {
 def xwiki;
 def rule;
 def name;

 public void initClasses(XWikiContext context)
 {
 this.xwiki = context.getWiki();
 // listen to notifications
 this.rule = DocObjectChangedRule(this);

 context.getWiki().getNotificationManager().addGeneralRule(rule);
 }

 public void notify(XWikiNotificationRule rule, XWikiDocument  
 newdoc, \
XWikiDocument olddoc, int event, XWikiContext  
 context)
 {
 def length = newdoc.getSpace().length();
 def lastFour = length - 4;
 if(newdoc.getSpace().substring(lastFour) == Blog) {

 def ms = xwiki.getPlugin(mailsender);
 def nb = ms.sendHtmlMessage(context.getUser(), 
 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] 
 , \
context.get(ccrecipients),  
 context.get(bccrecipients), \
context.get(subject),  
 newdoc.getRenderedContent(), \
newdoc.getContent(),  
 newdoc.getAttachments());
 }
 }
 }

 /* *# */

 Here's a velocity script I'm using to initialize/test:

 #set($sc = $context.getContext().getEngineContext().getServletContext())
 $sc.getAttribute(blgmailnotif)br/
 #set($blgmlnotif =  
 $xwiki.parseGroovyFromPage(XWSNotify.BlogMailNotificationGroovyClass))
 #set($ok = $sc.setAttribute(blgmailnotif, $blgmlnotif))
 #set($blgmailnotif = $sc.getAttribute(blgmailnotif))
 $sc.getAttribute(blgmailnotif)br/
 #set($ok = $blgmlnotif.initClasses($context))
 #set($ok = $blgmlnotif.notify($blgmlnotif.rule,$newdoc,$newdoc, 
 3,$context))

 Here's the output from the velocity script:

 [EMAIL PROTECTED]
 [EMAIL PROTECTED]

 So, the groovy class gets initialized to a new reference successfully  
 each time parseGroovyFromPage is called.

 Here's what appears in the log after running the velocity script:

 [ERROR] Left side ($request.title) of '!=' operation has null value.  
 Operation not possible.  [line 53, column 43]
 [WARNING] Cannot retrieve method notify from object of class  
 BlogMailNotificationGroovyClass due to security restrictions.

 If I alter the velocity script to:

 #set($sc = $context.getContext().getEngineContext().getServletContext())
 $sc.getAttribute(blgmailnotif)br/

 Here's what appears in the log:

 [ERROR] Left side ($request.title) of '!=' operation has null value.  
 Operation not possible.  [line 53, column 43]

 So, the [WARNING] is the only log entry pertaining to the groovy class.

 If I add a comment to a Blog article (with or without the  
 BlogMailNotificationGroovyClass initialized), the following appears in  
 the log:

 [ERROR] Left side ($index) of addition operation has null value.  
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.  
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.  
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.  
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.  
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.  
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.  
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.  
 Operation not possible.  [line 20, column 25]
 [ERROR] Left side ($index) of addition operation has null value.  
 Operation not possible.  [line 20, column 25]

 The number of lines corresponds to the number of comments present in  
 the Blog article. There's nothing in the log pertaining to the groovy  
 class.

 Indeed, this has nothing to do with your