HI,
now next step is to add an annotation using velocity template.
I did an addannotation.vm template (view attached files).
I'had like to do a form like in commentsinline.vm.
But i have a problem: $doc.getURL("commentadd") How does it work? I
can't find the URLFactory.java file.
I had like to do $doc.getURL("annotationadd") that would add my
annotation and, like than for comments, would return to the active doc.
Thank you for your help.
Ludovic Dubost a écrit :
You plugin can create the class at initialization time.. Check the
CalendarPlugin in the XWiki source
https://svn.xwiki.org/svnroot/xwiki/xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/calendar/CalendarPlugin.java
Ludovic
antoine SEILLES wrote:
Ok
that's what i thought: i can't do without the XWiki class editor.
So if i want to add my plugin to another XWiki installation, i'll have
to create an AnnotationClass through the class editor.
Thank you.
Ludovic Dubost a écrit :
AnnotationClass should be a wiki page describing your class..
Check the tutorial for FAQClass as an example
http://www.xwiki.org/xwiki/bin/view/DevGuide/FAQTutorial
Once you have a working XWiki Class storing data in your wiki, you can
work on your plugin to create such objects programmatically.
Ludovic
antoine SEILLES wrote:
Hi,
Thank for your help.
So i have changed my class Annotation into AnnotationClass (and i
changed debut into begin and fin into end).
But what does AnnotationClasses represents? Should it be the name of my
package?
In AnnotationPlugin i have a method getName:
public String getName() {
return "annotation";
}
What should it return instead of "annotation"?
Ludovic Dubost a écrit :
Hi,
Indeed you are lacking an AnnotationClass here
You should use
AnnotationClasses.AnnotationClass
-> begin
-> end
-> selection
-> author
-> date
Then you should make sure you persist your annotation using this object..
Once you have that you would get them by doing
$doc.getObject("AnnotationClasses.AnnotationClass")
or better
$doc.use("AnnotationClasses.AnnotationClass")
$doc.getValue("begin")
Ludovic
antoine SEILLES wrote:
Now my objects are persistents. But i don't know how to access their
properties.
Should i create an annotation class through the XWiki class editor?
It seems that in my database, none of the properties of my annotations
are stored.
I define an annotation for a document:
$xwiki.annotation.addNewAnnotation($doc,"blablablaAnnotation",0,10,"blablaSelection","auteur")
I retrieve all annotations of a document:
#set($annots=$doc.getObjects("annotation"))
And i try to get the selection field of my annotations:
#foreach($annot in $annots)
"$annot.get("selection")"
#end
But all i have is "".
What should i do?
------------------------------------------------------------------------
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs
--
Antoine SEILLES
Doctorant (phd student)
Pikko software
Cap Omega - Rond Point Benjamin Franklin
CS 39521
34960 Montpellier Cedex 2
FRANCE
LIRMM CNRS
UMR 5506 - 161 rue Ada
34392 Montpellier Cedex 5
FRANCE
Tel: +33 (0)6 10 192 055
http://www.pikko-software.com
http://www.lirmm.fr
#if($xwiki.hasAccessLevel("comment"))
#set($cclass = $xwiki.getDocument("XWiki.AnnotationClass").getxWikiClass())
#set($comment = $cclass.newObject())
<form action="$doc.getURL("annotationadd")" method="post">
<fieldset class="expanded" id="commentform">
<legend onclick="toggleForm(this.form)">$msg.get("addcomment")<span
class="expands">...</span></legend>
<input type="hidden" name="xredirect" value="${doc.getURL("view")}" />
<input type="hidden" name="XWiki.AnnotationClass_author"
value="$context.user"/>
<input type="hidden" name="XWiki.AnnotationClass_begin"
value="0"/>
<input type="hidden" name="XWiki.AnnotationClass_end"
value="10"/>
<input type="hidden" name="XWiki.AnnotationClass_selection"
value="blablabla pour le moment"/>
<div><textarea id='XWiki.XWikiComments_comment' rows='5' cols="80"
name='XWiki.Annotation_comment' style="width: 100%;"></textarea></div>
<div>
<span class="buttonwrapper"><input type="submit"
value="$msg.get("addannotation")" class="button"/></span>
<span class="buttonwrapper"><input type="reset"
value="$msg.get("cancel")" onclick="hideForm(this.form);"
class="button"/></span>
</div>
</fieldset>
</form>
#end
</div> ## comments
</div> ## commentscontentpackage com.xpn.xwiki.plugin.annotation;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.objects.BaseObject;
import java.util.HashMap;
import java.util.Map;
import java.lang.Integer;
import java.util.Date;
public class AnnotationClass
{
private String id;
private String pageId;
private String title;
private String content;
private String url;
private Date created;
private String creator;
private int begin;
private int end;
private String selection;
public AnnotationClass(XWikiDocument doc, XWikiContext context, String comment, int begin, int end, String selection, Date date, String author){
BaseObject obj= new BaseObject();
setId(doc.getFullName() + ":" + obj.getNumber());
setPageId(doc.getFullName());
setTitle(doc.getName());
setContent(comment);
setCreated(date);
setCreator(author);
setUrl(doc.getURL("view", context));
setBegin(begin);
setEnd(end);
setSelection(selection);
}
public AnnotationClass(XWikiDocument doc, BaseObject obj, XWikiContext context)
{
setId(doc.getFullName() + ":" + obj.getNumber());
setPageId(doc.getFullName());
setTitle(doc.getName());
setContent(obj.getStringValue("comment"));
setCreated(obj.getDateValue("date"));
setCreator(obj.getStringValue("author"));
setUrl(doc.getURL("view", context));
setBegin(obj.getIntValue("begin"));
setEnd(obj.getIntValue("end"));
setSelection(obj.getStringValue("selection"));
}
public AnnotationClass(Map parameters)
{
setId((String)parameters.get("id"));
setPageId((String)parameters.get("pageId"));
setTitle((String)parameters.get("title"));
setContent((String)parameters.get("content"));
setUrl((String)parameters.get("url"));
setCreated((Date)parameters.get("created"));
setCreator((String)parameters.get("creator"));
setBegin(((Integer)parameters.get("begin")).intValue());
setEnd(((Integer)parameters.get("end")).intValue());
setSelection((String)parameters.get("selection"));
}
public Map getParameters()
{
Map params = new HashMap();
params.put("id", getId());
params.put("pageId", getPageId());
params.put("title", getTitle());
params.put("content", getContent());
params.put("url", getUrl());
params.put("created", getCreated());
params.put("creator", getCreator());
params.put("begin", new Integer(getBegin()));
params.put("end", new Integer(getEnd()));
params.put("selection", getSelection());
return params;
}
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public String getPageId()
{
return pageId;
}
public void setPageId(String pageId)
{
this.pageId = pageId;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title = title;
}
public String getContent()
{
return content;
}
public void setContent(String content)
{
this.content = content;
}
public String getUrl()
{
return url;
}
public void setUrl(String url)
{
this.url = url;
}
public Date getCreated()
{
return created;
}
public void setCreated(Date created)
{
this.created = created;
}
public String getCreator()
{
return creator;
}
public void setCreator(String creator)
{
this.creator = creator;
}
public int getBegin()
{
return begin;
}
public void setBegin(int begin)
{
this.begin = begin;
}
public int getEnd()
{
return end;
}
public void setEnd(int end)
{
this.end = end;
}
public String getSelection()
{
return selection;
}
public void setSelection(String selection)
{
this.selection = selection;
}
}
package com.xpn.xwiki.plugin.annotation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.api.Api;
import com.xpn.xwiki.plugin.XWikiDefaultPlugin;
import com.xpn.xwiki.plugin.XWikiPluginInterface;
import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.objects.classes.BaseClass;
public class AnnotationPlugin extends XWikiDefaultPlugin {
public AnnotationPlugin(String name, String className, XWikiContext context) {
super(name,className,context);
}
public String getName() {
return "annotation";
}
public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context) {
return new AnnotationPluginApi((AnnotationPlugin) plugin, context);
}
public void init(XWikiContext context) {
try {
getAnnotationClass(context);
} catch (Exception e) {
e.printStackTrace();
}
}
protected BaseClass getAnnotationClass(XWikiContext context) throws XWikiException {
XWikiDocument doc;
XWiki xwiki = context.getWiki();
boolean needsUpdate = false;
try {
doc = xwiki.getDocument("XWiki.AnnotationClass", context);
} catch (Exception e) {
doc = new XWikiDocument();
doc.setSpace("XWiki");
doc.setName("AnnotationClass");
needsUpdate = true;
}
BaseClass bclass = doc.getxWikiClass();
bclass.setName("XWiki.AnnotationClass");
needsUpdate |= bclass.addTextField("author", "Author", 30);
needsUpdate |= bclass.addDateField("created", "Created", "dd/MM/yyyy");
needsUpdate |= bclass.addTextAreaField("comment", "Comment", 40, 5);
needsUpdate |= bclass.addTextAreaField("selection", "Selection", 40, 5);
needsUpdate |= bclass.addNumberField("begin", "Begin", 100, "integer");
needsUpdate |= bclass.addNumberField("end", "End", 100, "integer");
String content = doc.getContent();
if ((content == null) || (content.equals(""))) {
needsUpdate = true;
doc.setContent("1 AnnotationClass");
}
if (needsUpdate)
xwiki.saveDocument(doc, context);
return bclass;
}
}package com.xpn.xwiki.plugin.annotation;
import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.api.Document;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.web.ObjectAddForm;
import com.xpn.xwiki.api.Api;
import com.xpn.xwiki.objects.BaseObject;
import java.util.Vector;
import java.util.Date;
import java.lang.Integer;
public class AnnotationPluginApi extends Api {
private AnnotationPlugin plugin;
/**
* Constructor inherits from super class Api.
*/
public AnnotationPluginApi(AnnotationPlugin plugin, XWikiContext context) {
super(context);
setPlugin(plugin);
}
/**
* Accessor get of plugin attribute.
*/
public AnnotationPlugin getPlugin(){
return (hasProgrammingRights() ? plugin : null);
// Uncomment for allowing unrestricted access to the plugin
// return plugin;
}
/**
* Accessor set of plugin attribute.
*/
public void setPlugin(AnnotationPlugin plugin) {
this.plugin = plugin;
}
/**
* Hello world method to test the class.
*/
public String hello() {
return "Annotation says: Hello World!";
}
/**
* To get all the annotations of a document.
* @param doc the document you want to get the annotations
* @return a vector that contains all the annotations
*/
public Vector getAnnotations(Document doc){
return doc.getObjects("AnnotationClass");
}
/**
* To add an annotation to a document
* @param doc the document
* @param annotation the annotation
*/
public void addAnnotation(Document doc, AnnotationClass annotation) throws XWikiException{
BaseObject obj=doc.getDocument().newObject("AnnotationClass",this.getXWikiContext());
obj.set("id", annotation.getId(),this.getXWikiContext());
obj.set("pageId", annotation.getPageId(),this.getXWikiContext());
obj.set("title", annotation.getTitle(),this.getXWikiContext());
obj.set("comment", annotation.getContent(),this.getXWikiContext());
obj.set("url", annotation.getUrl(),this.getXWikiContext());
obj.set("created", annotation.getCreated(),this.getXWikiContext());
obj.set("author", annotation.getCreator(),this.getXWikiContext());
obj.set("begin", new Integer(annotation.getBegin()),this.getXWikiContext());
obj.set("end", new Integer(annotation.getEnd()),this.getXWikiContext());
obj.set("selection", annotation.getSelection(),this.getXWikiContext());
doc.save();
}
/**
* To add an annotation to a document but giving not the annotation but the parameters of the annotation.
* This method creates the annotation and call addAnnotation(Document doc,Annotation annotation)
* @param doc the document
* @param comment the comment of the annotation
* @param begin an int to store the begining of the selection
* @param end an int to store the end of the selection
* @param selection the selected part of the document
* @param date the date of creation of the annotation
* @param author the author of the annotation
*/
public void addAnnotation(Document doc, String comment, int begin, int end, String selection, Date date, String author)throws XWikiException {
addAnnotation(doc, new AnnotationClass(doc.getDocument(), this.getXWikiContext(), comment, begin, end, selection, date, author));
}
/**
* To add an annotation to a document but giving not the annotation but the parameters of the annotation except the date wich is here deended by the System.currentTimeMillis() method.
* This method creates the annotation and call addAnnotation(Document doc,Annotation annotation)
* @param doc the document
* @param comment the comment of the annotation
* @param begin an int to store the begining of the selection
* @param end an int to store the end of the selection
* @param selection the selected part of the document
* @param author the author of the annotation
*/
public void addNewAnnotation(Document doc, String comment, int begin, int end, String selection, String author) throws XWikiException{
addAnnotation(doc,comment,begin,end,selection, new Date(System.currentTimeMillis()), author);
}
}_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs