/** Send characters to the validator in CHUNK_SIZE character chunks. */ private void sendCharactersToSchemaParser(String str, boolean whitespace) { if (str != null) { final int length = str.length(); final int remainder = length & CHUNK_MASK; if (remainder > 0) { str.getChars(0, remainder, fCharBuffer, 0); fTempString.setValues(fCharBuffer, 0, remainder); if (whitespace) { fSchemaDOMParser.ignorableWhitespace(fTempString, null); } else { fSchemaDOMParser.characters(fTempString, null); } } int i = remainder; while (i < length) { str.getChars(i, i += CHUNK_SIZE, fCharBuffer, 0); fTempString.setValues(fCharBuffer, 0, CHUNK_SIZE); if (whitespace) { fSchemaDOMParser.ignorableWhitespace(fTempString, null); } else { fSchemaDOMParser.characters(fTempString, null); } } } }
public void parse(XMLStreamReader input) throws XMLStreamException, XNIException { if (input.hasNext()) { int eventType = input.getEventType(); if (eventType != XMLStreamConstants.START_DOCUMENT && eventType != XMLStreamConstants.START_ELEMENT) { throw new XMLStreamException(); } fLocationWrapper.setLocation(input.getLocation()); fSchemaDOMParser.startDocument(fLocationWrapper, null, fNamespaceContext, null); boolean first = true; loop: while (input.hasNext()) { if (!first) { eventType = input.next(); } else { first = false; } switch (eventType) { case XMLStreamConstants.START_ELEMENT: ++fDepth; fLocationWrapper.setLocation(input.getLocation()); fNamespaceContext.setNamespaceContext(input.getNamespaceContext()); fillQName( fElementQName, input.getNamespaceURI(), input.getLocalName(), input.getPrefix()); fillXMLAttributes(input); fillDeclaredPrefixes(input); addNamespaceDeclarations(); fNamespaceContext.pushContext(); fSchemaDOMParser.startElement(fElementQName, fAttributes, null); break; case XMLStreamConstants.END_ELEMENT: fLocationWrapper.setLocation(input.getLocation()); fNamespaceContext.setNamespaceContext(input.getNamespaceContext()); fillQName( fElementQName, input.getNamespaceURI(), input.getLocalName(), input.getPrefix()); fillDeclaredPrefixes(input); fSchemaDOMParser.endElement(fElementQName, null); fNamespaceContext.popContext(); --fDepth; if (fDepth <= 0) { break loop; } break; case XMLStreamConstants.CHARACTERS: fTempString.setValues( input.getTextCharacters(), input.getTextStart(), input.getTextLength()); fSchemaDOMParser.characters(fTempString, null); break; case XMLStreamConstants.SPACE: fTempString.setValues( input.getTextCharacters(), input.getTextStart(), input.getTextLength()); fSchemaDOMParser.ignorableWhitespace(fTempString, null); break; case XMLStreamConstants.CDATA: fSchemaDOMParser.startCDATA(null); fTempString.setValues( input.getTextCharacters(), input.getTextStart(), input.getTextLength()); fSchemaDOMParser.characters(fTempString, null); fSchemaDOMParser.endCDATA(null); break; case XMLStreamConstants.PROCESSING_INSTRUCTION: fillProcessingInstruction(input.getPIData()); fSchemaDOMParser.processingInstruction(input.getPITarget(), fTempString, null); break; case XMLStreamConstants.DTD: /* There shouldn't be a DTD in the schema */ break; case XMLStreamConstants.ENTITY_REFERENCE: /* Not needed for schemas */ break; case XMLStreamConstants.COMMENT: /* No point in sending comments */ break; case XMLStreamConstants.START_DOCUMENT: ++fDepth; /* We automatically call startDocument before the loop */ break; case XMLStreamConstants.END_DOCUMENT: /* We automatically call endDocument after the loop */ break; } } fLocationWrapper.setLocation(null); fNamespaceContext.setNamespaceContext(null); fSchemaDOMParser.endDocument(null); } }