Search in sources :

Example 1 with SystemImportHandler

use of org.exist.backup.restore.SystemImportHandler in project exist by eXist-db.

the class SystemImport method restore.

public void restore(final String username, final Object credentials, @Nullable final String newCredentials, final Path f, final RestoreListener listener) throws IOException, SAXException, AuthenticationException, ConfigurationException, PermissionDeniedException, TransactionException {
    // login
    try (final DBBroker broker = db.authenticate(username, credentials);
        final Txn transaction = broker.continueOrBeginTransaction()) {
        // set the new password
        if (newCredentials != null) {
            setAdminCredentials(broker, newCredentials);
        }
        // get the backup descriptors, can be more than one if it was an incremental backup
        final Deque<BackupDescriptor> descriptors = getBackupDescriptors(f);
        final XMLReaderPool parserPool = broker.getBrokerPool().getParserPool();
        XMLReader reader = null;
        try {
            reader = parserPool.borrowXMLReader();
            listener.started(0);
            while (!descriptors.isEmpty()) {
                final BackupDescriptor descriptor = descriptors.pop();
                final EXistInputSource is = descriptor.getInputSource();
                is.setEncoding("UTF-8");
                final SystemImportHandler handler = new SystemImportHandler(broker, transaction, descriptor, listener);
                reader.setContentHandler(handler);
                reader.parse(is);
            }
        } finally {
            listener.finished();
            if (reader != null) {
                parserPool.returnXMLReader(reader);
            }
        }
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) SystemImportHandler(org.exist.backup.restore.SystemImportHandler) EXistInputSource(org.exist.util.EXistInputSource) Txn(org.exist.storage.txn.Txn) XMLReaderPool(org.exist.util.XMLReaderPool) XMLReader(org.xml.sax.XMLReader)

Aggregations

SystemImportHandler (org.exist.backup.restore.SystemImportHandler)1 DBBroker (org.exist.storage.DBBroker)1 Txn (org.exist.storage.txn.Txn)1 EXistInputSource (org.exist.util.EXistInputSource)1 XMLReaderPool (org.exist.util.XMLReaderPool)1 XMLReader (org.xml.sax.XMLReader)1