if (fParseInProgress) { // REVISIT - need to add new error message thrownewXNIException("FWK005 parse may not be called while parsing."); } fParseInProgress = true;
try { setInputSource(source); #将输入流赋值给fInputSource parse(true); } catch (XNIException ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw ex; } catch (IOException ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw ex; } catch (RuntimeException ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw ex; } catch (Exception ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); thrownewXNIException(ex); } finally { fParseInProgress = false; // close all streams opened by xerces this.cleanup(); }
// keep dispatching "events" fEntityManager.setEntityHandler(this); //System.out.println(" get Document Handler in NSDocumentHandler " + fDocumentHandler );
intevent= next(); do { switch (event) { case XMLStreamConstants.START_DOCUMENT : //fDocumentHandler.startDocument(fEntityManager.getEntityScanner(),fEntityManager.getEntityScanner().getVersion(),fNamespaceContext,null);// not able to get break; case XMLStreamConstants.START_ELEMENT : //System.out.println(" in scann element"); //fDocumentHandler.startElement(getElementQName(),fAttributes,null); break; case XMLStreamConstants.CHARACTERS : fEntityScanner.checkNodeCount(fEntityScanner.fCurrentEntity); fDocumentHandler.characters(getCharacterData(),null); break; case XMLStreamConstants.SPACE: //check if getCharacterData() is the right function to retrieve ignorableWhitespace information. //System.out.println("in the space"); //fDocumentHandler.ignorableWhitespace(getCharacterData(), null); break; case XMLStreamConstants.ENTITY_REFERENCE : fEntityScanner.checkNodeCount(fEntityScanner.fCurrentEntity); //entity reference callback are given in startEntity break; case XMLStreamConstants.PROCESSING_INSTRUCTION : fEntityScanner.checkNodeCount(fEntityScanner.fCurrentEntity); fDocumentHandler.processingInstruction(getPITarget(),getPIData(),null); break; case XMLStreamConstants.COMMENT : fEntityScanner.checkNodeCount(fEntityScanner.fCurrentEntity); fDocumentHandler.comment(getCharacterData(),null); break; case XMLStreamConstants.DTD : //all DTD related callbacks are handled in DTDScanner. //1. Stax doesn't define DTD states as it does for XML Document. //therefore we don't need to take care of anything here. So Just break; break; case XMLStreamConstants.CDATA: fEntityScanner.checkNodeCount(fEntityScanner.fCurrentEntity); fDocumentHandler.startCDATA(null); //xxx: check if CDATA values comes from getCharacterData() function fDocumentHandler.characters(getCharacterData(),null); fDocumentHandler.endCDATA(null); //System.out.println(" in CDATA of the XMLNSDocumentScannerImpl"); break; case XMLStreamConstants.NOTATION_DECLARATION : break; case XMLStreamConstants.ENTITY_DECLARATION : break; case XMLStreamConstants.NAMESPACE : break; case XMLStreamConstants.ATTRIBUTE : break; case XMLStreamConstants.END_ELEMENT : //do not give callback here. //this callback is given in scanEndElement function. //fDocumentHandler.endElement(getElementQName(),null); break; default : thrownewInternalError("processing event: " + event);
} //System.out.println("here in before calling next"); event = next(); //System.out.println("here in after calling next"); } while (event!=XMLStreamConstants.END_DOCUMENT && complete);
publicintnext()throws IOException, XNIException { if(DEBUG_NEXT){ System.out.println("NOW IN XMLDeclDriver"); }
// next driver is prolog regardless of whether there // is an XMLDecl in this document setScannerState(SCANNER_STATE_PROLOG); setDriver(fPrologDriver);
//System.out.println("fEntityScanner = " + fEntityScanner); // scan XMLDecl try { if (fEntityScanner.skipString(xmlDecl)) { fMarkupDepth++; // NOTE: special case where document starts with a PI // whose name starts with "xml" (e.g. "xmlfoo") if (XMLChar.isName(fEntityScanner.peekChar())) { fStringBuffer.clear(); fStringBuffer.append("xml"); while (XMLChar.isName(fEntityScanner.peekChar())) { fStringBuffer.append((char)fEntityScanner.scanChar(null)); } Stringtarget= fSymbolTable.addSymbol(fStringBuffer.ch, fStringBuffer.offset, fStringBuffer.length); //this function should fill the data.. and set the fEvent object to this event. fContentBuffer.clear() ; scanPIData(target, fContentBuffer); //REVISIT:where else we can set this value to 'true' fEntityManager.fCurrentEntity.mayReadChunks = true; //return PI event since PI was encountered return XMLEvent.PROCESSING_INSTRUCTION ; } // standard XML declaration else { scanXMLDeclOrTextDecl(false); //REVISIT:where else we can set this value to 'true' fEntityManager.fCurrentEntity.mayReadChunks = true; return XMLEvent.START_DOCUMENT; } } else{ //REVISIT:where else we can set this value to 'true' fEntityManager.fCurrentEntity.mayReadChunks = true; //In both case return the START_DOCUMENT. ony difference is that first block will //cosume the XML declaration if any. return XMLEvent.START_DOCUMENT; }
// pseudo-attribute values Stringversion= fStrings[0]; Stringencoding= fStrings[1]; Stringstandalone= fStrings[2]; fDeclaredEncoding = encoding; // set standalone fStandaloneSet = standalone != null; fStandalone = fStandaloneSet && standalone.equals("yes"); ///xxx see where its used.. this is not used anywhere. it may be useful for entity to store this information //but this information is only related with Document Entity. fEntityManager.setStandalone(fStandalone);
if(version != null){ fEntityScanner.setVersion(version); fEntityScanner.setXMLVersion(version); } // set encoding on reader, only if encoding was not specified by the application explicitly if (encoding != null && !fEntityScanner.getCurrentEntity().isEncodingExternallySpecified()) { fEntityScanner.setEncoding(encoding); }
case SCANNER_STATE_ROOT_ELEMENT: { if (scanRootElementHook()) { fEmptyElement = true; //rest would be taken care by fTrailingMiscDriver set by scanRootElementHook return XMLEvent.START_ELEMENT; } setScannerState(SCANNER_STATE_CONTENT); return XMLEvent.START_ELEMENT ; }