Hi Thomas, thanks a lot for the review. On 12/04/2009 07:20 PM, Thomas Mortagne wrote:
On Fri, Dec 4, 2009 at 16:25, lucaa<[email protected]> wrote:
Author: lucaa Date: 2009-12-04 16:25:46 +0100 (Fri, 04 Dec 2009) New Revision: 25544
Added: contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/internal/content/WhiteSpaceContentAlterer.java contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/internal/content/filter/WhiteSpaceFilter.java contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/internal/renderer/ contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/internal/renderer/AnnotationGeneratorChainingListener.java contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/internal/renderer/XHTMLAnnotationChainingPrintRenderer.java contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/internal/renderer/XHTMLAnnotationRenderer.java
XHTMLAnnotationRenderer seems wrong, it's a specialized XHTML renderer so it should be the other way around: AnnotationXHTMLRenderer
contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/ contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AbstractAnnotationRenderer.java contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AnnotationChainingPrintRenderer.java contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AnnotationListener.java contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AnnotationPrintRenderer.java contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/test/java/org/xwiki/annotation/content/ contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/test/java/org/xwiki/annotation/content/WhiteSpaceContentAltererTest.java contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/test/java/org/xwiki/annotation/renderer/ contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/test/java/org/xwiki/annotation/renderer/XHTMLAnnotationRendererTest.java Modified: contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/pom.xml contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/resources/META-INF/components.txt Log: First prototype for the annotations renderer API with the default XHTML renderer.
[snip]
Added: contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/internal/renderer/XHTMLAnnotationChainingPrintRenderer.java =================================================================== --- contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/internal/renderer/XHTMLAnnotationChainingPrintRenderer.java (rev 0) +++ contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/internal/renderer/XHTMLAnnotationChainingPrintRenderer.java 2009-12-04 15:25:46 UTC (rev 25544) @@ -0,0 +1,94 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.annotation.internal.renderer; + +import java.util.LinkedHashMap; +import java.util.Map; + +import org.xwiki.annotation.Annotation; +import org.xwiki.annotation.renderer.AnnotationChainingPrintRenderer; +import org.xwiki.rendering.internal.renderer.xhtml.XHTMLChainingRenderer; +import org.xwiki.rendering.listener.chaining.ListenerChain; +import org.xwiki.rendering.renderer.xhtml.XHTMLImageRenderer; +import org.xwiki.rendering.renderer.xhtml.XHTMLLinkRenderer; + +/** + * Extends the default XHTML renderer to add handling of annotations.<br /> + * FIXME: this implementation is a very simple handling of annotation events, it should handle annotation markers + * splitting& nesting in other elements. + * + * @version $Id$ + */ +public class XHTMLAnnotationChainingPrintRenderer extends XHTMLChainingRenderer implements + AnnotationChainingPrintRenderer +{ + /** + * The annotation marker element in HTML. + */ + private static final String ANNOTATION_MARKER = "span"; + + /** + * Constructor from super class. + * + * @param linkRenderer the renderer for links + * @param imageRenderer the renderer for images + * @param listenerChain the listener chain in which to add this listener + */ + public XHTMLAnnotationChainingPrintRenderer(XHTMLLinkRenderer linkRenderer, XHTMLImageRenderer imageRenderer, + ListenerChain listenerChain) + { + super(linkRenderer, imageRenderer, listenerChain); + } + + /** + * {@inheritDoc} + * + * @see org.xwiki.annotation.renderer.AnnotationListener#beginAnnotation(Annotation) + */ + public void beginAnnotation(Annotation annotation) + { + Map<String, String> attributes = new LinkedHashMap<String, String>(); + + attributes.put("class", createAnnotationClass(annotation.getId()));
why don't you put the annotationId as an id instead of class if it's a unique id ?
It's not going to be unique. There will be multiple annotation marker spans, when the implementation will be finished, to wrap all pieces of annotated text (in different block elements, for example).
+ attributes.put("title", annotation.getAnnotation().toString());
I generally try to avoid as much as possible using Object#toString() for anything else that debugging. If Annotation officially has a title it should have a getTitle() method or something like that.
It's just a bad naming for the 'getTitle()' method, it does return the title of the annotation but it's a CharSequence (I am still to refactor all those CharSequences around this code). Thanks, Anca
+ getXHTMLWikiPrinter().printXMLStartElement(ANNOTATION_MARKER, attributes); + } + + /** + * Creates the class value of the annotation. + * + * @param annotationId the id of the annotation + * @return the class value for the passed annotation + */ + private String createAnnotationClass(int annotationId) + { + return "annotation ID" + annotationId; + } + + /** + * {@inheritDoc} + * + * @see org.xwiki.annotation.renderer.AnnotationListener#endAnnotation(Annotation) + */ + public void endAnnotation(Annotation annotation) + { + getXHTMLWikiPrinter().printXMLEndElement(ANNOTATION_MARKER); + } +}
Property changes on: contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/internal/renderer/XHTMLAnnotationChainingPrintRenderer.java ___________________________________________________________________ Name: svn:keywords + Author Id Revision HeadURL Name: svn:eol-style + native
Added: contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/internal/renderer/XHTMLAnnotationRenderer.java =================================================================== --- contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/internal/renderer/XHTMLAnnotationRenderer.java (rev 0) +++ contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/internal/renderer/XHTMLAnnotationRenderer.java 2009-12-04 15:25:46 UTC (rev 25544) @@ -0,0 +1,68 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.annotation.internal.renderer; + +import org.xwiki.annotation.renderer.AbstractAnnotationRenderer; +import org.xwiki.annotation.renderer.AnnotationChainingPrintRenderer; +import org.xwiki.component.annotation.Component; +import org.xwiki.component.annotation.InstantiationStrategy; +import org.xwiki.component.annotation.Requirement; +import org.xwiki.component.descriptor.ComponentInstantiationStrategy; +import org.xwiki.rendering.listener.chaining.ListenerChain; +import org.xwiki.rendering.renderer.xhtml.XHTMLImageRenderer; +import org.xwiki.rendering.renderer.xhtml.XHTMLLinkRenderer; + +/** + * Renders annotations in the XHTML format. + * + * @version $Id$ + */ +@Component("annotations/xhtml/1.0")
You should not use / in the syntax name since it's the syntax name/syntax version separator also AnnotatedXHTMLBlockRenderer use "annotatedxhtml/1.0" so it's not consistant
+@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP) +public class XHTMLAnnotationRenderer extends AbstractAnnotationRenderer +{ + /** + * To render link events into XHTML. This is done so that it's pluggable because link rendering depends on how the + * underlying system wants to handle it. For example for XWiki we check if the document exists, we get the document + * URL, etc. + */ + @Requirement + private XHTMLLinkRenderer linkRenderer; + + /** + * To render image events into XHTML. This is done so that it's pluggable because image rendering depends on how the + * underlying system wants to handle it. For example for XWiki we check if the image exists as a document + * attachments, we get its URL, etc. + */ + @Requirement + private XHTMLImageRenderer imageRenderer; + + /** + * {@inheritDoc} + * + * @see org.xwiki.annotation.renderer.AbstractAnnotationRenderer#getAnnotationPrintRenderer(ListenerChain) + */ + @Override + public AnnotationChainingPrintRenderer getAnnotationPrintRenderer(ListenerChain chain) + { + return new XHTMLAnnotationChainingPrintRenderer(linkRenderer, imageRenderer, chain); + } + +}
Property changes on: contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/internal/renderer/XHTMLAnnotationRenderer.java ___________________________________________________________________ Name: svn:keywords + Author Id Revision HeadURL Name: svn:eol-style + native
Added: contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AbstractAnnotationRenderer.java =================================================================== --- contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AbstractAnnotationRenderer.java (rev 0) +++ contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AbstractAnnotationRenderer.java 2009-12-04 15:25:46 UTC (rev 25544) @@ -0,0 +1,107 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.annotation.renderer; + +import java.util.Collection; + +import org.xwiki.annotation.Annotation; +import org.xwiki.annotation.content.ContentAlterer; +import org.xwiki.annotation.internal.renderer.AnnotationGeneratorChainingListener; +import org.xwiki.component.annotation.Requirement; +import org.xwiki.component.phase.Initializable; +import org.xwiki.component.phase.InitializationException; +import org.xwiki.rendering.listener.chaining.EmptyBlockChainingListener; +import org.xwiki.rendering.listener.chaining.ListenerChain; +import org.xwiki.rendering.renderer.AbstractChainingPrintRenderer; +import org.xwiki.rendering.renderer.LinkLabelGenerator; + +/** + * Abstract class for annotation renderer, any specific syntax renderer should implement this class and provide the + * specific annotation listener. + * + * @version $Id$ + */ +public abstract class AbstractAnnotationRenderer extends AbstractChainingPrintRenderer implements Initializable, + AnnotationPrintRenderer +{ + /** + * The link label generator for this renderer. + */ + @Requirement + protected LinkLabelGenerator linkLabelGenerator; + + /** + * Selection cleaner so that the selection can be mapped on the content.<br /> + * TODO: not really sure if this is the right place for this pull, but the annotations generator is not a component + * so it cannot 'require' it. + */ + @Requirement("whitespace") + protected ContentAlterer selectionAlterer; + + /** + * The annotations generator listener to use in this renderer. + */ + private AnnotationGeneratorChainingListener annotationsGenerator; + + /** + * {@inheritDoc} + * + * @see org.xwiki.component.phase.Initializable#initialize() + */ + public void initialize() throws InitializationException + { + ListenerChain chain = new ListenerChain(); + setListenerChain(chain); + + // Construct the listener chain in the right order. Listeners early in the chain are called before listeners + // placed later in the chain. + chain.addListener(this); + chain.addListener(new EmptyBlockChainingListener(chain)); + // will generate annotation events to the next listener in chain + + // TODO: could also have the annotation listener passed to the annotationgenerator chaininglistener (which would + // become a print renderer and delegate all printing functions to the aggregated annotation print renderer). + // All buffered events will be consumed to this aggregated listener. This way the next element in chain is + // better coupled in the listener that knows how to send such events and we don't need to test in the annotation + // generator that the next listener in the chain can receive annotation events. However I like the chaining idea + // more (because one could add any number of other annotation listeners after this generator in the chain). + annotationsGenerator = new AnnotationGeneratorChainingListener(linkLabelGenerator, selectionAlterer, chain); + chain.addListener(annotationsGenerator); + // the actual annotations renderer + chain.addListener(getAnnotationPrintRenderer(chain)); + } + + /** + * @param chain the chain in which the renderer needs to be added. + * @return the annotation listener to which the annotation events generated by this renderer should be sent (the + * actual renderer of annotated content) + */ + public abstract AnnotationChainingPrintRenderer getAnnotationPrintRenderer(ListenerChain chain); + + /** + * {@inheritDoc} + * + * @see org.xwiki.annotation.renderer.AnnotationPrintRenderer#setAnnotations(java.util.Collection) + */ + public void setAnnotations(Collection<Annotation> annotations) + { + this.annotationsGenerator.setAnnotations(annotations); + } +}
Property changes on: contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AbstractAnnotationRenderer.java ___________________________________________________________________ Name: svn:keywords + Author Id Revision HeadURL Name: svn:eol-style + native
Added: contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AnnotationChainingPrintRenderer.java =================================================================== --- contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AnnotationChainingPrintRenderer.java (rev 0) +++ contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AnnotationChainingPrintRenderer.java 2009-12-04 15:25:46 UTC (rev 25544) @@ -0,0 +1,34 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.annotation.renderer; + +import org.xwiki.rendering.listener.chaining.ChainingListener; +import org.xwiki.rendering.renderer.PrintRenderer; + +/** + * Define the chaining annotation print renderer. To be implemented by extending a ChainingPrintRenderer and + * implementing the functions in the {@link AnnotationListener} interface. + * + * @version $Id$ + */ +public interface AnnotationChainingPrintRenderer extends AnnotationListener, ChainingListener, PrintRenderer +{ + +}
Property changes on: contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AnnotationChainingPrintRenderer.java ___________________________________________________________________ Name: svn:keywords + Author Id Revision HeadURL Name: svn:eol-style + native
Added: contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AnnotationListener.java =================================================================== --- contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AnnotationListener.java (rev 0) +++ contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AnnotationListener.java 2009-12-04 15:25:46 UTC (rev 25544) @@ -0,0 +1,49 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.annotation.renderer; + +import org.xwiki.annotation.Annotation; +import org.xwiki.rendering.listener.Listener; + +/** + * Extends the standard XWiki events listener by adding a set of events for start and end of an annotation. + * + * @version $Id$ + */ +public interface AnnotationListener extends Listener +{ + /** + * Signals the start of an annotation. Note that this event will only be fired once, splitting the annotation + * markers in multiple pieces and correctly imbricating them in the rendered syntax (such as multiple spans across + * multiple block elements in the XHTML renderer) is the responsibility of the renderer. + * + * @param annotation the annotation whose selected text starts + */ + void beginAnnotation(Annotation annotation); + + /** + * Signals the end of an annotation. Note that this event will only be fired once, splitting the annotation markers + * in multiple pieces and correctly imbricating them in the rendered syntax (such as multiple spans across multiple + * block elements in the XHTML renderer) is the responsibility of the renderer. + * + * @param annotation the annotation whose selected text ends + */ + void endAnnotation(Annotation annotation); +}
Property changes on: contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AnnotationListener.java ___________________________________________________________________ Name: svn:keywords + Author Id Revision HeadURL Name: svn:eol-style + native
Added: contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AnnotationPrintRenderer.java =================================================================== --- contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AnnotationPrintRenderer.java (rev 0) +++ contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AnnotationPrintRenderer.java 2009-12-04 15:25:46 UTC (rev 25544) @@ -0,0 +1,42 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.annotation.renderer; + +import java.util.Collection; + +import org.xwiki.annotation.Annotation; +import org.xwiki.component.annotation.ComponentRole; +import org.xwiki.rendering.renderer.PrintRenderer; + +/** + * An annotations print renderer is a {@link PrintRenderer} that also renders annotations on the content. + * + * @version $Id$ + */ +@ComponentRole +public interface AnnotationPrintRenderer extends PrintRenderer +{ + /** + * Sets the annotations to render on the content. + * + * @param annotations the collection of annotations to render + */ + void setAnnotations(Collection<Annotation> annotations); +}
Property changes on: contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/java/org/xwiki/annotation/renderer/AnnotationPrintRenderer.java ___________________________________________________________________ Name: svn:keywords + Author Id Revision HeadURL Name: svn:eol-style + native
Modified: contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/resources/META-INF/components.txt =================================================================== --- contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/resources/META-INF/components.txt 2009-12-04 15:18:58 UTC (rev 25543) +++ contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/main/resources/META-INF/components.txt 2009-12-04 15:25:46 UTC (rev 25544) @@ -1,5 +1,8 @@ org.xwiki.annotation.internal.DefaultAnnotationService org.xwiki.annotation.internal.content.XWiki20SyntaxContentAlterer +org.xwiki.annotation.internal.content.WhiteSpaceContentAlterer org.xwiki.annotation.internal.content.filter.XWiki20SyntaxFilter +org.xwiki.annotation.internal.content.filter.WhiteSpaceFilter org.xwiki.annotation.internal.target.DefaultDocumentContentTarget -org.xwiki.annotation.internal.selection.DefaultSelectionService \ No newline at end of file +org.xwiki.annotation.internal.selection.DefaultSelectionService +org.xwiki.annotation.internal.renderer.XHTMLAnnotationRenderer \ No newline at end of file
Added: contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/test/java/org/xwiki/annotation/content/WhiteSpaceContentAltererTest.java =================================================================== --- contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/test/java/org/xwiki/annotation/content/WhiteSpaceContentAltererTest.java (rev 0) +++ contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/test/java/org/xwiki/annotation/content/WhiteSpaceContentAltererTest.java 2009-12-04 15:25:46 UTC (rev 25544) @@ -0,0 +1,105 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.annotation.content; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.Collection; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.xwiki.test.AbstractComponentTestCase; + +/** + * @version $Id$ + */ +@RunWith(Parameterized.class) +public class WhiteSpaceContentAltererTest extends AbstractComponentTestCase +{ + /** + * The initial String to alter. + */ + private String initial; + + /** + * The expected altered string. + */ + private String altered; + + /** + * The content alterer to test. + */ + private ContentAlterer alterer; + + /** + * @param initial the original string + * @param altered the altered string after being whitespace filtered + */ + public WhiteSpaceContentAltererTest(String initial, String altered) + { + this.initial = initial; + this.altered = altered; + } + + /** + * {@inheritDoc} + * + * @see org.xwiki.test.AbstractComponentTestCase#setUp() + */ + @Override + public void setUp() throws Exception + { + super.setUp(); + alterer = getComponentManager().lookup(ContentAlterer.class, "whitespace"); + } + + /** + * @return list of corpus files to instantiate tests for + */ + @Parameters + public static Collection<String[]> data() + { + Collection<String[]> params = new ArrayList<String[]>(); + // unbreakable space + params.add(new String[] {"not to be", "nottobe"}); + // tabs + params.add(new String[] {"to be or not\tto be", "tobeornottobe"}); + // commas, signs with regular spaces + params.add(new String[] {"roses, see I in her cheeks;", "roses,seeIinhercheeks;"}); + // new lines + params.add(new String[] {"eyes nothing\nlike the sun", "eyesnothinglikethesun"}); + // new line carriage return + params.add(new String[] {"eyes\n\rnothing", "eyesnothing"}); + return params; + } + + /** + * Tests that the content alterer filters correctly the characters out of the Strings. + */ + @Test + public void testFiltering() + { + AlteredContent alteredContent = alterer.alter(initial); + assertEquals(altered, alteredContent.getContent().toString()); + } +}
Property changes on: contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/test/java/org/xwiki/annotation/content/WhiteSpaceContentAltererTest.java ___________________________________________________________________ Name: svn:keywords + Author Id Revision HeadURL Name: svn:eol-style + native
Added: contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/test/java/org/xwiki/annotation/renderer/XHTMLAnnotationRendererTest.java =================================================================== --- contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/test/java/org/xwiki/annotation/renderer/XHTMLAnnotationRendererTest.java (rev 0) +++ contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/test/java/org/xwiki/annotation/renderer/XHTMLAnnotationRendererTest.java 2009-12-04 15:25:46 UTC (rev 25544) @@ -0,0 +1,166 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.annotation.renderer; + +import static org.junit.Assert.assertEquals; + +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Collection; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.xwiki.annotation.TestDocumentFactory; +import org.xwiki.rendering.block.XDOM; +import org.xwiki.rendering.parser.Parser; +import org.xwiki.rendering.renderer.printer.DefaultWikiPrinter; +import org.xwiki.rendering.renderer.printer.WikiPrinter; +import org.xwiki.rendering.syntax.Syntax; +import org.xwiki.rendering.transformation.TransformationManager; +import org.xwiki.test.AbstractComponentTestCase; + +/** + * Renderer tests for the XHTML annotations renderer, from the test files. + * + * @version $Id$ + */ +@RunWith(Parameterized.class) +public class XHTMLAnnotationRendererTest extends AbstractComponentTestCase +{ + /** + * Document description files to run this test for. + */ + private static Collection<String[]> files = new ArrayList<String[]>(); + + /** + * The annotations renderer hint. + */ + private static final String ANNOTATIONS_RENDERER_HINT = "annotations/xhtml/1.0"; + + /** + * Mock document to run tests for. + */ + protected String docName; + + static { + // FIXME: checkstyle is so gonna shout when this will be longer than 30 files + addFileToTest("Document1"); + addFileToTest("Document2"); + addFileToTest("Document3"); + addFileToTest("Document4"); + addFileToTest("Document5"); + addFileToTest("Document6"); + addFileToTest("Document7"); + addFileToTest("Document8"); + addFileToTest("Document9"); + addFileToTest("Document10"); + addFileToTest("Document11"); + addFileToTest("Document12"); + addFileToTest("Document13"); + addFileToTest("Document14"); + addFileToTest("Document15"); + addFileToTest("Document16"); + addFileToTest("Document17"); + addFileToTest("Document18"); + } + + /** + * Creates a test for the passed document. Will be instantiated by the parameterized runner for all the parameters. + * + * @param docName the document (and corpus filename) to run tests for + */ + public XHTMLAnnotationRendererTest(String docName) + { + this.docName = docName; + } + + /** + * Adds a file to the list of files to run tests for. + * + * @param docName the name of the document / file to test + */ + private static void addFileToTest(String docName) + { + files.add(new String[] {docName}); + } + + /** + * @return list of corpus files to instantiate tests for + */ + @Parameters + public static Collection<String[]> data() + { + return files; + } + + /** + * Test rendering the annotations in the document description file results in the annotated html. + * + * @throws Exception in case something goes wrong looking up components and rendering + */ + @Test + public void getAnnotatedHTML() throws Exception + { + Parser parser = getComponentManager().lookup(Parser.class, Syntax.XWIKI_2_0.toIdString()); + XDOM xdom = parser.parse(new StringReader(TestDocumentFactory.getDocument(docName).getSource())); + + // run transformations + TransformationManager transformationManager = getComponentManager().lookup(TransformationManager.class); + transformationManager.performTransformations(xdom, Syntax.XWIKI_2_0); + + AnnotationPrintRenderer renderer = + getComponentManager().lookup(AnnotationPrintRenderer.class, ANNOTATIONS_RENDERER_HINT); + WikiPrinter printer = new DefaultWikiPrinter(); + renderer.setPrinter(printer); + // set the annotations for this renderer + renderer.setAnnotations(TestDocumentFactory.getDocument(docName).getSafeAnnotations()); + + xdom.traverse(renderer); + + assertEquals(TestDocumentFactory.getDocument(docName).getAnnotatedContent(), printer.toString()); + } + + /** + * Test rendering with the annotations renderer but without annotations doesn't alter the content. + * + * @throws Exception in case something goes wrong looking up components and rendering + */ + @Test + public void getAnnotatedHTMLWithoutAnnotations() throws Exception + { + Parser parser = getComponentManager().lookup(Parser.class, Syntax.XWIKI_2_0.toIdString()); + XDOM xdom = parser.parse(new StringReader(TestDocumentFactory.getDocument(docName).getSource())); + + // run transformations + TransformationManager transformationManager = getComponentManager().lookup(TransformationManager.class); + transformationManager.performTransformations(xdom, Syntax.XWIKI_2_0); + + AnnotationPrintRenderer renderer = + getComponentManager().lookup(AnnotationPrintRenderer.class, ANNOTATIONS_RENDERER_HINT); + WikiPrinter printer = new DefaultWikiPrinter(); + renderer.setPrinter(printer); + + xdom.traverse(renderer); + + assertEquals(TestDocumentFactory.getDocument(docName).getRenderedContent(), printer.toString()); + } +}
Property changes on: contrib/sandbox/xwiki-annotation-parent/xwiki-annotation-core/src/test/java/org/xwiki/annotation/renderer/XHTMLAnnotationRendererTest.java ___________________________________________________________________ Name: svn:keywords + Author Id Revision HeadURL Name: svn:eol-style + native
_______________________________________________ notifications mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/notifications