1 /*
2  * reserved comment block
3  * DO NOT REMOVE OR ALTER!
4  */
5 /*
6  * Copyright 2001-2004 The Apache Software Foundation.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 package com.sun.org.apache.xerces.internal.impl.xs.opti;
22 
23 import org.w3c.dom.DOMException;
24 import org.w3c.dom.Node;
25 
26 /**
27  * @xerces.internal
28  *
29  * @author Neil Graham, IBM
30  */
31 
32 public class TextImpl extends DefaultText {
33 
34     // Data
35     String fData = null;
36     SchemaDOM fSchemaDOM = null;
37     int fRow;
38     int fCol;
39 
TextImpl(StringBuffer str, SchemaDOM sDOM, int row, int col)40     public TextImpl(StringBuffer str, SchemaDOM sDOM, int row, int col) {
41         fData = str.toString();
42         fSchemaDOM = sDOM;
43         fRow = row;
44         fCol = col;
45         rawname = prefix = localpart = uri = null;
46         nodeType = Node.TEXT_NODE;
47     }
48 
49     //
50     // org.w3c.dom.Node methods
51     //
52 
getParentNode()53     public Node getParentNode() {
54         return fSchemaDOM.relations[fRow][0];
55     }
56 
getPreviousSibling()57     public Node getPreviousSibling() {
58         if (fCol == 1) {
59             return null;
60         }
61         return fSchemaDOM.relations[fRow][fCol-1];
62     }
63 
64 
getNextSibling()65     public Node getNextSibling() {
66         if (fCol == fSchemaDOM.relations[fRow].length-1) {
67             return null;
68         }
69         return fSchemaDOM.relations[fRow][fCol+1];
70     }
71 
72     // CharacterData methods
73 
74     /**
75      * The character data of the node that implements this interface. The DOM
76      * implementation may not put arbitrary limits on the amount of data
77      * that may be stored in a <code>CharacterData</code> node. However,
78      * implementation limits may mean that the entirety of a node's data may
79      * not fit into a single <code>DOMString</code>. In such cases, the user
80      * may call <code>substringData</code> to retrieve the data in
81      * appropriately sized pieces.
82      * @exception DOMException
83      *   NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
84      * @exception DOMException
85      *   DOMSTRING_SIZE_ERR: Raised when it would return more characters than
86      *   fit in a <code>DOMString</code> variable on the implementation
87      *   platform.
88      */
getData()89     public String getData()
90                             throws DOMException {
91         return fData;
92     }
93 
94     /**
95      * The number of 16-bit units that are available through <code>data</code>
96      * and the <code>substringData</code> method below. This may have the
97      * value zero, i.e., <code>CharacterData</code> nodes may be empty.
98      */
getLength()99     public int getLength() {
100         if(fData == null) return 0;
101         return fData.length();
102     }
103 
104     /**
105      * Extracts a range of data from the node.
106      * @param offset Start offset of substring to extract.
107      * @param count The number of 16-bit units to extract.
108      * @return The specified substring. If the sum of <code>offset</code> and
109      *   <code>count</code> exceeds the <code>length</code>, then all 16-bit
110      *   units to the end of the data are returned.
111      * @exception DOMException
112      *   INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
113      *   negative or greater than the number of 16-bit units in
114      *   <code>data</code>, or if the specified <code>count</code> is
115      *   negative.
116      *   <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text does
117      *   not fit into a <code>DOMString</code>.
118      */
substringData(int offset, int count)119     public String substringData(int offset,
120                                 int count)
121                                 throws DOMException {
122         if(fData == null) return null;
123         if(count < 0 || offset < 0 || offset > fData.length())
124             throw new DOMException(DOMException.INDEX_SIZE_ERR, "parameter error");
125         if(offset+count >= fData.length())
126             return fData.substring(offset);
127         return fData.substring(offset, offset+count);
128     }
129 
130 }
131