use of org.exist.backup.SystemImport in project exist by eXist-db.
the class FnImport method eval.
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
if (!context.getSubject().hasDbaRole()) {
throw (new XPathException(this, "Permission denied, calling user '" + context.getSubject().getName() + "' must be a DBA to kill a running xquery"));
}
final String dirOrFile = args[0].getStringValue();
String adminPass = null;
if (args[1].hasOne()) {
adminPass = args[1].getStringValue();
}
String adminPassAfter = null;
if (args[2].hasOne()) {
adminPassAfter = args[2].getStringValue();
}
MemTreeBuilder builder = null;
context.pushDocumentContext();
try {
if (NAME.equals(getName())) {
builder = context.getDocumentBuilder();
builder.startDocument();
builder.startElement(IMPORT_ELEMENT, null);
}
try {
final SystemImport restore = new SystemImport(context.getDatabase());
final RestoreListener listener = new XMLRestoreListener(builder);
restore.restore(org.exist.security.SecurityManager.DBA_USER, adminPass, adminPassAfter, Paths.get(dirOrFile), listener);
} catch (final Exception e) {
throw new XPathException(this, "restore failed with exception: " + e.getMessage(), e);
}
if (builder == null) {
return Sequence.EMPTY_SEQUENCE;
} else {
builder.endElement();
builder.endDocument();
return (NodeValue) builder.getDocument().getDocumentElement();
}
} finally {
if (builder != null) {
context.popDocumentContext();
}
}
}
Aggregations