@Override public Text splitText(int offset) throws DOMException { Text text = getDomElement().splitText(offset); getSoapDocument().registerChildNodes(text, true); return text; }
/** * @param offset * @return * @throws org.w3c.dom.DOMException * @see org.w3c.dom.Text#splitText(int) */ public Text splitText(int offset) { return getParent().splitText(offset); }
@Override protected void runTest() throws Throwable { Document document = dbf.newDocumentBuilder().newDocument(); Text text = document.createTextNode("ABCD"); Text newText = text.splitText(2); assertThat(text.getData()).isEqualTo("AB"); assertThat(newText.getData()).isEqualTo("CD"); } }
public DOMText splitText(int offset) throws DOMException { try { return wrap(_delegate.splitText(offset)); } catch (org.w3c.dom.DOMException ex) { throw wrap(ex); } } }
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Node nameNode; Text textNode; Text splitNode; doc = (Document) load("staff", true); elementList = doc.getElementsByTagName("name"); nameNode = elementList.item(2); textNode = (Text) nameNode.getFirstChild(); { boolean success = false; try { splitNode = textNode.splitText(300); } catch (DOMException ex) { success = (ex.code == DOMException.INDEX_SIZE_ERR); } assertTrue("throw_INDEX_SIZE_ERR", success); } } /**
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Node nameNode; Text textNode; Text splitNode; doc = (Document) load("staff", true); elementList = doc.getElementsByTagName("name"); nameNode = elementList.item(2); textNode = (Text) nameNode.getFirstChild(); { boolean success = false; try { splitNode = textNode.splitText(-69); } catch (DOMException ex) { success = (ex.code == DOMException.INDEX_SIZE_ERR); } assertTrue("throws_INDEX_SIZE_ERR", success); } } /**
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Node nameNode; Text textNode; Text splitNode; doc = (Document) load("hc_staff", true); elementList = doc.getElementsByTagName("strong"); nameNode = elementList.item(2); textNode = (Text) nameNode.getFirstChild(); { boolean success = false; try { splitNode = textNode.splitText(-69); } catch (DOMException ex) { success = (ex.code == DOMException.INDEX_SIZE_ERR); } assertTrue("throws_INDEX_SIZE_ERR", success); } } /**
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Node nameNode; Text textNode; Text splitNode; doc = (Document) load("hc_staff", true); elementList = doc.getElementsByTagName("strong"); nameNode = elementList.item(2); textNode = (Text) nameNode.getFirstChild(); { boolean success = false; try { splitNode = textNode.splitText(300); } catch (DOMException ex) { success = (ex.code == DOMException.INDEX_SIZE_ERR); } assertTrue("throw_INDEX_SIZE_ERR", success); } } /**
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Node nameNode; Text textNode; Text splitNode; String value; doc = (Document) load("hc_staff", true); elementList = doc.getElementsByTagName("strong"); nameNode = elementList.item(2); textNode = (Text) nameNode.getFirstChild(); splitNode = textNode.splitText(5); value = textNode.getNodeValue(); assertEquals("textSplitTextTwoAssert", "Roger", value); } /**
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Node addressNode; Text textNode; Text splitNode; String value; doc = (Document) load("staff", true); elementList = doc.getElementsByTagName("address"); addressNode = elementList.item(0); textNode = (Text) addressNode.getFirstChild(); splitNode = textNode.splitText(30); value = splitNode.getNodeValue(); assertEquals("textSplitTextFourAssert", "98551", value); } /**
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Node nameNode; Text textNode; Text splitNode; Node secondPart; String value; doc = (Document) load("hc_staff", true); elementList = doc.getElementsByTagName("strong"); nameNode = elementList.item(2); textNode = (Text) nameNode.getFirstChild(); splitNode = textNode.splitText(7); secondPart = textNode.getNextSibling(); value = secondPart.getNodeValue(); assertEquals("textSplitTextOneAssert", "Jones", value); } /**
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Node nameNode; Text textNode; Text splitNode; Node secondPart; String value; doc = (Document) load("staff", true); elementList = doc.getElementsByTagName("name"); nameNode = elementList.item(2); textNode = (Text) nameNode.getFirstChild(); splitNode = textNode.splitText(7); secondPart = textNode.getNextSibling(); value = secondPart.getNodeValue(); assertEquals("textSplitTextOneAssert", "Jones", value); } /**
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Node nameNode; Text textNode; Text splitNode; String value; doc = (Document) load("staff", true); elementList = doc.getElementsByTagName("name"); nameNode = elementList.item(2); textNode = (Text) nameNode.getFirstChild(); splitNode = textNode.splitText(5); value = textNode.getNodeValue(); assertEquals("textSplitTextTwoAssert", "Roger", value); } /**
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Node addressNode; Text textNode; Text splitNode; String value; doc = (Document) load("hc_staff", true); elementList = doc.getElementsByTagName("acronym"); addressNode = elementList.item(0); textNode = (Text) addressNode.getFirstChild(); splitNode = textNode.splitText(30); value = splitNode.getNodeValue(); assertEquals("textSplitTextFourAssert", "98551", value); } /**
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Node nameNode; Text textNode; Text splitNode; String value; doc = (Document) load("hc_staff", true); elementList = doc.getElementsByTagName("strong"); nameNode = elementList.item(2); textNode = (Text) nameNode.getFirstChild(); splitNode = textNode.splitText(6); value = splitNode.getNodeValue(); assertEquals("textSplitTextThreeAssert", " Jones", value); } /**
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Node nameNode; Text textNode; Text splitNode; String value; doc = (Document) load("staff", true); elementList = doc.getElementsByTagName("name"); nameNode = elementList.item(2); textNode = (Text) nameNode.getFirstChild(); splitNode = textNode.splitText(6); value = splitNode.getNodeValue(); assertEquals("textSplitTextThreeAssert", " Jones", value); } /**
protected void runTest() throws Throwable { String textValue = "temp text value"; Document doc = dbf.newDocumentBuilder().newDocument(); Element element = doc.createElement("test"); Text txt = doc.createTextNode(textValue); element.appendChild(txt); txt.splitText(3); assertNotNull("Text value missing in the original Text node", txt .getNodeValue()); assertNotNull("Sibling missing after split", txt.getNextSibling()); assertNotNull("Text value missing in the new split Text node", txt .getNextSibling().getNodeValue()); assertEquals("Incorrect split point", textValue.substring(0, 3), txt .getNodeValue()); assertEquals("Incorrect split point", textValue.substring(3, textValue .length()), txt.getNextSibling().getNodeValue()); } }
public static Text splitDomText(EditPart part, DesignRange range) { if (part instanceof TextEditPart) { Text textNode = (Text) part.getModel(); DOMRange domRange = DOMRangeHelper.toDOMRange(range); IDOMPosition start = domRange.getStartPosition(); IDOMPosition end = domRange.getEndPosition(); int domTempStartOffset = computeOffset(start, textNode); int domTempEndOffset = computeOffset(end, textNode); int domStartOffset = Math.min(domTempStartOffset, domTempEndOffset); int domEndOffset = Math.max(domTempStartOffset, domTempEndOffset); Text lastNode = textNode; if (domStartOffset > 0) { lastNode = textNode.splitText(domStartOffset); } lastNode = lastNode.splitText(domEndOffset - domStartOffset); Text middleNode = (Text) lastNode.getPreviousSibling(); return middleNode; } return null; }
/** * if "position" is inside a text node, then split the text node and return * a new IDOMPosition semantically equal to the position in the two * splitted text. If the "position" is not a text position, then no action * will be taken and will return the original position. * * @param position * @return IDOMPosition */ public static IDOMPosition splitText(IDOMPosition position) { Node container = position.getContainerNode(); if (container instanceof Text) { int offset = position.getOffset(); if (offset <= 0) { // at beginning of text node. no need to split return new DOMRefPosition(container, false); } String textData = ((Text) container).getData(); if (offset >= textData.length()) { // at end of text node. no need to split return new DOMRefPosition(container, true); } // ok, we need split ((Text) container).splitText(offset); return new DOMRefPosition(container, true); } return position; }
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; Node entRef; Node entText; Text splitNode; doc = (Document) load("staff", true); entRef = doc.createEntityReference("ent3"); assertNotNull("createdEntRefNotNull", entRef); entText = entRef.getFirstChild(); assertNotNull("entTextNotNull", entText); { boolean success = false; try { splitNode = ((Text) /*Node */entText).splitText(2); } catch (DOMException ex) { success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR); } assertTrue("throw_NO_MODIFICATION_ALLOWED_ERR", success); } } /**