001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.xml.text.syntax.dom;
043:
044: import org.w3c.dom.*;
045: import org.netbeans.modules.xml.text.syntax.*;
046: import org.netbeans.modules.xml.spi.dom.*;
047: import org.netbeans.editor.*;
048:
049: /**
050: * DOM Text implementation. Note that it is automatically
051: * coalesced with <code>Text</code> siblings.
052: * <p>
053: * The implementation handles differently content and attribute
054: * text nodes because there is no syntax element for attribute.
055: *
056: * @author Petr Kuzel
057: */
058: public class TextImpl extends SyntaxNode implements Text {
059:
060: // if attribute text node then parent otherwise null
061: private AttrImpl parent;
062:
063: /**
064: * Create content text node.
065: */
066: public TextImpl(XMLSyntaxSupport support, TokenItem from, int to) {
067: super (support, from, to);
068: }
069:
070: /**
071: * Create attribute text node.
072: */
073: TextImpl(XMLSyntaxSupport syntax, TokenItem from, AttrImpl parent) {
074: super (syntax, from, 0);
075: if (parent == null)
076: throw new IllegalArgumentException();
077: this .parent = parent;
078: }
079:
080: /**
081: * Get parent node. For content text nodes may be <code>null</code>
082: */
083: public Node getParentNode() {
084: if (parent != null) {
085: return parent;
086: } else {
087: return super .getParentNode();
088: }
089: }
090:
091: public Node getPreviousSibling() {
092: if (parent == null)
093: return super .getPreviousSibling();
094: return parent.getPreviousSibling(this );
095: }
096:
097: public Node getNextSibling() {
098: if (parent == null)
099: return super .getNextSibling();
100: return parent.getNextSibling(this );
101: }
102:
103: public short getNodeType() {
104: return Node.TEXT_NODE;
105: }
106:
107: public String getNodeValue() {
108: return getData();
109: }
110:
111: public Text splitText(int offset) {
112: throw new ROException();
113: }
114:
115: public String getData() {
116: return first().getImage();
117: }
118:
119: public void setData(String data) {
120: throw new ROException();
121: }
122:
123: public int getLength() {
124: return getData().length();
125: }
126:
127: public String substringData(int offset, int count) {
128: return getData().substring(offset, offset + count + 1);
129: }
130:
131: public void appendData(String arg) {
132: throw new ROException();
133: }
134:
135: public void insertData(int offset, String arg) {
136: throw new ROException();
137: }
138:
139: public void deleteData(int offset, int count) {
140: throw new ROException();
141: }
142:
143: public void replaceData(int offset, int count, String arg) {
144: throw new ROException();
145: }
146:
147: /**
148: * Dump content of the nod efor debug purposes.
149: */
150: public String toString() {
151: return "Text" + super .toString() + " value: '" + getNodeValue()
152: + "'";
153: }
154:
155: }
|