Hi,

On May 15, 2009, at 4:56 PM, lpereira (SVN) wrote:

> Author: lpereira
> Date: 2009-05-15 16:56:51 +0200 (Fri, 15 May 2009)
> New Revision: 20004
>
> Modified:
>   sandbox/xwiki-plugin-annotation/src/main/java/com/xpn/xwiki/plugin/ 
> annotation/AnnotationPlugin.java
> Log:
> Quick fix concerning annotation on generated content.
>
> Modified: sandbox/xwiki-plugin-annotation/src/main/java/com/xpn/ 
> xwiki/plugin/annotation/AnnotationPlugin.java
> ===================================================================
> --- sandbox/xwiki-plugin-annotation/src/main/java/com/xpn/xwiki/ 
> plugin/annotation/AnnotationPlugin.java       2009-05-15 14:38:30 UTC (rev  
> 20003)
> +++ sandbox/xwiki-plugin-annotation/src/main/java/com/xpn/xwiki/ 
> plugin/annotation/AnnotationPlugin.java       2009-05-15 14:56:51 UTC (rev  
> 20004)
> @@ -26,6 +26,14 @@
>
> // TODO support for non logged / programming right users (plugin ?=>  
> component)
> // TODO JavaDoc
> +// TODO FIX
> +/*
> + * java.lang.StringIndexOutOfBoundsException: String index out of  
> range: -15
> +     at java.lang.String.substring(String.java:1938)
> +     at  
> com 
> .xpn 
> .xwiki 
> .plugin 
> .annotation.AnnotationPlugin.getAnnotatedHTML(AnnotationPlugin.java: 
> 180)
> +     at  
> com 
> .xpn 
> .xwiki 
> .plugin 
> .annotation 
> .api.AnnotationPluginApi.getAnnotatedHTML(AnnotationPluginApi.java:78)
> +     at  
> com 
> .xpn 
> .xwiki 
> .rest.annotation.AnnotationService.doGet(AnnotationService.java:76)
> + */
> public class AnnotationPlugin extends XWikiDefaultPlugin
> {
>     public static final String NAME = "annotation";
> @@ -175,12 +183,25 @@
>                               {
>                                       continue;
>                               }
> +                             
> +                             /*
> +                              * #if($hasEdit) You can use the [Sandbox  
> space>Sandbox.WebHome] to try out your wiki's features. #end
> +                              *
> +                              * an annotation of this cause a crash at this 
> point.
> +                              *
> +                              * TODO FIX
> +                              */
>                               fromIndex =  
> htmlContent.indexOf(getAnnotationBeginTag(it.getNumber()));
>                       toIndex =  
> htmlContent.indexOf(getAnnotationEndTag(it.getNumber()));
> +                     // QUICK FIX
> +                     if(fromIndex < 0 || toIndex < 0)
> +                     {
> +                             continue;
> +                     }
>                       oldSelection = htmlContent.substring(fromIndex+ 
> (getAnnotationBeginTag(it.getNumber()).length()), toIndex);
>                       
> -                     newSelection = 
> oldSelection.replaceAll("<(/)?([^>]+?)>",  
> "</span><$1$2><span id=\"ano"+it.getNumber()+"\" style=\"background- 
> color: green;\">");
> -                     htmlContent =  
> htmlContent.replace(htmlContent.subSequence(fromIndex, toIndex 
> +getAnnotationEndTag(it.getNumber()).length()), "<span id= 
> \"ano"+it.getNumber()+"\" style=\"background-color: green; 
> \">"+newSelection+"</span>");
> +                     newSelection = 
> oldSelection.replaceAll("<(/)?([^>]+?)>",  
> "</span><$1$2><span id=\"ano"+it.getNumber()+"\" style=\"background- 
> color: green;\" title=\""+it.get("annotation")+"\">");
> +                     htmlContent =  
> htmlContent.replace(htmlContent.subSequence(fromIndex, toIndex 
> +getAnnotationEndTag(it.getNumber()).length()), "<span id= 
> \"ano"+it.getNumber()+"\" style=\"background-color: green;\" title= 
> \""+it.get("annotation")+"\">"+newSelection+"</span>");

Regex and HTML mixed... this is scary! Could you explain quickly the  
architecture/design for this annotation feature?

On http://dev.xwiki.org/xwiki/bin/view/Design/AnnotationFeature it  
lists several options. Has one bee chosen? How does it work? What's  
the relationship with the Rendering?

Thanks
-Vincent

_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to