user = currentUser;
finally {  user = currentUser; }
    public DocumentImpl storeTempResource(org.exist.memtree.DocumentImpl doc)     throws EXistException, PermissionDeniedException, LockException {        TransactionManager transact = pool.getTransactionManager();        Txn transaction = transact.beginTransaction();                //store the currentUser        User currentUser = user;                //elevate user to DBA_USER        user = pool.getSecurityManager().getUser(SecurityManager.DBA_USER);                XmldbURI docName = XmldbURI.create(MD5.md(Thread.currentThread().getName() + Long.toString(System.currentTimeMillis()),false) +            ".xml");        Collection temp = openCollection(XmldbURI.TEMP_COLLECTION_URI, Lock.WRITE_LOCK);                try {            if(temp == null)                temp = createTempCollection(transaction);            else                transaction.registerLock(temp.getLock(), Lock.WRITE_LOCK);            DocumentImpl targetDoc = new DocumentImpl(this, temp, docName);            targetDoc.setPermissions(0771);            long now = System.currentTimeMillis();            DocumentMetadata metadata = new DocumentMetadata();            metadata.setLastModified(now);            metadata.setCreated(now);            targetDoc.setMetadata(metadata);            targetDoc.setDocId(getNextResourceId(transaction, temp));            DOMIndexer indexer = new DOMIndexer(this, transaction, doc, targetDoc);            indexer.scan();            indexer.store();            temp.addDocument(transaction, this, targetDoc);            storeXMLResource(transaction, targetDoc);            closeDocument();            flush();            transact.commit(transaction);                        //restore the user            user = currentUser;                        return targetDoc;        } catch (Exception e) {            LOG.debug(e);            transact.abort(transaction);        }                //restore the user        user = currentUser;                return null;    }