1/* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package org.apache.harmony.xml.dom; 18 19import org.w3c.dom.DOMException; 20import org.w3c.dom.Document; 21import org.w3c.dom.Node; 22import org.w3c.dom.Text; 23 24/** 25 * Provides a straightforward implementation of the corresponding W3C DOM 26 * interface. The class is used internally only, thus only notable members that 27 * are not in the original interface are documented (the W3C docs are quite 28 * extensive). Hope that's ok. 29 * <p> 30 * Some of the fields may have package visibility, so other classes belonging to 31 * the DOM implementation can easily access them while maintaining the DOM tree 32 * structure. 33 */ 34public class TextImpl extends CharacterDataImpl implements Text { 35 36 TextImpl(DocumentImpl document, String data) { 37 super(document, data); 38 } 39 40 @Override 41 public String getNodeName() { 42 return "#text"; 43 } 44 45 @Override 46 public short getNodeType() { 47 return Node.TEXT_NODE; 48 } 49 50 @Override 51 public String getNodeValue() { 52 return getData(); 53 } 54 55 public Text splitText(int offset) throws DOMException { 56 Text newText = getOwnerDocument().createTextNode( 57 substringData(offset, getLength() - offset)); 58 deleteData(0, offset); 59 60 Node refNode = getNextSibling(); 61 if (refNode == null) { 62 getParentNode().appendChild(newText); 63 } else { 64 getParentNode().insertBefore(newText, refNode); 65 } 66 67 return this; 68 } 69 70} 71