ladar wrote:
Hello, I'm trying to make some kind of convertor plugin from XWiki syntax to DokuWiki syntax. I want to have a button on page and after pushing it I want to create new attachment to this page with content of the page in dokuwiki syntax.
So I have something like this in my plugin Api:
XWikiDocument doc = context.getDoc(); String text = doc.getContent(); XWikiAttachment att = doc.getAttachment("DokuWiki.txt"); if (att!=null) { att.incrementVersion();
}else{ att = new XWikiAttachment(doc, "DokuWiki.txt"); } ... att.setContent(aa.getBytes());
The problem is here:
doc.getAttachmentList().add(att);
You should call this method inside the "else" branch above, as "add" adds a new attachment, that's why you see two different attachments.
context.getWiki().saveDocument(doc, context);
The page source is just:
#if($request.con) "$xwiki.convertor.convert()" #end
Now I can push the convert button on the page. When I push it for the first time, everthing fine (I see the new attachment called Dokuwiki.txt, version for example 1.1), but when I push it for the second time, in the attachments there are 2 same files called DokuWiki.txt with the same version 1.2. After pushing the button for the third time, there are 3 files with same version 1.3... After restarting server, there is only one file, the latest one... Could you please help me what is wrong in my code?
-- Sergiu Dumitriu http://purl.org/net/sergiu/