try {
final int handle = Integer.parseInt(localFile);
final SerializedResult sr = factory.resultSets.getSerializedResult(handle);
if(sr==null)
{throw new EXistException("Invalid handle specified");}
source = new VirtualTempFileInputSource(sr.result);
// Unlinking the VirtualTempFile from the SerializeResult
sr.result=null;
factory.resultSets.remove(handle);
} catch(final NumberFormatException nfe) {
// As this file can be a non-temporal one, we should not
// blindly erase it!
final File file = new File(localFile);
if (!file.canRead())
{throw new EXistException("unable to read file " + file.getAbsolutePath());}
source = new VirtualTempFileInputSource(file);
} catch(final IOException ioe) {
throw new EXistException("Error preparing virtual temp file for parsing");
}
final TransactionManager transact = factory.getBrokerPool().getTransactionManager();
final Txn transaction = transact.beginTransaction();
DBBroker broker = null;
DocumentImpl doc = null;
// DWES
MimeType mime = MimeTable.getInstance().getContentType(mimeType);
if (mime == null)
{mime = MimeType.BINARY_TYPE;}
final boolean treatAsXML=(isXML!=null && isXML.booleanValue()) || (isXML==null && mime.isXMLType());
try {
broker = factory.getBrokerPool().get(user);
Collection collection = null;
IndexInfo info = null;
try {
collection = broker.openCollection(docUri.removeLastSegment(), Lock.WRITE_LOCK);
if (collection == null) {
transact.abort(transaction);
throw new EXistException("Collection " + docUri.removeLastSegment() + " not found");
}
if (overwrite == 0) {
final DocumentImpl old = collection.getDocument(broker, docUri.lastSegment());
if (old != null) {