if (location==null && appE==null) {
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("A location or remote app is required.");
}
RemoteApp app = null;
if (location==null) {
app = new RemoteApp(db,appE);
app.unmarshall();
if (!app.getIntrospection().isAbsolute()) {
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("URI could not be resolved to absolute URI: "+appE.getAttributeValue("introspect"));
}
} else {
File dir = new File(location);
if (!dir.exists()) {
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("The "+dir.getAbsolutePath()+" doesn't exist.");
}
if (!dir.canRead()) {
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("Cannot write to "+dir.getAbsolutePath());
}
File introspect = new File(dir,"_introspection_.xml");
if (!introspect.exists()) {
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("Introspection document "+introspect.getAbsolutePath()+" does not exist.");
}
app = new RemoteApp(db,"backup");
app.setIntrospection(introspect.toURI());
app.setRoot(dir.toURI());
}
SyncTarget target = new SyncTarget(db,"");
SyncProcess proc = new SyncProcess(db,"restore",true,target,app,null);