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. package com.sun.org.apache.xerces.internal.impl.xs.opti;
  58. import org.w3c.dom.DOMException;
  59. import org.w3c.dom.Node;
  60. /*
  61. * @author Neil Graham, IBM
  62. * @version $Id: TextImpl.java,v 1.2 2003/07/04 13:47:49 mrglavas Exp $
  63. */
  64. public class TextImpl extends DefaultText {
  65. // Data
  66. String fData = null;
  67. SchemaDOM fSchemaDOM = null;
  68. int fRow;
  69. int fCol;
  70. public TextImpl(StringBuffer str, SchemaDOM sDOM, int row, int col) {
  71. fData = str.toString();
  72. fSchemaDOM = sDOM;
  73. fRow = row;
  74. fCol = col;
  75. rawname = prefix = localpart = uri = null;
  76. nodeType = Node.TEXT_NODE;
  77. }
  78. //
  79. // org.w3c.dom.Node methods
  80. //
  81. public Node getParentNode() {
  82. return fSchemaDOM.relations[fRow][0];
  83. }
  84. public Node getPreviousSibling() {
  85. if (fCol == 1) {
  86. return null;
  87. }
  88. return fSchemaDOM.relations[fRow][fCol-1];
  89. }
  90. public Node getNextSibling() {
  91. if (fCol == fSchemaDOM.relations[fRow].length-1) {
  92. return null;
  93. }
  94. return fSchemaDOM.relations[fRow][fCol+1];
  95. }
  96. // CharacterData methods
  97. /**
  98. * The character data of the node that implements this interface. The DOM
  99. * implementation may not put arbitrary limits on the amount of data
  100. * that may be stored in a <code>CharacterData</code> node. However,
  101. * implementation limits may mean that the entirety of a node's data may
  102. * not fit into a single <code>DOMString</code>. In such cases, the user
  103. * may call <code>substringData</code> to retrieve the data in
  104. * appropriately sized pieces.
  105. * @exception DOMException
  106. * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
  107. * @exception DOMException
  108. * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
  109. * fit in a <code>DOMString</code> variable on the implementation
  110. * platform.
  111. */
  112. public String getData()
  113. throws DOMException {
  114. return fData;
  115. }
  116. /**
  117. * The number of 16-bit units that are available through <code>data</code>
  118. * and the <code>substringData</code> method below. This may have the
  119. * value zero, i.e., <code>CharacterData</code> nodes may be empty.
  120. */
  121. public int getLength() {
  122. if(fData == null) return 0;
  123. return fData.length();
  124. }
  125. /**
  126. * Extracts a range of data from the node.
  127. * @param offset Start offset of substring to extract.
  128. * @param count The number of 16-bit units to extract.
  129. * @return The specified substring. If the sum of <code>offset</code> and
  130. * <code>count</code> exceeds the <code>length</code>, then all 16-bit
  131. * units to the end of the data are returned.
  132. * @exception DOMException
  133. * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
  134. * negative or greater than the number of 16-bit units in
  135. * <code>data</code>, or if the specified <code>count</code> is
  136. * negative.
  137. * <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text does
  138. * not fit into a <code>DOMString</code>.
  139. */
  140. public String substringData(int offset,
  141. int count)
  142. throws DOMException {
  143. if(fData == null) return null;
  144. if(count < 0 || offset < 0 || offset > fData.length())
  145. throw new DOMException(DOMException.INDEX_SIZE_ERR, "parameter error");
  146. if(offset+count >= fData.length())
  147. return fData.substring(offset);
  148. return fData.substring(offset, offset+count);
  149. }
  150. }