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();
}
}
Aggregations