/** * {@inheritDoc} */ @Override public void setText(final String txt) { text.setData(txt); }
/** * {@inheritDoc} */ @Override public String getText() { return text.getData(); }
@Override public void setText(String text) { assert baseNode == null : "TextNode can be set once"; baseNode = Document.get().createTextNode(text); setElement(baseNode.<Element>cast()); }
public void testRepairsWherePossible() throws HtmlInserted, HtmlMissing { ContentDocument dom = TestEditors.createTestDocument(); c = dom.debugGetRawDocument(); ContentElement root = c.getDocumentElement(); m = dom.getContext().rendering().getNodeManager(); // TODO(danilatos): Expand this and other test cases String s1 = "some text", s2 = "other writings", s3 = "more information"; ContentTextNode t1 = c.createTextNode(s1, root, null); Text n1 = t1.getImplNodelet(), n1b; n1b = n1.splitText(1); n1b.setData(s1); n1.removeFromParent(); try { m.findTextWrapper(n1b, false); fail("Expected exception when not repairing"); } catch (HtmlInserted e) { } catch (HtmlMissing e) { } checkWrapper(t1, n1b, true); }
public void testImplDataSumsTextNodes() throws HtmlMissing { ContentDocument dom = TestEditors.createTestDocument(); c = dom.debugGetRawDocument(); ContentElement root = c.getDocumentElement(); ContentTextNode t1 = c.createTextNode("hello", root, null); Text txt = t1.getImplNodelet(); assertEquals("hello", t1.getImplData()); Text txt3 = Document.get().createTextNode(" there"); txt.getParentNode().insertAfter(txt3, txt); assertEquals("hello there", t1.getImplData()); Text txt2 = txt.splitText(2); assertEquals("hello there", t1.getImplData()); assertSame(txt3, txt.getNextSibling().getNextSibling()); assertTrue(t1.owns(txt) && t1.owns(txt2) && t1.owns(txt3)); ContentTextNode t2 = c.createTextNode("before", root, t1); assertEquals("before", t2.getImplData()); Text t2_2 = t2.getImplNodelet().splitText(3); assertEquals("before", t2.getImplData()); assertTrue(t2.owns(t2_2)); }
Text txt2 = t2.getImplNodelet(); txt1.removeFromParent(); txt2.getParentNode().insertBefore(txt1, txt2); txt2.removeFromParent(); Text txt1b = txt1.splitText(2); try { t1.getImplData(); txt1b.getParentNode().insertAfter(t2.getImplNodelet(), txt1b); try { assertEquals("hello", t1.getImplData());
/** * Breaks this node into two nodes at the specified <code>offset</code>, * keeping both in the tree as siblings. After being split, this node * will contain all the content up to the <code>offset</code> point. A * new node of the same type, which contains all the content at and * after the <code>offset</code> point, is returned. If the original * node had a parent node, the new node is inserted as the next sibling * of the original node. When the <code>offset</code> is equal to the * length of this node, the new node has no data. * @param offset The 16-bit unit offset at which to split, starting from * <code>0</code>. * @return The new node, of the same type as this node. * @exception DOMException * INDEX_SIZE_ERR: Raised if the specified offset is negative or greater * than the number of 16-bit units in <code>data</code>. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. */ public final OMText splitText(int offset) throws JavaScriptException { return new OMText(((Text)ot.cast()).splitText(offset)); };
t1.getImplNodelet().getParentNode().insertBefore(ca(), t1.getImplNodelet()); r.revertInner(Point.before(c, p), Point.after(c, p)); assertEquals("hello <b>th</b>ere", p.getImplNodelet().getInnerHTML()); t1.getImplNodelet().getParentNode().insertBefore(ca(), t1.getImplNodelet()); r.revertInner(Point.before(c, t1), Point.before(c, t3)); assertEquals("hello <b>th</b>ere<a></a>", p.getImplNodelet().getInnerHTML()); assertEquals("hello <b>there</b>", p.getImplNodelet().getInnerHTML()); Element wrapper = ca(); Node bit = t1.getImplNodelet().splitText(2); bit.getParentNode().insertBefore(wrapper, bit); wrapper.appendChild(bit);
public void testReporting() { init(); initHelloThere(); l.check(0, 0); // fix and revert a range p.getImplNodelet().appendChild(ca()); t1.getImplNodelet().getParentNode().insertBefore(ca(), t1.getImplNodelet()); r.revert(Point.before(c, t1), Point.before(c, t3)); assertEquals("hello <b>th</b>ere<a></a>", p.getImplNodelet().getInnerHTML()); l.check(0, 1); // revert everything r.revert(c, c.getDocumentElement()); assertEquals("hello <b>th</b>ere", p.getImplNodelet().getInnerHTML()); l.check(1, 1); }
/** * Creates a text node with the desired text * * @param txt String text to display */ public Text(final String txt) { text = Document.get().createTextNode(txt); setElement(text.<Element>cast()); }
public void testRepairsWherePossible() throws HtmlInserted, HtmlMissing { ContentDocument dom = TestEditors.createTestDocument(); c = dom.debugGetRawDocument(); ContentElement root = c.getDocumentElement(); m = dom.getContext().rendering().getNodeManager(); // TODO(danilatos): Expand this and other test cases String s1 = "some text", s2 = "other writings", s3 = "more information"; ContentTextNode t1 = c.createTextNode(s1, root, null); Text n1 = t1.getImplNodelet(), n1b; n1b = n1.splitText(1); n1b.setData(s1); n1.removeFromParent(); try { m.findTextWrapper(n1b, false); fail("Expected exception when not repairing"); } catch (HtmlInserted e) { } catch (HtmlMissing e) { } checkWrapper(t1, n1b, true); }
public void testImplDataSumsTextNodes() throws HtmlMissing { ContentDocument dom = TestEditors.createTestDocument(); c = dom.debugGetRawDocument(); ContentElement root = c.getDocumentElement(); ContentTextNode t1 = c.createTextNode("hello", root, null); Text txt = t1.getImplNodelet(); assertEquals("hello", t1.getImplData()); Text txt3 = Document.get().createTextNode(" there"); txt.getParentNode().insertAfter(txt3, txt); assertEquals("hello there", t1.getImplData()); Text txt2 = txt.splitText(2); assertEquals("hello there", t1.getImplData()); assertSame(txt3, txt.getNextSibling().getNextSibling()); assertTrue(t1.owns(txt) && t1.owns(txt2) && t1.owns(txt3)); ContentTextNode t2 = c.createTextNode("before", root, t1); assertEquals("before", t2.getImplData()); Text t2_2 = t2.getImplNodelet().splitText(3); assertEquals("before", t2.getImplData()); assertTrue(t2.owns(t2_2)); }
Text txt2 = t2.getImplNodelet(); txt1.removeFromParent(); txt2.getParentNode().insertBefore(txt1, txt2); txt2.removeFromParent(); Text txt1b = txt1.splitText(2); try { t1.getImplData(); txt1b.getParentNode().insertAfter(t2.getImplNodelet(), txt1b); try { assertEquals("hello", t1.getImplData());
/** * Breaks this node into two nodes at the specified <code>offset</code>, * keeping both in the tree as siblings. After being split, this node * will contain all the content up to the <code>offset</code> point. A * new node of the same type, which contains all the content at and * after the <code>offset</code> point, is returned. If the original * node had a parent node, the new node is inserted as the next sibling * of the original node. When the <code>offset</code> is equal to the * length of this node, the new node has no data. * @param offset The 16-bit unit offset at which to split, starting from * <code>0</code>. * @return The new node, of the same type as this node. * @exception DOMException * INDEX_SIZE_ERR: Raised if the specified offset is negative or greater * than the number of 16-bit units in <code>data</code>. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. */ public final OMText splitText(int offset) throws JavaScriptException { return new OMText(((Text)ot.cast()).splitText(offset)); };
t1.getImplNodelet().getParentNode().insertBefore(ca(), t1.getImplNodelet()); r.revertInner(Point.before(c, p), Point.after(c, p)); assertEquals("hello <b>th</b>ere", p.getImplNodelet().getInnerHTML()); t1.getImplNodelet().getParentNode().insertBefore(ca(), t1.getImplNodelet()); r.revertInner(Point.before(c, t1), Point.before(c, t3)); assertEquals("hello <b>th</b>ere<a></a>", p.getImplNodelet().getInnerHTML()); assertEquals("hello <b>there</b>", p.getImplNodelet().getInnerHTML()); Element wrapper = ca(); Node bit = t1.getImplNodelet().splitText(2); bit.getParentNode().insertBefore(wrapper, bit); wrapper.appendChild(bit);
public void testReporting() { init(); initHelloThere(); l.check(0, 0); // fix and revert a range p.getImplNodelet().appendChild(ca()); t1.getImplNodelet().getParentNode().insertBefore(ca(), t1.getImplNodelet()); r.revert(Point.before(c, t1), Point.before(c, t3)); assertEquals("hello <b>th</b>ere<a></a>", p.getImplNodelet().getInnerHTML()); l.check(0, 1); // revert everything r.revert(c, c.getDocumentElement()); assertEquals("hello <b>th</b>ere", p.getImplNodelet().getInnerHTML()); l.check(1, 1); }
/** * {@inheritDoc} */ @Override public String getText() { return text.getData(); } }
/** * {@inheritDoc} */ @Override public void setText(final String txt) { text.setData(txt); }