KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > dom > AbstractText


1 /*
2
3    Copyright 2000 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.dom;
19
20 import org.w3c.dom.DOMException JavaDoc;
21 import org.w3c.dom.Node JavaDoc;
22 import org.w3c.dom.Text JavaDoc;
23
24 /**
25  * This class implements the {@link org.w3c.dom.Text} interface.
26  *
27  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
28  * @version $Id: AbstractText.java,v 1.6 2005/02/22 09:12:58 cam Exp $
29  */

30
31 public abstract class AbstractText
32     extends AbstractCharacterData
33     implements Text JavaDoc {
34
35     /**
36      * <b>DOM</b>: Implements {@link org.w3c.dom.Text#splitText(int)}.
37      */

38     public Text JavaDoc splitText(int offset) throws DOMException JavaDoc {
39     if (isReadonly()) {
40         throw createDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
41                      "readonly.node",
42                      new Object JavaDoc[] { new Integer JavaDoc(getNodeType()),
43                             getNodeName() });
44     }
45     String JavaDoc v = getNodeValue();
46     if (offset < 0 || offset >= v.length()) {
47         throw createDOMException(DOMException.INDEX_SIZE_ERR,
48                      "offset",
49                      new Object JavaDoc[] { new Integer JavaDoc(offset) });
50     }
51     Node JavaDoc n = getParentNode();
52     if (n == null) {
53         throw createDOMException(DOMException.INDEX_SIZE_ERR,
54                      "need.parent",
55                      new Object JavaDoc[] {});
56     }
57     String JavaDoc t1 = v.substring(offset);
58     Text JavaDoc t = createTextNode(t1);
59     Node JavaDoc 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     /**
70      * Creates a text node of the current type.
71      */

72     protected abstract Text JavaDoc createTextNode(String JavaDoc text);
73 }
74
Popular Tags