1 18 package org.apache.batik.dom; 19 20 import org.w3c.dom.DOMException ; 21 import org.w3c.dom.Node ; 22 import org.w3c.dom.Text ; 23 24 30 31 public abstract class AbstractText 32 extends AbstractCharacterData 33 implements Text { 34 35 38 public Text splitText(int offset) throws DOMException { 39 if (isReadonly()) { 40 throw createDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, 41 "readonly.node", 42 new Object [] { new Integer (getNodeType()), 43 getNodeName() }); 44 } 45 String v = getNodeValue(); 46 if (offset < 0 || offset >= v.length()) { 47 throw createDOMException(DOMException.INDEX_SIZE_ERR, 48 "offset", 49 new Object [] { new Integer (offset) }); 50 } 51 Node n = getParentNode(); 52 if (n == null) { 53 throw createDOMException(DOMException.INDEX_SIZE_ERR, 54 "need.parent", 55 new Object [] {}); 56 } 57 String t1 = v.substring(offset); 58 Text t = createTextNode(t1); 59 Node ns = getNextSibling(); 60 if (ns != null) { 61 n.insertBefore(t, ns); 62 } else { 63 n.appendChild(t); 64 } 65 setNodeValue(v.substring(0, offset)); 66 return t; 67 } 68 69 72 protected abstract Text createTextNode(String text); 73 } 74 | Popular Tags |