Re: [xwiki-users] groovy.lang.MissingMethodException - No signatureof method

2009-01-30 Thread Denis Gervalle
Hi Adjin,

com.xpn.xwiki.doc.XWikiDocument.addAttachment() has just been added in  
revision 14565, which was only release in 1.8M1. Before, the  
addAttachment() function was only available from  
com.xpn.xwiki.api.Document object. You may want to wrap your  
XWikiDocument object into a Document object with:

com.xpn.xwiki.api.Document apidoc = new Document(doc,context)
apidoc.addAttachment(filenameToSavaAs, imgAsBites)

Or you may do the job by yourself (be very careful that changing an  
XWikiDocument implies that you have to clone it first, if you want to  
avoid cache corruption in case you never store your changes or it  
fails.), this should be something like this:

def att = doc.getAttachment(filenameToSavaAs)
if( !att ) att = new com.xpn.xwiki.doc.XWikiAttachment(doc,  
filenameToSavaAs)
doc.getAttachmentList().add(att)
att.content = imgAsBites
att.author = context.user
// att.comment = 'comments for your attachement if you want'
doc.saveAttachmentContent(att,context)

Hope this helps,

Denis


On 29 janv. 09, at 18:01, Ajdin Brandic wrote:

 * I'm posting this again cos the whole post got mixed up with
 another post Custom class field as field on a different class
 http://n2.nabble.com/Custom-class-field-as-field-on-a-different-class-t
 p2152709p2239310.html  *

 As written previously I'm trying to trigger some code on document  
 save.

 Sergiu Dumitriu explained issue I had with
 (com.xpn.xwiki.doc.XWikiDocument vs.
 com.xpn.xwiki.api.Document).  I got most the stuff to work except  
 (last
 two lines of code) I am not able to save image from url as attachment.

 I get Wrapped Exception: No signature of method
 com.xpn.xwiki.doc.XWikiDocument.addAttachment() is applicable for
 argument types: (java.lang.String, [B, com.xpn.xwiki.XWikiContext)
 values: {notif1.png, [-119,.., [vcontext:...]}

 Looking at the documentation at
 http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn
 /xwiki/doc/XWikiDocument.html
 Says  XWikiAttachment | addAttachment(java.lang.String fileName,  
 byte[]
 data, XWikiContext context) 

 Have I got type issue here or???

 This is what I'm doing
 def doc = xwiki.getDocument(docName, context); //use this for
 com.xpn.xwiki.XWiki def tmpElList = el.split([\]) def umlImage =
 tmpElList[1] def imgAsBites =
 xwiki.getURLContentAsBytes(http://www.websequencediagrams.com/index.php
 +umlImage, context);
 def newAttachment = doc.addAttachment(filenameToSavaAs,imgAsBites,
 context); //use this for com.xpn.xwiki.XWiki
 saveAttachmentContent(newAttachment,context);

 Has anyone had a similar problem?

 Ajdin

 -Original Message-
 From: users-boun...@xwiki.org [mailto:users-boun...@xwiki.org] On  
 Behalf
 Of Sergiu Dumitriu
 Sent: 14 January 2009 17:03
 To: XWiki Users
 Subject: Re: [xwiki-users] groovy.lang.MissingMethodException

 Ajdin Brandic wrote:
 Hi

 I'm trying to execute another script on Save event.  I've created a
 notification class (based on xwiki example
 http://dev.xwiki.org/xwiki/bin/view/Drafts/GroovyNotifications) and
 pointed to it in Administration  Programming  Notification pages.

 This script gets called every time which is fine and when I try to
 display name of a document that is being saved (doc.fullName) all
 works well. document name it works fine but when I try to display one
 of the fieldnames doc.display('Summary') I get

 groovy.lang.MissingMethodException: No signature of method
 com.xpn.xwiki.doc.XWikiDocument.display() is applicable for argument
 types: (java.lang.String) values: {Summary}

 I tried
  def tmpDoc = context.getWiki().getDocument(doc.fullName, context);
 But again fullName is OK but display('Summary') isn't

 Am I missing something in my syntax?  How do I make document values
 available in my Notification class?

 As you see, that is not an api object, but an internal class
 (com.xpn.xwiki.doc.XWikiDocument vs. com.xpn.xwiki.api.Document). This
 means that API methods don't work, unless they have an equivalent in  
 the
 other class.

 You can either look at the methods of the XWikiDocument class, or  
 get an
 API object and work with it (new com.xpn.xwiki.apiDocument(tmpDoc)

 --
 Sergiu Dumitriu
 http://purl.org/net/sergiu/
 ___
 users mailing list
 users@xwiki.org
 http://lists.xwiki.org/mailman/listinfo/users


 

 NOTICE

 This message and any files transmitted with it is intended for the
 addressee only and may contain information that is confidential or
 privileged. Unauthorised use is strictly prohibited. If you are not  
 the
 addressee, you should not read, copy, disclose or otherwise use this
 message, except for the purpose of delivery to the addressee.

 Any views or opinions expressed within this e-mail are those of the
 author and do not necessarily represent those of Coventry University.
 ___
 users mailing list
 users@xwiki.org
 

[xwiki-users] groovy.lang.MissingMethodException - No signatureof method

2009-01-29 Thread Ajdin Brandic
* I'm posting this again cos the whole post got mixed up with
another post Custom class field as field on a different class
http://n2.nabble.com/Custom-class-field-as-field-on-a-different-class-t
p2152709p2239310.html  *
 
As written previously I'm trying to trigger some code on document save.
 
Sergiu Dumitriu explained issue I had with
(com.xpn.xwiki.doc.XWikiDocument vs.
com.xpn.xwiki.api.Document).  I got most the stuff to work except (last
two lines of code) I am not able to save image from url as attachment.
 
I get Wrapped Exception: No signature of method
com.xpn.xwiki.doc.XWikiDocument.addAttachment() is applicable for
argument types: (java.lang.String, [B, com.xpn.xwiki.XWikiContext)
values: {notif1.png, [-119,.., [vcontext:...]}
 
Looking at the documentation at
http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn
/xwiki/doc/XWikiDocument.html
Says  XWikiAttachment | addAttachment(java.lang.String fileName, byte[]
data, XWikiContext context) 
 
Have I got type issue here or???
 
This is what I'm doing
def doc = xwiki.getDocument(docName, context); //use this for
com.xpn.xwiki.XWiki def tmpElList = el.split([\]) def umlImage =
tmpElList[1] def imgAsBites =
xwiki.getURLContentAsBytes(http://www.websequencediagrams.com/index.php
+umlImage, context);
def newAttachment = doc.addAttachment(filenameToSavaAs,imgAsBites,
context); //use this for com.xpn.xwiki.XWiki
saveAttachmentContent(newAttachment,context);
 
Has anyone had a similar problem?
 
Ajdin
 
-Original Message-
From: users-boun...@xwiki.org [mailto:users-boun...@xwiki.org] On Behalf
Of Sergiu Dumitriu
Sent: 14 January 2009 17:03
To: XWiki Users
Subject: Re: [xwiki-users] groovy.lang.MissingMethodException
 
Ajdin Brandic wrote:
 Hi
 
 I'm trying to execute another script on Save event.  I've created a 
 notification class (based on xwiki example
 http://dev.xwiki.org/xwiki/bin/view/Drafts/GroovyNotifications) and 
 pointed to it in Administration  Programming  Notification pages.
 
 This script gets called every time which is fine and when I try to 
 display name of a document that is being saved (doc.fullName) all 
 works well. document name it works fine but when I try to display one 
 of the fieldnames doc.display('Summary') I get
 
 groovy.lang.MissingMethodException: No signature of method
 com.xpn.xwiki.doc.XWikiDocument.display() is applicable for argument
 types: (java.lang.String) values: {Summary}
 
 I tried 
   def tmpDoc = context.getWiki().getDocument(doc.fullName, context); 
 But again fullName is OK but display('Summary') isn't
 
 Am I missing something in my syntax?  How do I make document values 
 available in my Notification class?
 
As you see, that is not an api object, but an internal class
(com.xpn.xwiki.doc.XWikiDocument vs. com.xpn.xwiki.api.Document). This
means that API methods don't work, unless they have an equivalent in the
other class.
 
You can either look at the methods of the XWikiDocument class, or get an
API object and work with it (new com.xpn.xwiki.apiDocument(tmpDoc)
 
--
Sergiu Dumitriu
http://purl.org/net/sergiu/
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users
 
 

 
NOTICE
 
This message and any files transmitted with it is intended for the
addressee only and may contain information that is confidential or
privileged. Unauthorised use is strictly prohibited. If you are not the
addressee, you should not read, copy, disclose or otherwise use this
message, except for the purpose of delivery to the addressee. 
 
Any views or opinions expressed within this e-mail are those of the
author and do not necessarily represent those of Coventry University.
___
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