All these considerations are interesting.
I agree we should think a bit more about capabilities of the plugin but
i'had like to do a demo of what it could look like on wednesday 12
december.
Timing is short.
Well, i have new difficulties every day.
I don't understand why but i have difficulties to include javascript.
When i do
<script language="javascript" type="text/javascript">
alert("toto");</script> no pbs.
but when i do:
<script language="javascript" type="text/javascript"
src="getSelection.js"></script>
<script language="javascript" type="text/javascript">
getSelection();</script>
with getSelection.js :
function getSelection(){
alert("toto");
}
I have an error in my console: getSelection is not define.
Another point is, how to get the values of a form in velocity?
I have an addannotation.vm :
#if($xwiki.hasAccessLevel("comment"))
#set($cclass = $xwiki.getDocument("XWiki.AnnotationClass").getxWikiClass())
#set($annotation = $cclass.newObject())
<form action="XXXXXXXXX" method="post" id="myForm">
<fieldset class="expanded" id="commentform">
<legend
onclick="toggleForm(this.form)">$msg.get("addannotationcomment")<span
class="expands">...</span></legend>
<input type="hidden" name="xredirect"
value="${doc.getURL("view")}" />
<input type="hidden" name="AnnotationClass_author"
value="$context.user"/>
<input type="hidden" name="AnnotationClass_begin" value=0/>
<input type="hidden" name="AnnotationClass_end" value=0/>
<input type="hidden" name="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> ## commentscontent
I'd like to have a link to a page in "<form action=" that would print
"your annotation has been added" and that would call my function
$xwiki.annotation.addNewAnnotation($doc, $AnnotationClass_selection,
$AnnotationClass_begin, $AnnotationClass_end,
$AnnotationClass_selection, $AnnotationClass_author)
(where $AnnotationClass_begin is the value of AnnotationClass_begin field).
Stéphane Laurière a écrit :
If you want to code the annotation feature exactly as the comment
feature, you need to have to look at the "commentadd" action in
"WEB-INF/struts-config.xml" and at the related classes like
"CommentAddAction" and the places where they show up, like
XWikiRightServiceImpl.java, and then to introduce the same elements for
the Annotation classes.
That's not necessarily the simplest thing to do, though. Another option
is to use Groovy or Velocity scripts directly in wiki pages for
introducing the annotation feature. For example, for the help desk we're
developing, the answers to questions asked are added as XWiki objects
through Groovy scripts, even though the feature is similar to the
XWikiComment feature as well. The main advantage I see in using scripts
in wiki pages instead of external templates is that it's then easier to
evolve those scripts collaboratively. You can see the way it's coded
from [1], and the add "?viewer=code" at the end of the URLs for
viewing the code.
I agrre, it's a bit hard for a xwiki beginner.
[1] http://club.mandriva.com/xwiki/bin/view/ITS/
Introducing annotation capabilities to XWiki is very relevant in various
contexts. I would say we should think about the capabilities of the
plugin a bit more before developing it.
Here are some considerations:
1) do we want to have the possibility to annotate annotations? And also
to tag annotations? If yes, having each annotation in a separate
document would probably be a better design. Personally, I think that'd
be a good feature to support tagging for annotations, letting users
describe some annotations as "critique" for instance, or rating some
annotations through the rating plugin when one will be available.
We want to have the possibility to tag and annotate annotations. But we
want to have the possiblility to list for a doc all the annotations
linked to.
2) what about rights? That may be handy to have various access rights
for annotations? Imagine a teacher and her students annotating a
document. The teacher may wish to keep her annotation private while the
students collaboratively annotate the same piece of document...
OK
3) choosing a name would help packaging the plugin into a unique Space
(not sure about the guidelines we chose there eventually, but having all
the wiki pages for a given feature in a single space increases
lisibility, I think)
I'm not sure to understand.
I have named my plugin: annotation.
And i want to be able to annotate any docs in any space.
4) how will we manage annotations on evolving documents? If the
structure remains the same, that may be ok, but what will happen when a
user moves an entire paragraph to a different position? Do you know if
there has been some work on this?
Arf. I don't know.
In this case, to localise annotation using tag should be better than
using references.
I propose we use the following page for refining the design of the
feature: http://www.xwiki.org/xwiki/bin/view/Design/AnnotationFeature
Great idea but i can't edit the page.
That may be easier to give input to the plugin development once we'll
have a common view on what we aim at.
Of course.
Note that annotation capabilities also share some aspects with the PSEW
prototype, that allows for external annotations of wiki pages (external
in the sense that annotations are then stored in a completely distinct
database):
http://nepomuk-eclipse.semanticdesktop.org/xwiki/bin/view/Main/PSEW
Cheers
Stéphane
Thank you.
And thank for your help.
PS: my plugin and templates are attached. addannotation.vm doesn't work
cause of the form action.
--
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 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();
}
}
public 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);
}
}#if($xwiki.hasAccessLevel("comment"))
#set($cclass = $xwiki.getDocument("XWiki.AnnotationClass").getxWikiClass())
#set($annotation = $cclass.newObject())
<form action=$xwiki.annotation.addNewAnnotation($doc,
$AnnotationClass_selection, $AnnotationClass_begin, $AnnotationClass_end,
$AnnotationClass_selection, $AnnotationClass_author) method="post" id="myForm">
<fieldset class="expanded" id="commentform">
<legend
onclick="toggleForm(this.form)">$msg.get("addannotationcomment")<span
class="expands">...</span></legend>
<input type="hidden" name="xredirect"
value="${doc.getURL("view")}" />
<input type="hidden" name="AnnotationClass_author"
value="$context.user"/>
<input type="hidden" name="AnnotationClass_begin" value=0/>
<input type="hidden" name="AnnotationClass_end" value=0/>
<input type="hidden" name="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> ## commentscontent
###
### 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 = $doc.display("created","view",$annotation))
#if($date)
| <span class="annotationdate">$date</span>
#end
#if($hasedit) <span class="annotationdelete"><a class="annotationremove"
href="$doc.getURL("objectremove" ,
"classname=XWiki.AnnotationClass&classid=${annotation.number}&xredirect=${request.getRequestURL()}")"
onclick="return
confirm('$msg.get("confirmannotationremove")')">[$msg.get("removethisannotation")]</a></span>#end
</div>
<div class="annotationcontent"><b>$msg.get("annotationselection") :</b>
$doc.getRenderedContent($doc.display("selection","view",$annotation)) <br>
<b>$msg.get("annotationcommentaire") :</b>
$doc.getRenderedContent($doc.display("comment","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