KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 2001, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package com.sun.org.apache.xerces.internal.impl.xs.opti;
59
60 import org.w3c.dom.DOMException JavaDoc;
61 import org.w3c.dom.Node JavaDoc;
62
63 /*
64  * @author Neil Graham, IBM
65  * @version $Id: TextImpl.java,v 1.2 2003/07/04 13:47:49 mrglavas Exp $
66  */

67
68 public class TextImpl extends DefaultText {
69
70     // Data
71
String JavaDoc fData = null;
72     SchemaDOM fSchemaDOM = null;
73     int fRow;
74     int fCol;
75
76     public TextImpl(StringBuffer JavaDoc str, SchemaDOM sDOM, int row, int col) {
77         fData = str.toString();
78         fSchemaDOM = sDOM;
79         fRow = row;
80         fCol = col;
81         rawname = prefix = localpart = uri = null;
82         nodeType = Node.TEXT_NODE;
83     }
84
85     //
86
// org.w3c.dom.Node methods
87
//
88

89     public Node JavaDoc getParentNode() {
90         return fSchemaDOM.relations[fRow][0];
91     }
92
93     public Node JavaDoc getPreviousSibling() {
94         if (fCol == 1) {
95             return null;
96         }
97         return fSchemaDOM.relations[fRow][fCol-1];
98     }
99
100
101     public Node JavaDoc getNextSibling() {
102         if (fCol == fSchemaDOM.relations[fRow].length-1) {
103             return null;
104         }
105         return fSchemaDOM.relations[fRow][fCol+1];
106     }
107
108     // CharacterData methods
109

110     /**
111      * The character data of the node that implements this interface. The DOM
112      * implementation may not put arbitrary limits on the amount of data
113      * that may be stored in a <code>CharacterData</code> node. However,
114      * implementation limits may mean that the entirety of a node's data may
115      * not fit into a single <code>DOMString</code>. In such cases, the user
116      * may call <code>substringData</code> to retrieve the data in
117      * appropriately sized pieces.
118      * @exception DOMException
119      * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
120      * @exception DOMException
121      * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
122      * fit in a <code>DOMString</code> variable on the implementation
123      * platform.
124      */

125     public String JavaDoc getData()
126                             throws DOMException JavaDoc {
127         return fData;
128     }
129
130     /**
131      * The number of 16-bit units that are available through <code>data</code>
132      * and the <code>substringData</code> method below. This may have the
133      * value zero, i.e., <code>CharacterData</code> nodes may be empty.
134      */

135     public int getLength() {
136         if(fData == null) return 0;
137         return fData.length();
138     }
139
140     /**
141      * Extracts a range of data from the node.
142      * @param offset Start offset of substring to extract.
143      * @param count The number of 16-bit units to extract.
144      * @return The specified substring. If the sum of <code>offset</code> and
145      * <code>count</code> exceeds the <code>length</code>, then all 16-bit
146      * units to the end of the data are returned.
147      * @exception DOMException
148      * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
149      * negative or greater than the number of 16-bit units in
150      * <code>data</code>, or if the specified <code>count</code> is
151      * negative.
152      * <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text does
153      * not fit into a <code>DOMString</code>.
154      */

155     public String JavaDoc substringData(int offset,
156                                 int count)
157                                 throws DOMException JavaDoc {
158         if(fData == null) return null;
159         if(count < 0 || offset < 0 || offset > fData.length())
160             throw new DOMException JavaDoc(DOMException.INDEX_SIZE_ERR, "parameter error");
161         if(offset+count >= fData.length())
162             return fData.substring(offset);
163         return fData.substring(offset, offset+count);
164     }
165
166 }
167
Popular Tags