001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.xml;
030:
031: import org.w3c.dom.DOMException;
032: import org.w3c.dom.Node;
033: import org.w3c.dom.Text;
034:
035: /**
036: * Represents a text node.
037: */
038: public class QText extends QCharacterData implements Text {
039: /**
040: * Creates a new text node.
041: */
042: public QText() {
043: super ();
044: }
045:
046: /**
047: * Creates a new text node with initial data.
048: */
049: public QText(String data) {
050: super (data);
051: }
052:
053: public String getNodeName() {
054: return "#text";
055: }
056:
057: public short getNodeType() {
058: return TEXT_NODE;
059: }
060:
061: Node importNode(QDocument owner, boolean deep) {
062: QText text = new QText(_data);
063: text._owner = owner;
064: text._filename = _filename;
065: text._line = _line;
066: return text;
067: }
068:
069: public Text splitText(int offset) throws DOMException {
070: QText text = new QText(_data.substring(offset));
071: text._owner = _owner;
072:
073: _data = _data.substring(0, offset);
074:
075: text._parent = _parent;
076: if (_next != null)
077: _next._previous = text;
078: else if (_parent != null)
079: _parent._lastChild = text;
080: text._previous = this ;
081: text._next = _next;
082: _next = text;
083:
084: return text;
085: }
086:
087: public Text joinText(Text node1, Text node2) throws DOMException {
088: return new QText(node1.getData() + node2.getData());
089: }
090:
091: // DOM level 3
092: public boolean getIsWhitespaceInElementContent() {
093: throw new UnsupportedOperationException();
094: }
095:
096: public String getWholeText() {
097: throw new UnsupportedOperationException();
098: }
099:
100: public Text replaceWholeText(String content) throws DOMException {
101: throw new UnsupportedOperationException();
102: }
103:
104: private Object writeReplace() {
105: return new SerializedXml(this );
106: }
107:
108: public String toString() {
109: return "Text[" + getData() + "]";
110: }
111: }
|