private List<Point<Node>> splitTextNodes(IndexedDocument<Node, Element, Text> doc) { List<Point<Node>> splitPoints = new ArrayList<Point<Node>>(); final List<Text> toSplit = new ArrayList<Text>(); DocHelper.traverse(doc, doc.getDocumentElement(), new NodeAction<Node>() { public void apply(Node node) { if (node instanceof Text) { Text t = (Text) node; if (t.getData().contains("^")) { toSplit.add(t); } } } }); for (Text t : toSplit) { while (t != null && t.getData().contains("^")) { t = doc.splitText(t, t.getData().indexOf("^") + 1); splitPoints.add(Point.before(doc, t)); } } return splitPoints; }
public void testCountChildrenReturnsZeroWhenThereAreNoChildren() { IndexedDocument<Node, Element, Text> doc = DocProviders.POJO.parse(""); assertEquals(0, DocHelper.countChildren(doc, doc.getDocumentElement())); }
public void testCountChildren() { IndexedDocument<Node, Element, Text> doc = DocProviders.POJO.parse("<a/>asdf<b/><c/>"); assertEquals(4, DocHelper.countChildren(doc, doc.getDocumentElement())); }
private List<Point<Node>> splitTextNodes(IndexedDocument<Node, Element, Text> doc) { List<Point<Node>> splitPoints = new ArrayList<Point<Node>>(); final List<Text> toSplit = new ArrayList<Text>(); DocHelper.traverse(doc, doc.getDocumentElement(), new NodeAction<Node>() { public void apply(Node node) { if (node instanceof Text) { Text t = (Text) node; if (t.getData().contains("^")) { toSplit.add(t); } } } }); for (Text t : toSplit) { while (t != null && t.getData().contains("^")) { t = doc.splitText(t, t.getData().indexOf("^") + 1); splitPoints.add(Point.before(doc, t)); } } return splitPoints; }
public void testCountChildrenReturnsZeroWhenThereAreNoChildren() { IndexedDocument<Node, Element, Text> doc = DocProviders.POJO.parse(""); assertEquals(0, DocHelper.countChildren(doc, doc.getDocumentElement())); }
public void testCountChildren() { IndexedDocument<Node, Element, Text> doc = DocProviders.POJO.parse("<a/>asdf<b/><c/>"); assertEquals(4, DocHelper.countChildren(doc, doc.getDocumentElement())); }
private void testHelper(String initialContent, int start, int end, String expectedContent) { IndexedDocument<Node, Element, Text> parse = DocProviders.POJO.parse(initialContent); SubTreeXmlRenderer<Node, Element, Text> renderer = new SubTreeXmlRenderer<Node, Element, Text>(parse); Element nearestCommonAncestor = parse.getDocumentElement(); XmlStringBuilder rendered = renderer.renderRange(parse.locate(start), parse.locate(end)); assertEquals(expectedContent, rendered.toString()); } }
private void testHelper(String initialContent, int start, int end, String expectedContent) { IndexedDocument<Node, Element, Text> parse = DocProviders.POJO.parse(initialContent); SubTreeXmlRenderer<Node, Element, Text> renderer = new SubTreeXmlRenderer<Node, Element, Text>(parse); Element nearestCommonAncestor = parse.getDocumentElement(); XmlStringBuilder rendered = renderer.renderRange(parse.locate(start), parse.locate(end)); assertEquals(expectedContent, rendered.toString()); } }
effectivePos == 0 ? doc.getDocumentElement() : Point.enclosingElement(doc, doc.locate(effectivePos)); E elementNext = Point.enclosingElement(doc, doc.locate(effectivePos + 1));
E root = doc.getDocumentElement(); assert root != null; return root;
/** * Test that sample locations are being mapped correctly. */ public void testSampleLocations1() { IndexedDocument<Node, Element, Text> document = createEmptyDocument(); try { document.consume(element("p")); document.consume(characters("a", 1, 1)); Node testNode = document.getDocumentElement().getFirstChild(); assertNotNull(testNode); testNode = testNode.getFirstChild(); assertNotNull(testNode); assertEquals(1, document.getLocation(testNode)); assertEquals(1, testNode.getIndexingContainer().size()); document.consume(characters("b", 2, 1)); assertEquals(1, document.getLocation(testNode)); assertEquals(2, testNode.getIndexingContainer().size()); document.consume(characters("c", 3, 1)); assertEquals(1, document.getLocation(testNode)); assertEquals(3, testNode.getIndexingContainer().size()); } catch (OperationException e) { fail(e.toString()); } }
/** * Test that sample locations are being mapped correctly. */ public void testSampleLocations1() { IndexedDocument<Node, Element, Text> document = createEmptyDocument(); try { document.consume(element("p")); document.consume(characters("a", 1, 1)); Node testNode = document.getDocumentElement().getFirstChild(); assertNotNull(testNode); testNode = testNode.getFirstChild(); assertNotNull(testNode); assertEquals(1, document.getLocation(testNode)); assertEquals(1, testNode.getIndexingContainer().size()); document.consume(characters("b", 2, 1)); assertEquals(1, document.getLocation(testNode)); assertEquals(2, testNode.getIndexingContainer().size()); document.consume(characters("c", 3, 1)); assertEquals(1, document.getLocation(testNode)); assertEquals(3, testNode.getIndexingContainer().size()); } catch (OperationException e) { fail(e.toString()); } }
assertEquals("abcdef", DocHelper.getText(doc, doc, doc.getDocumentElement()));
assertEquals("abcdef", DocHelper.getText(doc, doc, doc.getDocumentElement()));
Node last = cxt5.getIndexedDoc().getDocumentElement().getLastChild(); Point<Node> point = DocHelper.transparentSlice(Point.<Node>end(last), cxt5); assertEquals("he^llo<x>t^<a><b><c>TT</c>here^</b>" +
Node last = cxt5.getIndexedDoc().getDocumentElement().getLastChild(); Point<Node> point = DocHelper.transparentSlice(Point.<Node>end(last), cxt5); assertEquals("he^llo<x>t^<a><b><c>TT</c>here^</b>" +