@Override public void setAnnotation(int start, int end, String key, String value) { getDelegate().setAnnotation(start, end, key, value); }
private void useDocument(String docContent, String... annotations) { MutableDocument<Node, ?, ?> mutable = DocProviders.MOJO.parse("<body>" + docContent + "</body>"); // format: key:value:start:end for (String value : annotations) { String[] vals = value.split(":"); mutable.setAnnotation(Integer.parseInt(vals[2]), Integer.parseInt(vals[3]), vals[0], vals[1]); } doc = mutable; }
private void useDocument(String docContent, String... annotations) { MutableDocument<?, ?, ?> mutable = DocProviders.MOJO.parse("<body><line></line>" + docContent + "</body>"); // format: key:value:start:end for (String value : annotations) { String[] vals = value.split(":"); mutable.setAnnotation(Integer.parseInt(vals[2]), Integer.parseInt(vals[3]), vals[0], vals[1]); } doc = mutable; }
private void useDocument(String docContent, String... annotations) { MutableDocument<Node, Element, Text> mutable = DocProviders.MOJO.parse("<body>" + docContent + "</body>"); // format: key:value:start:end for (String value : annotations) { String[] vals = value.split(":"); mutable.setAnnotation(Integer.parseInt(vals[2]), Integer.parseInt(vals[3]), vals[0], vals[1]); } doc = mutable; }
private void useDocument(String docContent, String... annotations) { MutableDocument<?, ?, ?> mutable = DocProviders.MOJO.parse("<body><line></line>" + docContent + "</body>"); // format: key:value:start:end for (String value : annotations) { String[] vals = value.split(":"); mutable.setAnnotation(Integer.parseInt(vals[2]), Integer.parseInt(vals[3]), vals[0], vals[1]); } doc = mutable; }
private void useDocument(String docContent, String... annotations) { MutableDocument<Node, Element, Text> mutable = DocProviders.MOJO.parse("<body>" + docContent + "</body>"); // format: key:value:start:end for (String value : annotations) { String[] vals = value.split(":"); mutable.setAnnotation(Integer.parseInt(vals[2]), Integer.parseInt(vals[3]), vals[0], vals[1]); } doc = mutable; }
private void useDocument(String docContent, String... annotations) { MutableDocument<Node, ?, ?> mutable = DocProviders.MOJO.parse("<body>" + docContent + "</body>"); // format: key:value:start:end for (String value : annotations) { String[] vals = value.split(":"); mutable.setAnnotation(Integer.parseInt(vals[2]), Integer.parseInt(vals[3]), vals[0], vals[1]); } doc = mutable; }
public void testExplicitValueOverrides() { getDoc("<body><line/>Some text<line/>Some more text</body>"); doc.setAnnotation(2, 7, TitleHelper.TITLE_KEY, "Blah"); assertEquals("Blah", TitleHelper.extractTitle(doc)); assertTrue(TitleHelper.hasExplicitTitle(doc)); }
public void testExplicitValueOverrides() { getDoc("<body><line/>Some text<line/>Some more text</body>"); doc.setAnnotation(2, 7, TitleHelper.TITLE_KEY, "Blah"); assertEquals("Blah", TitleHelper.extractTitle(doc)); assertTrue(TitleHelper.hasExplicitTitle(doc)); }
public void checkGetRangePrecedingLocation(String initialContent, Range annotatedRange, Range expected, int end) { final TestDocumentContext<Node, Element, Text> cxt = initializeTestContext(initialContent); MutableDocument<Node, Element, Text> doc = cxt.document(); doc.setAnnotation(annotatedRange.getStart(), annotatedRange.getEnd(), "test", "value"); assertEquals(expected, AnnotationHelper.getRangePrecedingLocation(doc, end, "test")); } }
public void checkGetRangePrecedingLocation(String initialContent, Range annotatedRange, Range expected, int end) { final TestDocumentContext<Node, Element, Text> cxt = initializeTestContext(initialContent); MutableDocument<Node, Element, Text> doc = cxt.document(); doc.setAnnotation(annotatedRange.getStart(), annotatedRange.getEnd(), "test", "value"); assertEquals(expected, AnnotationHelper.getRangePrecedingLocation(doc, end, "test")); } }
public void testNodeAtEnd() { TestDocumentContext<Node, Element, Text> cxt = createAnnotationContext(); MutableDocument<Node, Element, Text> doc = cxt.document(); Element e = doc.createChildElement(doc.getDocumentElement(), "p", Attributes.EMPTY_MAP); doc.insertText(Point.<Node>inElement(e, null), "Hi"); doc.setAnnotation(3, 4, "x", "1"); timerService.tick(100); ReadableDocument<Node, Element, Text> fullDoc = cxt.getFullRawDoc(); Element boundary = fullDoc.asElement(fullDoc.getLastChild(e)); assertNotNull(boundary); assertEquals("l:b", boundary.getTagName()); doc.setAnnotation(3, 4, "x", null); timerService.tick(100); boundary = fullDoc.asElement(fullDoc.getLastChild(e)); assertNull(boundary); }
public void testNodeAtEnd() { TestDocumentContext<Node, Element, Text> cxt = createAnnotationContext(); MutableDocument<Node, Element, Text> doc = cxt.document(); Element e = doc.createChildElement(doc.getDocumentElement(), "p", Attributes.EMPTY_MAP); doc.insertText(Point.<Node>inElement(e, null), "Hi"); doc.setAnnotation(3, 4, "x", "1"); timerService.tick(100); ReadableDocument<Node, Element, Text> fullDoc = cxt.getFullRawDoc(); Element boundary = fullDoc.asElement(fullDoc.getLastChild(e)); assertNotNull(boundary); assertEquals("l:b", boundary.getTagName()); doc.setAnnotation(3, 4, "x", null); timerService.tick(100); boundary = fullDoc.asElement(fullDoc.getLastChild(e)); assertNull(boundary); }
/** Tests bug 1839733 */ public void testNestedPaintNodes() { TestDocumentContext<Node, Element, Text> cxt = createAnnotationContext(); MutableDocument<Node, Element, Text> doc = cxt.document(); Element e = doc.createChildElement(doc.getDocumentElement(), "p", Attributes.EMPTY_MAP); doc.insertText(doc.locate(1), "A"); doc.insertText(doc.locate(2), "B"); doc.setAnnotation(2, 3, "a", "1"); timerService.tick(100); checkXml("<p>A<l:p a=\"1\">B</l:p></p>", XmlStringBuilder.innerXml(cxt.getFullRawDoc())); doc.insertText(doc.locate(3), "C"); doc.setAnnotation(3, 4, "b", "2"); timerService.tick(100); checkXml("<p>A<l:p a=\"1\">B</l:p><l:p a=\"1\" b=\"2\">C</l:p></p>", XmlStringBuilder.innerXml(cxt.getFullRawDoc())); doc.insertText(doc.locate(4), "D"); doc.setAnnotation(4, 5, "a", null); timerService.tick(100); checkXml("<p>A<l:p a=\"1\">B</l:p><l:p a=\"1\" b=\"2\">C</l:p><l:p b=\"2\">D</l:p></p>", XmlStringBuilder.innerXml(cxt.getFullRawDoc())); doc.insertText(doc.locate(5), "E"); doc.setAnnotation(5, 6, "b", null); timerService.tick(100); checkXml("<p>A<l:p a=\"1\">B</l:p><l:p a=\"1\" b=\"2\">C</l:p><l:p b=\"2\">D</l:p>E</p>", XmlStringBuilder.innerXml(cxt.getFullRawDoc())); }
/** Tests bug 1839733 */ public void testNestedPaintNodes() { TestDocumentContext<Node, Element, Text> cxt = createAnnotationContext(); MutableDocument<Node, Element, Text> doc = cxt.document(); Element e = doc.createChildElement(doc.getDocumentElement(), "p", Attributes.EMPTY_MAP); doc.insertText(doc.locate(1), "A"); doc.insertText(doc.locate(2), "B"); doc.setAnnotation(2, 3, "a", "1"); timerService.tick(100); checkXml("<p>A<l:p a=\"1\">B</l:p></p>", XmlStringBuilder.innerXml(cxt.getFullRawDoc())); doc.insertText(doc.locate(3), "C"); doc.setAnnotation(3, 4, "b", "2"); timerService.tick(100); checkXml("<p>A<l:p a=\"1\">B</l:p><l:p a=\"1\" b=\"2\">C</l:p></p>", XmlStringBuilder.innerXml(cxt.getFullRawDoc())); doc.insertText(doc.locate(4), "D"); doc.setAnnotation(4, 5, "a", null); timerService.tick(100); checkXml("<p>A<l:p a=\"1\">B</l:p><l:p a=\"1\" b=\"2\">C</l:p><l:p b=\"2\">D</l:p></p>", XmlStringBuilder.innerXml(cxt.getFullRawDoc())); doc.insertText(doc.locate(5), "E"); doc.setAnnotation(5, 6, "b", null); timerService.tick(100); checkXml("<p>A<l:p a=\"1\">B</l:p><l:p a=\"1\" b=\"2\">C</l:p><l:p b=\"2\">D</l:p>E</p>", XmlStringBuilder.innerXml(cxt.getFullRawDoc())); }
public void testCorrectBoundaryPoint() { // immitate the structore of line containers with a local paragraph TestDocumentContext<Node, Element, Text> cxt = createAnnotationContext(); MutableDocument<Node, Element, Text> doc = cxt.document(); Element lc = doc.createChildElement(doc.getDocumentElement(), "body", Attributes.EMPTY_MAP); Element l = doc.createChildElement(lc, "line", Attributes.EMPTY_MAP); Element label = doc.createChildElement(lc, "label", Attributes.EMPTY_MAP); doc.insertText(Point.end((Node)label), "test"); // set up local content, moving the label into it Element local = cxt.annotatableContent().transparentCreate( "l:l", Attributes.EMPTY_MAP, lc, null); PersistentContent.makeHard(cxt.annotatableContent(), local); cxt.annotatableContent().transparentMove(local, l.getNextSibling(), local, null); try { doc.setAnnotation(3, 9, "a", "1"); timerService.tick(100); } catch (Exception e) { fail("Annotation painting threw exception - " + e.getMessage()); } }
public void testCorrectBoundaryPoint() { // immitate the structore of line containers with a local paragraph TestDocumentContext<Node, Element, Text> cxt = createAnnotationContext(); MutableDocument<Node, Element, Text> doc = cxt.document(); Element lc = doc.createChildElement(doc.getDocumentElement(), "body", Attributes.EMPTY_MAP); Element l = doc.createChildElement(lc, "line", Attributes.EMPTY_MAP); Element label = doc.createChildElement(lc, "label", Attributes.EMPTY_MAP); doc.insertText(Point.end((Node)label), "test"); // set up local content, moving the label into it Element local = cxt.annotatableContent().transparentCreate( "l:l", Attributes.EMPTY_MAP, lc, null); PersistentContent.makeHard(cxt.annotatableContent(), local); cxt.annotatableContent().transparentMove(local, l.getNextSibling(), local, null); try { doc.setAnnotation(3, 9, "a", "1"); timerService.tick(100); } catch (Exception e) { fail("Annotation painting threw exception - " + e.getMessage()); } }
/** Test whether left/right alignment of annotation retrieval is working. */ public void testGetAlignedAnnotation() { // setup: ab[cdef]gh MutableDocument<Node, Element, Text> doc = ContextProviders.createTestPojoContext( "abcdefgh", null, null, null, DocumentSchema.NO_SCHEMA_CONSTRAINTS).document(); doc.setAnnotation(2, 6, "X", "Y"); // check left-align at start, middle, and end and after of non-null annotation assertEquals(Annotations.getAlignedAnnotation(doc, 2, "X", true), null); assertEquals(Annotations.getAlignedAnnotation(doc, 4, "X", true), "Y"); assertEquals(Annotations.getAlignedAnnotation(doc, 6, "X", true), "Y"); assertEquals(Annotations.getAlignedAnnotation(doc, 8, "X", true), null); // check right-align at start, middle, and end of non-null annotation assertEquals(Annotations.getAlignedAnnotation(doc, 0, "X", false), null); assertEquals(Annotations.getAlignedAnnotation(doc, 2, "X", false), "Y"); assertEquals(Annotations.getAlignedAnnotation(doc, 4, "X", false), "Y"); assertEquals(Annotations.getAlignedAnnotation(doc, 6, "X", false), null); // Boundary cases - left aligning at start, right aligning at end assertNull(Annotations.getAlignedAnnotation(doc, 0, "X", true)); assertNull(Annotations.getAlignedAnnotation(doc, doc.size(), "X", false)); }
/** Test whether left/right alignment of annotation retrieval is working. */ public void testGetAlignedAnnotation() { // setup: ab[cdef]gh MutableDocument<Node, Element, Text> doc = ContextProviders.createTestPojoContext( "abcdefgh", null, null, null, DocumentSchema.NO_SCHEMA_CONSTRAINTS).document(); doc.setAnnotation(2, 6, "X", "Y"); // check left-align at start, middle, and end and after of non-null annotation assertEquals(Annotations.getAlignedAnnotation(doc, 2, "X", true), null); assertEquals(Annotations.getAlignedAnnotation(doc, 4, "X", true), "Y"); assertEquals(Annotations.getAlignedAnnotation(doc, 6, "X", true), "Y"); assertEquals(Annotations.getAlignedAnnotation(doc, 8, "X", true), null); // check right-align at start, middle, and end of non-null annotation assertEquals(Annotations.getAlignedAnnotation(doc, 0, "X", false), null); assertEquals(Annotations.getAlignedAnnotation(doc, 2, "X", false), "Y"); assertEquals(Annotations.getAlignedAnnotation(doc, 4, "X", false), "Y"); assertEquals(Annotations.getAlignedAnnotation(doc, 6, "X", false), null); // Boundary cases - left aligning at start, right aligning at end assertNull(Annotations.getAlignedAnnotation(doc, 0, "X", true)); assertNull(Annotations.getAlignedAnnotation(doc, doc.size(), "X", false)); }
/***/ public void testAnnotationBoundaryHelpers() { MutableDocument<Node, Element, Text> doc = ContextProviders.createTestPojoContext( "abcdefgh", null, null, null, DocumentSchema.NO_SCHEMA_CONSTRAINTS).document(); int s = doc.size(); assertEquals(s, Annotations.firstAnnotationBoundary(doc, 0, s, "a", null)); assertEquals(0, Annotations.lastAnnotationBoundary(doc, 0, s, "a", null)); assertEquals(s - 1, Annotations.firstAnnotationBoundary(doc, 1, s - 1, "a", null)); assertEquals(1, Annotations.lastAnnotationBoundary(doc, 1, s - 1, "a", null)); assertEquals(0, Annotations.firstAnnotationBoundary(doc, 0, s, "a", "x")); assertEquals(s, Annotations.lastAnnotationBoundary(doc, 0, s, "a", "x")); assertEquals(1, Annotations.firstAnnotationBoundary(doc, 1, s - 1, "a", "")); assertEquals(s - 1, Annotations.lastAnnotationBoundary(doc, 1, s - 1, "a", "")); doc.setAnnotation(2, 3, "a", ""); doc.setAnnotation(4, 5, "a", ""); assertEquals(2, Annotations.firstAnnotationBoundary(doc, 0, s, "a", null)); assertEquals(5, Annotations.lastAnnotationBoundary(doc, 0, s, "a", null)); assertEquals(2, Annotations.firstAnnotationBoundary(doc, 1, s - 1, "a", null)); assertEquals(5, Annotations.lastAnnotationBoundary(doc, 1, s - 1, "a", null)); assertEquals(0, Annotations.firstAnnotationBoundary(doc, 0, s, "a", "x")); assertEquals(s, Annotations.lastAnnotationBoundary(doc, 0, s, "a", "x")); assertEquals(1, Annotations.firstAnnotationBoundary(doc, 1, s - 1, "a", "y")); assertEquals(s - 1, Annotations.lastAnnotationBoundary(doc, 1, s - 1, "a", "y")); assertEquals(0, Annotations.firstAnnotationBoundary(doc, 0, s, "a", "")); assertEquals(s, Annotations.lastAnnotationBoundary(doc, 0, s, "a", "")); assertEquals(1, Annotations.firstAnnotationBoundary(doc, 1, s - 1, "a", "")); assertEquals(s - 1, Annotations.lastAnnotationBoundary(doc, 1, s - 1, "a", "")); }