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?

--

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.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("annotation");
    }
    /**
     * To add an annotation to a document
     * @param doc the document 
     * @param annotation the annotation 
     */
    public void addAnnotation(Document doc, Annotation annotation) throws XWikiException{
    	BaseObject obj=doc.getDocument().newObject("annotation",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("content", annotation.getContent(),this.getXWikiContext());
    	obj.set("url", annotation.getUrl(),this.getXWikiContext());
    	obj.set("created", annotation.getCreated(),this.getXWikiContext());
    	obj.set("creator", annotation.getCreator(),this.getXWikiContext());
    	obj.set("debut", new Integer(annotation.getDebut()),this.getXWikiContext());
    	obj.set("fin", new Integer(annotation.getFin()),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 debut an int to store the begining of the selection
     * @param fin 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 debut, int fin, String selection, Date date, String author)throws XWikiException {
    	addAnnotation(doc, new Annotation(doc.getDocument(), this.getXWikiContext(), comment, debut, fin, 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 defined 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 debut an int to store the begining of the selection
    * @param fin 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 debut, int fin, String selection, String author) throws XWikiException{
   		addAnnotation(doc,comment,debut,fin,selection, new Date(System.currentTimeMillis()), author);
   }
   
}
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to