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