neilg 2003/07/03 08:15:58 Modified: java/src/org/apache/xerces/impl/xs/opti ElementImpl.java SchemaDOM.java SchemaDOMParser.java Added: java/src/org/apache/xerces/impl/xs/opti DefaultText.java TextImpl.java Log: add representations of annotations as Text-node children to the first child of an annotation element. The complete annotation is stored as a string, with all in-scope namespaces from ancestor elements. This allows for minimal schema-correctness checking in the schema-parsing code, while giving the annotation implementation full access to a representation of what was included in the schema Revision Changes Path 1.4 +2 -2 xml-xerces/java/src/org/apache/xerces/impl/xs/opti/ElementImpl.java Index: ElementImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/opti/ElementImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ElementImpl.java 8 May 2003 20:11:56 -0000 1.3 +++ ElementImpl.java 3 Jul 2003 15:15:58 -0000 1.4 @@ -267,4 +267,4 @@ return column; } -} \ No newline at end of file +} 1.4 +158 -23 xml-xerces/java/src/org/apache/xerces/impl/xs/opti/SchemaDOM.java Index: SchemaDOM.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/opti/SchemaDOM.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SchemaDOM.java 8 May 2003 20:11:57 -0000 1.3 +++ SchemaDOM.java 3 Jul 2003 15:15:58 -0000 1.4 @@ -2,7 +2,7 @@ * The Apache Software License, Version 1.1 * * - * Copyright (c) 2001, 2002 The Apache Software Foundation. All rights + * Copyright (c) 2001-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -57,16 +57,19 @@ package org.apache.xerces.impl.xs.opti; -import org.apache.xerces.xni.Augmentations; +import org.apache.xerces.xni.NamespaceContext; import org.apache.xerces.xni.QName; import org.apache.xerces.xni.XMLAttributes; import org.apache.xerces.xni.XMLString; -import org.apache.xerces.xni.XNIException; +import org.apache.xerces.util.XMLSymbols; import org.w3c.dom.Attr; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; +import java.util.Vector; +import java.util.Enumeration; + /** * @author Rahul Srivastava, Sun Microsystems Inc. * @author Sandy Gao, IBM @@ -78,35 +81,38 @@ static final int relationsRowResizeFactor = 15; static final int relationsColResizeFactor = 10; - ElementImpl[][] relations; + NodeImpl[][] relations; + // parent must be an element in this scheme ElementImpl parent; int currLoc; int nextFreeLoc; boolean hidden; + // for annotation support: + StringBuffer fAnnotationBuffer = null; public SchemaDOM() { reset(); } - public void startElement(QName element, XMLAttributes attributes, Augmentations augs, - int line, int column) throws XNIException { + public void startElement(QName element, XMLAttributes attributes, + int line, int column) { ElementImpl node = new ElementImpl(line, column); - processElement(element, attributes, augs, node); + processElement(element, attributes, node); // now the current node added, becomes the parent parent = node; } - public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs, - int line, int column) throws XNIException { + public void emptyElement(QName element, XMLAttributes attributes, + int line, int column) { ElementImpl node = new ElementImpl(line, column); - processElement(element, attributes, augs, node); + processElement(element, attributes, node); } - private void processElement(QName element, XMLAttributes attributes, Augmentations augs, ElementImpl node) throws XNIException { + private void processElement(QName element, XMLAttributes attributes, ElementImpl node) { // populate node node.prefix = element.prefix; @@ -160,30 +166,92 @@ } - public void endElement(QName element, Augmentations augs) throws XNIException { + public void endElement() { // the parent of current parent node becomes the parent // for the next node. currLoc = parent.row; - parent = relations[currLoc][0]; + parent = (ElementImpl)relations[currLoc][0]; } + // note that this will only be called within appinfo/documentation + void comment(XMLString text) { + fAnnotationBuffer.append("<!--").append(text.toString()).append("-->"); + } + + // note that this will only be called within appinfo/documentation + void processingInstruction(String target, String data) { + fAnnotationBuffer.append("<?").append(target).append(" ").append(data).append("?>"); + } - public void characters(XMLString text, Augmentations augs) throws XNIException { - // REVISIT: Make a text node. + // note that this will only be called within appinfo/documentation + void characters(XMLString text ) { + // need to handle &s and <s + for(int i=text.offset; i<text.offset+text.length; i++ ) { + if(text.ch[i] == '&') { + fAnnotationBuffer.append("&"); + } else if (text.ch[i] == '<') { + fAnnotationBuffer.append("<"); + } else { + fAnnotationBuffer.append(text.ch[i]); + } + } + } + + void endAnnotationElement(QName elemName, boolean complete) { + if(complete) { + fAnnotationBuffer.append("\n</").append(elemName.rawname).append(">"); + // note that this is always called after endElement on <annotation>'s + // child and before endElement on annotation. + // hence, we must make this the child of the current + // parent's only child. + ElementImpl child = (ElementImpl)relations[currLoc][1]; + + // check if array needs to be resized + if (nextFreeLoc == relations.length) { + resizeRelations(); + } + int newRow = child.parentRow = nextFreeLoc++; + + // now find the place to insert this node + boolean foundPlace = false; + int i = 1; + for (; i<relations[newRow].length; i++) { + if (relations[newRow][i] == null) { + foundPlace = true; + break; + } + } + + if (!foundPlace) { + resizeRelations(newRow); + } + relations[newRow][i] = new TextImpl(fAnnotationBuffer, this, newRow, i); + // apparently, there is no sensible way of resetting + // these things + fAnnotationBuffer = null; + } else //capturing character calls + fAnnotationBuffer.append("</").append(elemName.rawname).append(">"); + } + + void startAnnotationCDATA() { + fAnnotationBuffer.append("<![CDATA["); } + void endAnnotationCDATA() { + fAnnotationBuffer.append("]]>"); + } private void resizeRelations() { - ElementImpl[][] temp = new ElementImpl[relations.length+relationsRowResizeFactor][]; + NodeImpl[][] temp = new NodeImpl[relations.length+relationsRowResizeFactor][]; System.arraycopy(relations, 0, temp, 0, relations.length); for (int i = relations.length ; i < temp.length ; i++) { - temp[i] = new ElementImpl[relationsColResizeFactor]; + temp[i] = new NodeImpl[relationsColResizeFactor]; } relations = temp; } private void resizeRelations(int i) { - ElementImpl[] temp = new ElementImpl[relations[i].length+relationsColResizeFactor]; + NodeImpl[] temp = new NodeImpl[relations[i].length+relationsColResizeFactor]; System.arraycopy(relations[i], 0, temp, 0, relations[i].length); relations[i] = temp; } @@ -191,13 +259,18 @@ public void reset() { - relations = new ElementImpl[relationsRowResizeFactor][]; + // help out the garbage collector + if(relations != null) + for(int i=0; i<relations.length; i++) + for(int j=0; j<relations[i].length; j++) + relations[i][j] = null; + relations = new NodeImpl[relationsRowResizeFactor][]; parent = new ElementImpl(0, 0); parent.rawname = "DOCUMENT_NODE"; currLoc = 0; nextFreeLoc = 1; for (int i=0; i<relationsRowResizeFactor; i++) { - relations[i] = new ElementImpl[relationsColResizeFactor]; + relations[i] = new NodeImpl[relationsColResizeFactor]; } relations[currLoc][0] = parent; } @@ -256,7 +329,69 @@ // org.w3c.dom methods public Element getDocumentElement() { - return relations[0][1]; + // this returns a parent node, known to be an ElementImpl + return (ElementImpl)relations[0][1]; } -} \ No newline at end of file + // commence the serialization of an annotation + void startAnnotation(QName elemName, XMLAttributes attributes, + NamespaceContext namespaceContext) { + if(fAnnotationBuffer == null) fAnnotationBuffer = new StringBuffer(256); + fAnnotationBuffer.append("<").append(elemName.rawname).append(" "); + + // attributes are a bit of a pain. To get this right, we have to keep track + // of the namespaces we've seen declared, then examine the namespace context + // for other namespaces so that we can also include them. + // optimized for simplicity and the case that not many + // namespaces are declared on this annotation... + Vector namespaces = new Vector(); + for(int i=0; i<attributes.getLength(); i++) { + String aValue = attributes.getValue(i); + String aPrefix = attributes.getPrefix(i); + // if it's xmlns, must be a namespace decl + namespaces.addElement(aValue); + fAnnotationBuffer.append(attributes.getQName(i)).append("=\"").append(aValue).append("\" "); + } + // now we have to look through currently in-scope namespaces to see what + // wasn't declared here + Enumeration currPrefixes = namespaceContext.getAllPrefixes(); + while(currPrefixes.hasMoreElements()) { + String prefix = (String)currPrefixes.nextElement(); + String uri = namespaceContext.getURI(prefix); + if(!namespaces.contains(uri)) { + // have to declare this one + if(prefix == XMLSymbols.EMPTY_STRING) + fAnnotationBuffer.append("xmlns").append("=\"").append(uri).append("\" "); + else + fAnnotationBuffer.append("xmlns:").append(prefix).append("=\"").append(uri).append("\" "); + } + } + fAnnotationBuffer.append(">\n"); + } + void startAnnotationElement(QName elemName, XMLAttributes attributes) { + fAnnotationBuffer.append("<").append(elemName.rawname).append(" "); + for(int i=0; i<attributes.getLength(); i++) { + String aValue = attributes.getValue(i); + fAnnotationBuffer.append(" ").append(attributes.getQName(i)).append("=\"").append(processAttValue(aValue)).append("\" "); + } + fAnnotationBuffer.append(">"); + } + + private static String processAttValue(String original) { + // normally, nothing will happen + StringBuffer newVal = new StringBuffer(original.length()); + for(int i=0; i<original.length(); i++) { + char currChar = original.charAt(i); + if(currChar == '"') { + newVal.append("""); + } else if (currChar == '>') { + newVal.append(">"); + } else if (currChar == '&') { + newVal.append("&"); + } else { + newVal.append(currChar); + } + } + return newVal.toString(); + } +} 1.4 +150 -27 xml-xerces/java/src/org/apache/xerces/impl/xs/opti/SchemaDOMParser.java Index: SchemaDOMParser.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/opti/SchemaDOMParser.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SchemaDOMParser.java 8 May 2003 20:11:57 -0000 1.3 +++ SchemaDOMParser.java 3 Jul 2003 15:15:58 -0000 1.4 @@ -2,7 +2,7 @@ * The Apache Software License, Version 1.1 * * - * Copyright (c) 2001, 2002 The Apache Software Foundation. All rights + * Copyright (c) 2001-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -92,6 +92,10 @@ // the locator containing line/column information protected XMLLocator fLocator; + // namespace context, needed for producing + // representations of annotations + protected NamespaceContext fNamespaceContext = null; + SchemaDOM schemaDOM; XMLParserConfiguration config; @@ -106,10 +110,12 @@ this.config = config; } - + // where an annotation element itself begins + // -1 means not in an annotation's scope + private int fAnnotationDepth = -1; // Where xs:appinfo or xs:documentation starts; // -1 means not in the scope of either of the two elements. - private int fAnnotationDepth = -1; + private int fInnerAnnotationDepth = -1; // The current element depth private int fDepth = -1; // Use to report the error when characters are not allowed. @@ -124,7 +130,8 @@ NamespaceContext namespaceContext, Augmentations augs) throws XNIException { fLocator = locator; - } // startDocument(XMLLocator,String,Augmentations) + fNamespaceContext = namespaceContext; + } // startDocument(XMLLocator,String,NamespaceContext, Augmentations) /** * The end of the document. @@ -133,12 +140,52 @@ * @throws XNIException Thrown by handler to signal an error. */ public void endDocument(Augmentations augs) throws XNIException { - // To debug the DOM created uncomment the line below - // schemaDOM.printDOM(); + // To debug the DOM created uncomment the line below + // schemaDOM.printDOM(); } // endDocument() /** + * A comment. + * + * @param text The text in the comment. + * @param augs Additional information that may include infoset augmentations + * + * @exception XNIException + * Thrown by application to signal an error. + */ + public void comment(XMLString text, Augmentations augs) throws XNIException { + if(fAnnotationDepth > -1) { + schemaDOM.comment(text); + } + } + + /** + * A processing instruction. Processing instructions consist of a + * target name and, optionally, text data. The data is only meaningful + * to the application. + * <p> + * Typically, a processing instruction's data will contain a series + * of pseudo-attributes. These pseudo-attributes follow the form of + * element attributes but are <strong>not</strong> parsed or presented + * to the application as anything other than text. The application is + * responsible for parsing the data. + * + * @param target The target. + * @param data The data or null if none specified. + * @param augs Additional information that may include infoset augmentations + * + * @exception XNIException + * Thrown by handler to signal an error. + */ + public void processingInstruction(String target, XMLString data, Augmentations augs) + throws XNIException { + if(fAnnotationDepth > -1) { + schemaDOM.processingInstruction(target, data.toString()); + } + } + + /** * Character content. * * @param text The content. @@ -149,7 +196,7 @@ */ public void characters(XMLString text, Augmentations augs) throws XNIException { // when it's not within xs:appinfo or xs:documentation - if (fAnnotationDepth == -1) { + if (fInnerAnnotationDepth == -1 ) { for (int i=text.offset; i<text.offset+text.length; i++) { // and there is a non-whitespace character if (!XMLChar.isSpace(text.ch[i])) { @@ -182,7 +229,7 @@ // when it's within either of the 2 elements, characters are allowed // and we need to store them. else { - schemaDOM.characters(text, augs); + schemaDOM.characters(text); } } @@ -201,21 +248,29 @@ public void startElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException { - schemaDOM.startElement(element, attributes, augs, - fLocator.getLineNumber(), - fLocator.getColumnNumber()); - fDepth++; - // if it's not within either element, check whether it's one of them - // if so, record the current depth, so that any element with larger - // depth is allowed to have character data. + // while it is true that non-whitespace character data + // may only occur in appInfo or documentation + // elements, it's certainly legal for comments and PI's to + // occur as children of annotation; we need + // to account for these here. if (fAnnotationDepth == -1) { if (element.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA && - (element.localpart == SchemaSymbols.ELT_APPINFO || - element.localpart == SchemaSymbols.ELT_DOCUMENTATION)) { + element.localpart == SchemaSymbols.ELT_ANNOTATION) { fAnnotationDepth = fDepth; - } + schemaDOM.startAnnotation(element, attributes, fNamespaceContext); + } + } else if(fDepth == fAnnotationDepth+1) { + fInnerAnnotationDepth = fDepth; + schemaDOM.startAnnotationElement(element, attributes); + } else { + schemaDOM.startAnnotationElement(element, attributes); + // avoid falling through; don't call startElement in this case + return; } + schemaDOM.startElement(element, attributes, + fLocator.getLineNumber(), + fLocator.getColumnNumber()); } @@ -233,7 +288,18 @@ public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException { - schemaDOM.emptyElement(element, attributes, augs, + if (fAnnotationDepth == -1) { + // this is messed up, but a case to consider: + if (element.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA && + element.localpart == SchemaSymbols.ELT_ANNOTATION) { + schemaDOM.startAnnotation(element, attributes, fNamespaceContext); + schemaDOM.endAnnotationElement(element, true); + } + } else { + schemaDOM.startAnnotationElement(element, attributes); + schemaDOM.endAnnotationElement(element, false); + } + schemaDOM.emptyElement(element, attributes, fLocator.getLineNumber(), fLocator.getColumnNumber()); @@ -251,15 +317,72 @@ */ public void endElement(QName element, Augmentations augs) throws XNIException { - schemaDOM.endElement(element, augs); - // when we reach the endElement of xs:appinfo or xs:documentation, - // change fAnnotationDepth to -1 - if (fAnnotationDepth == fDepth) - fAnnotationDepth = -1; - fDepth--; + // when we reach the endElement of xs:appinfo or xs:documentation, + // change fInnerAnnotationDepth to -1 + if(fAnnotationDepth > -1) { + if (fInnerAnnotationDepth == fDepth) { + fInnerAnnotationDepth = -1; + schemaDOM.endAnnotationElement(element, false); + schemaDOM.endElement(); + } else if (fAnnotationDepth == fDepth) { + fAnnotationDepth = -1; + schemaDOM.endAnnotationElement(element, true); + schemaDOM.endElement(); + } else { // inside a child of annotation + schemaDOM.endAnnotationElement(element, false); + } + } else { // not in an annotation at all + schemaDOM.endElement(); + } + fDepth--; } + /** + * Ignorable whitespace. For this method to be called, the document + * source must have some way of determining that the text containing + * only whitespace characters should be considered ignorable. For + * example, the validator can determine if a length of whitespace + * characters in the document are ignorable based on the element + * content model. + * + * @param text The ignorable whitespace. + * @param augs Additional information that may include infoset augmentations + * + * @exception XNIException + * Thrown by handler to signal an error. + */ + public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException { + // unlikely to be called, but you never know... + if (fAnnotationDepth != -1 ) { + schemaDOM.characters(text); + } + } + + /** + * The start of a CDATA section. + * + * @param augs Additional information that may include infoset augmentations + * + * @exception XNIException + * Thrown by handler to signal an error. + */ + public void startCDATA(Augmentations augs) throws XNIException { + schemaDOM.startAnnotationCDATA(); + } + + /** + * The end of a CDATA section. + * + * @param augs Additional information that may include infoset augmentations + * + * @exception XNIException + * Thrown by handler to signal an error. + */ + public void endCDATA(Augmentations augs) throws XNIException { + schemaDOM.endAnnotationCDATA(); + } + // // other methods @@ -272,4 +395,4 @@ return schemaDOM; } -} \ No newline at end of file +} 1.1 xml-xerces/java/src/org/apache/xerces/impl/xs/opti/DefaultText.java Index: DefaultText.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Xerces" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation and was * originally based on software copyright (c) 2001, International * Business Machines, Inc., http://www.apache.org. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.xerces.impl.xs.opti; import org.w3c.dom.Text; import org.w3c.dom.DOMException; /* * @author Neil Graham, IBM * @version $Id: DefaultText.java,v 1.1 2003/07/03 15:15:58 neilg Exp $ */ /** * The <code>Text</code> interface inherits from <code>CharacterData</code> * and represents the textual content (termed character data in XML) of an * <code>Element</code> or <code>Attr</code>. If there is no markup inside * an element's content, the text is contained in a single object * implementing the <code>Text</code> interface that is the only child of * the element. If there is markup, it is parsed into the information items * (elements, comments, etc.) and <code>Text</code> nodes that form the list * of children of the element. * <p>When a document is first made available via the DOM, there is only one * <code>Text</code> node for each block of text. Users may create adjacent * <code>Text</code> nodes that represent the contents of a given element * without any intervening markup, but should be aware that there is no way * to represent the separations between these nodes in XML or HTML, so they * will not (in general) persist between DOM editing sessions. The * <code>normalize()</code> method on <code>Node</code> merges any such * adjacent <code>Text</code> objects into a single node for each block of * text. * <p>See also the <a href='http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113'>Document Object Model (DOM) Level 2 Core Specification</a>. * * This is an empty implementation. */ public class DefaultText extends NodeImpl implements Text { // CharacterData methods /** * The character data of the node that implements this interface. The DOM * implementation may not put arbitrary limits on the amount of data * that may be stored in a <code>CharacterData</code> node. However, * implementation limits may mean that the entirety of a node's data may * not fit into a single <code>DOMString</code>. In such cases, the user * may call <code>substringData</code> to retrieve the data in * appropriately sized pieces. * @exception DOMException * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly. * @exception DOMException * DOMSTRING_SIZE_ERR: Raised when it would return more characters than * fit in a <code>DOMString</code> variable on the implementation * platform. */ public String getData() throws DOMException { return null; } /** * The character data of the node that implements this interface. The DOM * implementation may not put arbitrary limits on the amount of data * that may be stored in a <code>CharacterData</code> node. However, * implementation limits may mean that the entirety of a node's data may * not fit into a single <code>DOMString</code>. In such cases, the user * may call <code>substringData</code> to retrieve the data in * appropriately sized pieces. * @exception DOMException * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly. * @exception DOMException * DOMSTRING_SIZE_ERR: Raised when it would return more characters than * fit in a <code>DOMString</code> variable on the implementation * platform. */ public void setData(String data) throws DOMException { throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); } /** * The number of 16-bit units that are available through <code>data</code> * and the <code>substringData</code> method below. This may have the * value zero, i.e., <code>CharacterData</code> nodes may be empty. */ public int getLength() { return 0; } /** * Extracts a range of data from the node. * @param offset Start offset of substring to extract. * @param count The number of 16-bit units to extract. * @return The specified substring. If the sum of <code>offset</code> and * <code>count</code> exceeds the <code>length</code>, then all 16-bit * units to the end of the data are returned. * @exception DOMException * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is * negative or greater than the number of 16-bit units in * <code>data</code>, or if the specified <code>count</code> is * negative. * <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text does * not fit into a <code>DOMString</code>. */ public String substringData(int offset, int count) throws DOMException { throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); } /** * Append the string to the end of the character data of the node. Upon * success, <code>data</code> provides access to the concatenation of * <code>data</code> and the <code>DOMString</code> specified. * @param arg The <code>DOMString</code> to append. * @exception DOMException * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. */ public void appendData(String arg) throws DOMException { throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); } /** * Insert a string at the specified 16-bit unit offset. * @param offset The character offset at which to insert. * @param arg The <code>DOMString</code> to insert. * @exception DOMException * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is * negative or greater than the number of 16-bit units in * <code>data</code>. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. */ public void insertData(int offset, String arg) throws DOMException { throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); } /** * Remove a range of 16-bit units from the node. Upon success, * <code>data</code> and <code>length</code> reflect the change. * @param offset The offset from which to start removing. * @param count The number of 16-bit units to delete. If the sum of * <code>offset</code> and <code>count</code> exceeds * <code>length</code> then all 16-bit units from <code>offset</code> * to the end of the data are deleted. * @exception DOMException * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is * negative or greater than the number of 16-bit units in * <code>data</code>, or if the specified <code>count</code> is * negative. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. */ public void deleteData(int offset, int count) throws DOMException { throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); } /** * Replace the characters starting at the specified 16-bit unit offset * with the specified string. * @param offset The offset from which to start replacing. * @param count The number of 16-bit units to replace. If the sum of * <code>offset</code> and <code>count</code> exceeds * <code>length</code>, then all 16-bit units to the end of the data * are replaced; (i.e., the effect is the same as a <code>remove</code> * method call with the same range, followed by an <code>append</code> * method invocation). * @param arg The <code>DOMString</code> with which the range must be * replaced. * @exception DOMException * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is * negative or greater than the number of 16-bit units in * <code>data</code>, or if the specified <code>count</code> is * negative. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. */ public void replaceData(int offset, int count, String arg) throws DOMException { throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); } // Text node methods /** * Breaks this node into two nodes at the specified <code>offset</code>, * keeping both in the tree as siblings. After being split, this node * will contain all the content up to the <code>offset</code> point. A * new node of the same type, which contains all the content at and * after the <code>offset</code> point, is returned. If the original * node had a parent node, the new node is inserted as the next sibling * of the original node. When the <code>offset</code> is equal to the * length of this node, the new node has no data. * @param offset The 16-bit unit offset at which to split, starting from * <code>0</code>. * @return The new node, of the same type as this node. * @exception DOMException * INDEX_SIZE_ERR: Raised if the specified offset is negative or greater * than the number of 16-bit units in <code>data</code>. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. */ public Text splitText(int offset) throws DOMException { throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); } } 1.1 xml-xerces/java/src/org/apache/xerces/impl/xs/opti/TextImpl.java Index: TextImpl.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Xerces" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation and was * originally based on software copyright (c) 2001, International * Business Machines, Inc., http://www.apache.org. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.xerces.impl.xs.opti; import org.w3c.dom.DOMException; import org.w3c.dom.Node; /* * @author Neil Graham, IBM * @version $Id: TextImpl.java,v 1.1 2003/07/03 15:15:58 neilg Exp $ */ public class TextImpl extends DefaultText { // Data String fData = null; SchemaDOM fSchemaDOM = null; int fRow; int fCol; public TextImpl(StringBuffer str, SchemaDOM sDOM, int row, int col) { fData = str.toString(); fSchemaDOM = sDOM; fRow = row; fCol = col; rawname = prefix = localpart = uri = null; nodeType = Node.TEXT_NODE; } // // org.w3c.dom.Node methods // public Node getParentNode() { return fSchemaDOM.relations[fRow][0]; } public Node getPreviousSibling() { if (fCol == 1) { return null; } return fSchemaDOM.relations[fRow][fCol-1]; } public Node getNextSibling() { if (fCol == fSchemaDOM.relations[fRow].length-1) { return null; } return fSchemaDOM.relations[fRow][fCol+1]; } // CharacterData methods /** * The character data of the node that implements this interface. The DOM * implementation may not put arbitrary limits on the amount of data * that may be stored in a <code>CharacterData</code> node. However, * implementation limits may mean that the entirety of a node's data may * not fit into a single <code>DOMString</code>. In such cases, the user * may call <code>substringData</code> to retrieve the data in * appropriately sized pieces. * @exception DOMException * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly. * @exception DOMException * DOMSTRING_SIZE_ERR: Raised when it would return more characters than * fit in a <code>DOMString</code> variable on the implementation * platform. */ public String getData() throws DOMException { return fData; } /** * The number of 16-bit units that are available through <code>data</code> * and the <code>substringData</code> method below. This may have the * value zero, i.e., <code>CharacterData</code> nodes may be empty. */ public int getLength() { if(fData == null) return 0; return fData.length();; } /** * Extracts a range of data from the node. * @param offset Start offset of substring to extract. * @param count The number of 16-bit units to extract. * @return The specified substring. If the sum of <code>offset</code> and * <code>count</code> exceeds the <code>length</code>, then all 16-bit * units to the end of the data are returned. * @exception DOMException * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is * negative or greater than the number of 16-bit units in * <code>data</code>, or if the specified <code>count</code> is * negative. * <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text does * not fit into a <code>DOMString</code>. */ public String substringData(int offset, int count) throws DOMException { if(fData == null) return null; if(count < 0 || offset < 0 || offset > fData.length()) throw new DOMException(DOMException.INDEX_SIZE_ERR, "parameter error"); if(offset+count >= fData.length()) return fData.substring(offset); return fData.substring(offset, offset+count); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]