KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > impl > xs > opti > TextImpl


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
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
17 package org.apache.xerces.impl.xs.opti;
18
19 import org.w3c.dom.DOMException JavaDoc;
20 import org.w3c.dom.Node JavaDoc;
21
22 /**
23  * @xerces.internal
24  *
25  * @author Neil Graham, IBM
26  * @version $Id: TextImpl.java,v 1.4 2004/10/06 15:14:49 mrglavas Exp $
27  */

28
29 public class TextImpl extends DefaultText {
30
31     // Data
32
String JavaDoc fData = null;
33     SchemaDOM fSchemaDOM = null;
34     int fRow;
35     int fCol;
36
37     public TextImpl(StringBuffer JavaDoc str, SchemaDOM sDOM, int row, int col) {
38         fData = str.toString();
39         fSchemaDOM = sDOM;
40         fRow = row;
41         fCol = col;
42         rawname = prefix = localpart = uri = null;
43         nodeType = Node.TEXT_NODE;
44     }
45
46     //
47
// org.w3c.dom.Node methods
48
//
49

50     public Node JavaDoc getParentNode() {
51         return fSchemaDOM.relations[fRow][0];
52     }
53
54     public Node JavaDoc getPreviousSibling() {
55         if (fCol == 1) {
56             return null;
57         }
58         return fSchemaDOM.relations[fRow][fCol-1];
59     }
60
61
62     public Node JavaDoc getNextSibling() {
63         if (fCol == fSchemaDOM.relations[fRow].length-1) {
64             return null;
65         }
66         return fSchemaDOM.relations[fRow][fCol+1];
67     }
68
69     // CharacterData methods
70

71     /**
72      * The character data of the node that implements this interface. The DOM
73      * implementation may not put arbitrary limits on the amount of data
74      * that may be stored in a <code>CharacterData</code> node. However,
75      * implementation limits may mean that the entirety of a node's data may
76      * not fit into a single <code>DOMString</code>. In such cases, the user
77      * may call <code>substringData</code> to retrieve the data in
78      * appropriately sized pieces.
79      * @exception DOMException
80      * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
81      * @exception DOMException
82      * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
83      * fit in a <code>DOMString</code> variable on the implementation
84      * platform.
85      */

86     public String JavaDoc getData()
87                             throws DOMException JavaDoc {
88         return fData;
89     }
90
91     /**
92      * The number of 16-bit units that are available through <code>data</code>
93      * and the <code>substringData</code> method below. This may have the
94      * value zero, i.e., <code>CharacterData</code> nodes may be empty.
95      */

96     public int getLength() {
97         if(fData == null) return 0;
98         return fData.length();
99     }
100
101     /**
102      * Extracts a range of data from the node.
103      * @param offset Start offset of substring to extract.
104      * @param count The number of 16-bit units to extract.
105      * @return The specified substring. If the sum of <code>offset</code> and
106      * <code>count</code> exceeds the <code>length</code>, then all 16-bit
107      * units to the end of the data are returned.
108      * @exception DOMException
109      * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
110      * negative or greater than the number of 16-bit units in
111      * <code>data</code>, or if the specified <code>count</code> is
112      * negative.
113      * <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text does
114      * not fit into a <code>DOMString</code>.
115      */

116     public String JavaDoc substringData(int offset,
117                                 int count)
118                                 throws DOMException JavaDoc {
119         if(fData == null) return null;
120         if(count < 0 || offset < 0 || offset > fData.length())
121             throw new DOMException JavaDoc(DOMException.INDEX_SIZE_ERR, "parameter error");
122         if(offset+count >= fData.length())
123             return fData.substring(offset);
124         return fData.substring(offset, offset+count);
125     }
126
127 }
128
Popular Tags