if (!isComplete) { builder.startDocument(); } dom2sax.parse(input); if (!isComplete) { builder.endDocument(); }
dom2sax.parse();
    private DOMImpl getDOM(Source source, int mask)	throws TransformerException     {	try {	    DOMImpl dom = null;	    DTDMonitor dtd = null;	    // Get systemId from source	    if (source != null) {		_sourceSystemId = source.getSystemId();	    }	    // Handle SAXSource input	    if (source instanceof SAXSource) {		// Get all info from the input SAXSource object		final SAXSource   sax    = (SAXSource)source;		XMLReader   reader = sax.getXMLReader();		final InputSource input  = sax.getInputSource();		// if reader was not set with setXMLReader by user,		// then we must create one ourselves.		if (reader == null) {		    SAXParserFactory pfactory= SAXParserFactory.newInstance();		    pfactory.setNamespaceAware(true);		    reader = pfactory.newSAXParser().getXMLReader();		}		// Create a DTD monitor to trap all DTD/declarative events		dtd = new DTDMonitor();		dtd.handleDTD(reader);		// Create a new internal DOM and set up its builder to trap		// all content/lexical events		dom = new DOMImpl();		final DOMBuilder builder = dom.getBuilder();		try {		    reader.setProperty(LEXICAL_HANDLER_PROPERTY, builder);		}		catch (SAXException e) {		    // quitely ignored		}		reader.setContentHandler(builder);		// Parse the input and build the internal DOM		reader.parse(input);		dom.setDocumentURI(_sourceSystemId);	    }	    // Handle DOMSource input	    else if (source instanceof DOMSource) {		final DOMSource domsrc = (DOMSource) source;		final org.w3c.dom.Node node = domsrc.getNode();		boolean isComplete = true;		if (node.getNodeType() != org.w3c.dom.Node.DOCUMENT_NODE) {		    isComplete = false;		}		final DOM2SAX dom2sax = new DOM2SAX(node);		final InputSource input = null; 		// Create a DTD monitor to trap all DTD/declarative events		dtd = new DTDMonitor();		dtd.handleDTD(dom2sax);		// Create a new internal DOM and set up its builder to trap		// all content/lexical events		dom = new DOMImpl();		final DOMBuilder builder = dom.getBuilder();		dom2sax.setContentHandler(builder);		// Parse the input and build the internal DOM		if (!isComplete) {		    builder.startDocument();		}		dom2sax.parse(input); // need this parameter?		if (!isComplete) {		    builder.endDocument();		}		dom.setDocumentURI(_sourceSystemId);	    }	    // Handle StreamSource input	    else if (source instanceof StreamSource) {		// Get all info from the input StreamSource object		final StreamSource stream = (StreamSource)source;		final InputStream  streamInput = stream.getInputStream();		final Reader streamReader = stream.getReader();		// With a StreamSource we need to create our own parser		final SAXParserFactory factory = SAXParserFactory.newInstance();		try {		    factory.setFeature(NAMESPACE_FEATURE,true);		}		catch (Exception e) {		    factory.setNamespaceAware(true);		}		final SAXParser parser = factory.newSAXParser();		final XMLReader reader = parser.getXMLReader();		// Create a DTD monitor to trap all DTD/declarative events		dtd = new DTDMonitor();		dtd.handleDTD(reader);		// Create a new internal DOM and set up its builder to trap		// all content/lexical events		dom = new DOMImpl();		final DOMBuilder builder = dom.getBuilder();		try {		    reader.setProperty(LEXICAL_HANDLER_PROPERTY, builder);		}		catch (SAXException e) {		    // quitely ignored		}		reader.setContentHandler(builder);		InputSource input;		if (streamInput != null) {		    input = new InputSource(streamInput);		    input.setSystemId(_sourceSystemId); 		} 		else if (streamReader != null) {		    input = new InputSource(streamReader);		    input.setSystemId(_sourceSystemId); 		} 		else if (_sourceSystemId != null) {		    input = new InputSource(_sourceSystemId);		} 		else {		    ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_SOURCE_ERR);		    throw new TransformerException(err.toString());		}		// Parse the input and build the internal DOM		reader.parse(input);		dom.setDocumentURI(_sourceSystemId);	    }	    // Handle XSLTC-internal Source input	    else if (source instanceof XSLTCSource) {		final XSLTCSource xsltcsrc = (XSLTCSource)source;		dtd = xsltcsrc.getDTD();		dom = xsltcsrc.getDOM();	    }	    // DOM already set via a call to setDOM()	    else if (_dom != null) {		dtd = _dtdMonitor;	   // must be set via setDTDMonitor()		dom = _dom; _dom = null;   // use only once, so reset to 'null'	    }	    else {		return null;	    }	    // Set size of key/id indices	    _translet.setIndexSize(dom.getSize());	    // If there are any elements with ID attributes, build an index	    dtd.buildIdIndex(dom, mask, _translet);	    // Pass unparsed entity URIs to the translet	    _translet.setDTDMonitor(dtd);	    return dom;	}	catch (FileNotFoundException e) {	    if (_errorListener != null)	postErrorToListener(e.getMessage());	    throw new TransformerException(e);	}	catch (MalformedURLException e) {	    if (_errorListener != null)	postErrorToListener(e.getMessage());	    throw new TransformerException(e);	}	catch (UnknownHostException e) {	    if (_errorListener != null)	postErrorToListener(e.getMessage());	    throw new TransformerException(e);	}	catch (Exception e) {	    if (_errorListener != null)	postErrorToListener(e.getMessage());	    throw new TransformerException(e);	}    }