Well, my annotation plugin is in progress.

I join my new version.
Now i can add annotation to doc but this is not permanent. :'(

I have another problem, i did annotations.vm and annotationsinline.vm templates to list annotations of a document. Well, i don't understand how to acces attributes of my annotations to display them.

If someone can help, please.



antoine SEILLES a écrit :
Hi
i'm doing an annotation plugin and i need some help.

An annotation is a comment linked to a document (like a XWikiComment).
More precisely, an annotation is linked to a selected part of a document.

My objective is to get something like in attached picture (.jpg).

I have created three classes for my plugin (view attached pieces) inspired of helloworldplugin and XWikiComment class.

What i need is:
*  to create an annotation.
*  to add an annotation to a document
*  to modify an annotation
*  to delete an annotation
*  to list annotations linked to a document

If someone had some advices.
Thank


------------------------------------------------------------------------



--

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


package 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 Annotation
{
    private String id;

    private String pageId;

    private String title;

    private String content;

    private String url;

    private Date created;

    private String creator;
    
    private int debut;
    
    private int fin;
    
    private String selection;
    
    public Annotation(XWikiDocument doc, XWikiContext context, String comment, int debut, int fin, 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));
        setDebut(debut);
        setFin(fin);
        setSelection(selection);
    }

    public Annotation(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));
        setDebut(obj.getIntValue("debut"));
        setFin(obj.getIntValue("fin"));
        setSelection(obj.getStringValue("selection"));
        
    }

    public Annotation(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"));
    	setDebut(((Integer)parameters.get("debut")).intValue());
        setFin(((Integer)parameters.get("fin")).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("debut", new Integer(getDebut()));
        params.put("fin", new Integer(getFin()));
        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 getDebut()
    {
        return debut;
    }

    public void setDebut(int debut)
    {
        this.debut = debut;
    }
    
    public int getFin()
    {
        return fin;
    }

    public void setFin(int fin)
    {
        this.fin = fin;
    }
    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;

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) {
		   super.init(context);
		}
	
}
package com.xpn.xwiki.plugin.annotation;

import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.api.Document;
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;

    public AnnotationPluginApi(AnnotationPlugin plugin, XWikiContext context) {
        super(context);
        setPlugin(plugin);
    }

    public AnnotationPlugin getPlugin(){
        return (hasProgrammingRights() ? plugin : null);
        // Uncomment for allowing unrestricted access to the plugin
        // return plugin;
    }

    public void setPlugin(AnnotationPlugin plugin) {
        this.plugin = plugin;
    }

    public String hello() {
        return "Annotation says: Hello World!";
    }

    public Vector getAnnotations(Document doc){
    	return doc.getObjects("annotation");
    }
    
    public void addAnnotation(Document doc, Annotation annotation){
    	BaseObject annotationObject=new BaseObject();
    	annotationObject.set("id", annotation.getId(), this.getXWikiContext());
    	annotationObject.set("pageId", annotation.getPageId(), this.getXWikiContext());
    	annotationObject.set("title", annotation.getTitle(), this.getXWikiContext());
    	annotationObject.set("content", annotation.getContent(), this.getXWikiContext());
    	annotationObject.set("url", annotation.getUrl(), this.getXWikiContext());
    	annotationObject.set("created", annotation.getCreated(), this.getXWikiContext());
    	annotationObject.set("creator", annotation.getCreator(), this.getXWikiContext());
    	annotationObject.set("debut", new Integer(annotation.getDebut()), this.getXWikiContext());
    	annotationObject.set("fin", new Integer(annotation.getFin()), this.getXWikiContext());
    	annotationObject.set("selection", annotation.getSelection(), this.getXWikiContext());
    	doc.getDocument().addObject("annotation",annotationObject);
    }
    
   public void addAnnotation(Document doc, String comment, int debut, int fin, String selection, Date date, String author){
    	addAnnotation(doc, new Annotation(doc.getDocument(), this.getXWikiContext(), comment, debut, fin, selection, date, author));
    }
   
   public void addNewAnnotation(Document doc, String comment, int debut, int fin, String selection, String author){
   		addAnnotation(doc,comment,debut,fin,selection, new Date(System.currentTimeMillis()), author);
   }
   
   public String getComment(Annotation annotation){
   		return annotation.getContent();
   }
   
   public String getAuthor(Annotation annotation){
   		return annotation.getCreator();
   }
   
   public Date getCreationDate(Annotation annotation){
   		return annotation.getCreated();
   }
   
   public int getDebut(Annotation annotation){
   		return annotation.getDebut();
   }
   
   public int getFin(Annotation annotation){
		return annotation.getFin();
   }
   
   public String getSelection(Annotation annotation){
		return annotation.getSelection();
   }
   
   public String getTitle(Annotation annotation){
		return annotation.getTitle();
   }
   
   public String getId(Annotation annotation){
	return annotation.getId();
   }
   
   public String getPageId(Annotation annotation){
	return annotation.getPageId();
   }
   
   public String getUrl(Annotation annotation){
	return annotation.getUrl();
   }
   
}
###
### Annotations page in the "view" mode
###
###
<h2>$xwiki.parseMessage("viewannotationstitle")</h2>
#template("annotationsinline.vm")
###
### List document annotations
###
### TODO: web service?
###
#if($xwiki.getWebPreferenceAsInt("commentsorder",1)==1)
#set($annotations = $xwiki.annotation.getAnnotations($doc))
#end
  <div id="annotationscontent" class="xwikiintracontent">
#if($inline && ($inline == true))    <div class="xwikititlewrapper" 
onclick="toggleClass($('annotations'), 'hidden'); 
toggleClass($('annotationscontent'), 'exp')"><h3 
class="xwikiintratitle">$msg.get("annotations")<span class="hidden">:</span> 
<span 
class="annotationsno"><span>$annotations.size()</span></span></h3></div>#end
    <div id="annotations">
#if($annotations.size()>0)
#foreach($annotation in $annotations)
#if($velocityCount > 1)    <hr class="annotationspacer"/>
#end
    <div id="xwikiannotation_${velocityCount}" class="xwikiannotation 
#if($velocityCount % 2 == 1) odd #else even #end">
##      <div class="annotationavatar">#useravatar($annotation.getAuthor())</div>
      <div class="annotationheader"><span 
class="annotationauthor">$!xwiki.getLocalUserName($doc.display('author','view', 
$annotation))</span>
## #set($date = $doc.display("date","view",$annotation))
#set($date = $xwiki.annotation.getCreationDate($annotation).value)
#if($date)
 | <span class="annotationdate">$xwiki.formatDate($date, "dd.MM.yyyy") 
$msg.get("at") $xwiki.formatDate($date, "hh:mm a")</span>
#end
#if($hasedit) <span class="annotationdelete"><a class="annotationremove" 
href="$doc.getURL("objectremove" , 
"classname=XWiki.XWikiAnnotations&amp;classid=${annotation.number}&amp;xredirect=${request.getRequestURL()}")"
    onclick="return 
confirm('$msg.get("confirmannotationremove")')">[$msg.get("removethisannotation")]</a></span>#end
      </div>
      <div 
class="annotationcontent">$doc.getRenderedContent($doc.display("content","view",$annotation))
       </div>
    </div>
#end
#else
$msg.get("noannotations")
#end
    </div> ## annotations
  </div> ## annotationscontent
#if($inline && ($inline == true))
      <script type="text/javascript">
//<!--
if(document.getElementById("annotationform")) {
  document.getElementById("annotationform").className = "collapsed";
}
document.getElementById("annotations").className += " hidden";
//-->
      </script>
#end
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to