2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
package org.apache.xerces.impl.xs.opti;
20
import org.w3c.dom.DOMException;
21
import org.w3c.dom.Node;
26
* @author Neil Graham, IBM
27
* @version $Id: TextImpl.java,v 1.2 2009/12/10 03:18:27 matthewoliver Exp $
30
public class TextImpl extends DefaultText {
34
SchemaDOM fSchemaDOM = null;
38
public TextImpl(StringBuffer str, SchemaDOM sDOM, int row, int col) {
39
fData = str.toString();
43
rawname = prefix = localpart = uri = null;
44
nodeType = Node.TEXT_NODE;
48
// org.w3c.dom.Node methods
51
public Node getParentNode() {
52
return fSchemaDOM.relations[fRow][0];
55
public Node getPreviousSibling() {
59
return fSchemaDOM.relations[fRow][fCol-1];
63
public Node getNextSibling() {
64
if (fCol == fSchemaDOM.relations[fRow].length-1) {
67
return fSchemaDOM.relations[fRow][fCol+1];
70
// CharacterData methods
73
* The character data of the node that implements this interface. The DOM
74
* implementation may not put arbitrary limits on the amount of data
75
* that may be stored in a <code>CharacterData</code> node. However,
76
* implementation limits may mean that the entirety of a node's data may
77
* not fit into a single <code>DOMString</code>. In such cases, the user
78
* may call <code>substringData</code> to retrieve the data in
79
* appropriately sized pieces.
80
* @exception DOMException
81
* NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
82
* @exception DOMException
83
* DOMSTRING_SIZE_ERR: Raised when it would return more characters than
84
* fit in a <code>DOMString</code> variable on the implementation
87
public String getData()
93
* The number of 16-bit units that are available through <code>data</code>
94
* and the <code>substringData</code> method below. This may have the
95
* value zero, i.e., <code>CharacterData</code> nodes may be empty.
97
public int getLength() {
98
if(fData == null) return 0;
99
return fData.length();
103
* Extracts a range of data from the node.
104
* @param offset Start offset of substring to extract.
105
* @param count The number of 16-bit units to extract.
106
* @return The specified substring. If the sum of <code>offset</code> and
107
* <code>count</code> exceeds the <code>length</code>, then all 16-bit
108
* units to the end of the data are returned.
109
* @exception DOMException
110
* INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
111
* negative or greater than the number of 16-bit units in
112
* <code>data</code>, or if the specified <code>count</code> is
114
* <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text does
115
* not fit into a <code>DOMString</code>.
117
public String substringData(int offset,
119
throws DOMException {
120
if(fData == null) return null;
121
if(count < 0 || offset < 0 || offset > fData.length())
122
throw new DOMException(DOMException.INDEX_SIZE_ERR, "parameter error");
123
if(offset+count >= fData.length())
124
return fData.substring(offset);
125
return fData.substring(offset, offset+count);