org.xwiki.annotation.internal.renderer
Class AnnotationMarkersXHTMLPrinter

java.lang.Object
  extended by org.xwiki.rendering.renderer.printer.XMLWikiPrinter
      extended by org.xwiki.rendering.renderer.printer.XHTMLWikiPrinter
          extended by org.xwiki.annotation.internal.renderer.AnnotationMarkersXHTMLPrinter

public class AnnotationMarkersXHTMLPrinter
extends XHTMLWikiPrinter

XHTML Printer to handle printing annotations markers in the rendered XHTML. It is able to generate the annotation start marker and end marker and to store information about the annotations state: which ones are being currently rendered, which markers are opened, etc. To be used by the XHTML renderers to render annotations on the XHTML.
Note that, although this class could aggregate a XHTMLWikiPrinter, and be used to wrap the default XHTMLWikiPrinter in a XHTML Renderer, it extends it so that it can replace. TODO: in a future improved implementation, this could handle annotations rendering alone, just using state information from the renderer.

Since:
2.3M1

Field Summary
 
Fields inherited from class org.xwiki.rendering.renderer.printer.XMLWikiPrinter
wikiWriter, xmlWriter
 
Constructor Summary
AnnotationMarkersXHTMLPrinter(WikiPrinter printer)
          Builds an XHTML markers annotations printer which uses the underlying wiki printer.
 
Method Summary
 void beginAnnotation(Annotation annotation)
          Handles the beginning of a new annotation.
 void closeAllAnnotationMarkers()
          Helper function to handle closing all annotations.
 void endAnnotation(Annotation annotation)
          Handles the end of an annotation.
 void openAllAnnotationMarkers()
          Helper function to handle opening all annotations.
 void printXMLWithAnnotations(String text, SortedMap<Integer,List<AnnotationEvent>> annotations)
          Helper function to help render a piece of text with annotation events inside it, at the specified offsets.
 
Methods inherited from class org.xwiki.rendering.renderer.printer.XHTMLWikiPrinter
printRaw, printSpace, printXML, printXMLComment, printXMLComment, printXMLElement, printXMLElement, printXMLElement, printXMLEndCData, printXMLEndElement, printXMLStartCData, printXMLStartElement, printXMLStartElement, printXMLStartElement, printXMLStartElement
 
Methods inherited from class org.xwiki.rendering.renderer.printer.XMLWikiPrinter
getXMLWriter, printEntity, setWikiPrinter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationMarkersXHTMLPrinter

public AnnotationMarkersXHTMLPrinter(WikiPrinter printer)
Builds an XHTML markers annotations printer which uses the underlying wiki printer.

Parameters:
printer - the wiki printer used by this XHTML printer
Method Detail

beginAnnotation

public void beginAnnotation(Annotation annotation)
Handles the beginning of a new annotation.

Parameters:
annotation - the annotation that begins

endAnnotation

public void endAnnotation(Annotation annotation)
Handles the end of an annotation.

Parameters:
annotation - the annotation that ends

closeAllAnnotationMarkers

public void closeAllAnnotationMarkers()
Helper function to handle closing all annotations. To be called either when elements close or when an element opens (all annotation spans will only wrap text, not inner elements). It will close all opened annotations markers and set the flag to specify that annotations are closed and they should be opened at next text element.


openAllAnnotationMarkers

public void openAllAnnotationMarkers()
Helper function to handle opening all annotations. If the annotations are not already opened, it should open them all and set the flag to opened so that next text event doesn't do the same.


printXMLWithAnnotations

public void printXMLWithAnnotations(String text,
                                    SortedMap<Integer,List<AnnotationEvent>> annotations)
Helper function to help render a piece of text with annotation events inside it, at the specified offsets. To be used for the events which generate text and need to generate annotation markers inside them.

Parameters:
text - the text to render
annotations - the map of indexes and annotation events to render in this text