reader.setContentHandler(builder);
    private DOMImpl getDOM(Source source, int mask)	throws TransformerException {	try {	    // Use the pre-defined DOM if present	    if (_dom != null) {		DOMImpl dom = _dom;		_dom = null; // use only once, so reset to 'null'		return(dom);	    }	    DOMImpl dom = null;	    DTDMonitor dtd = null;	    // Handle SAXSource input	    if (source instanceof SAXSource) {		// Get all info from the input SAXSource object		final SAXSource   sax    = (SAXSource)source;		final XMLReader   reader = sax.getXMLReader();		final InputSource input  = sax.getInputSource();		final String      systemId = sax.getSystemId();		// 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();		reader.setContentHandler(builder);		try {		    reader.setProperty(LEXICAL_HANDLER_PROPERTY, builder);		}		catch (SAXException e) {		    // quitely ignored		}		// Parse the input and build the internal DOM		reader.parse(input);		dom.setDocumentURI(systemId);	    }	    // Handle DOMSource input	    else if (source instanceof DOMSource) {		final DOMSource   domsrc = (DOMSource)source;		final Document    tree = (Document)domsrc.getNode();		final DOM2SAX     dom2sax = new DOM2SAX(tree);		final InputSource input = null; 		final String      systemId = domsrc.getSystemId(); 		// 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		dom2sax.parse(input); // need this parameter?		dom.setDocumentURI(systemId);	    }	    // 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();		final String systemId = stream.getSystemId();		// With a StreamSource we need to create our own parser		final SAXParserFactory factory = SAXParserFactory.newInstance();		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();		reader.setContentHandler(builder);		try {		    reader.setProperty(LEXICAL_HANDLER_PROPERTY, builder);		}		catch (SAXException e) {		    // quitely ignored		}		InputSource input;		if (streamInput != null)		    input = new InputSource(streamInput);		else if (streamReader != null)		    input = new InputSource(streamReader);		else if (systemId != null)		    input = new InputSource(systemId);		else		    throw new TransformerException(INPUT_SOURCE_EMPTY);		// Parse the input and build the internal DOM		reader.parse(input);		dom.setDocumentURI(systemId);	    }	    // Handle XSLTC-internal Source input	    else if (source instanceof XSLTCSource) {		final XSLTCSource xsltcsrc = (XSLTCSource)source;		dtd = xsltcsrc.getDTD();		dom = xsltcsrc.getDOM();	    }	    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("File not found: " + e.getMessage());	    throw new TransformerException(e);	}	catch (MalformedURLException e) {	    if (_errorListener != null)		postErrorToListener("Malformed URL: " + e.getMessage());	    throw new TransformerException(e);	}	catch (UnknownHostException e) {	    if (_errorListener != null)		postErrorToListener("Cannot resolve URI: " + e.getMessage());	    throw new TransformerException(e);	}	catch (Exception e) {	    if (_errorListener != null)		postErrorToListener("Internal error: " + e.getMessage()); 	    throw new TransformerException(e);	}    }