return new StringRepresentation("Non-XML media type for entity body: "+entity.getMediaType().getName());
}
Map<String,DBInfo> dbList = (Map<String,DBInfo>)getContext().getAttributes().get(DatabaseListResource.DB_LIST);
Map<String,DBInfo> autodbList = (Map<String,DBInfo>)getContext().getAttributes().get(DatabaseListResource.AUTO_DB_LIST);
StorageFactory storageFactory = (StorageFactory)getContext().getAttributes().get(DatabaseListResource.STORAGE_FACTORY);
try {
DocumentDestination dest = new DocumentDestination();
parser.parse(entity,AdminApplication.createAdminDocumentDestination(dest,AdminXML.NM_RESTORE));
Document doc = dest.getDocument();
Element top = doc.getDocumentElement();
String location = top.getAttributeValue("location");
if (location==null) {
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("The 'location' attribute is missing.");
}
location = location.trim();
if (location.length()==0) {
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("The 'location' attribute is empty.");
}
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());
}
Set<String> dbNames = new TreeSet<String>();
Iterator<Element> names = top.getElementsByName(AdminXML.NM_NAME);
while (names.hasNext()) {
dbNames.add(names.next().getText());
}
List<Map<String,DBInfo>> lists = new ArrayList<Map<String,DBInfo>>();
lists.add(dbList);
lists.add(autodbList);
User user = (User)getRequest().getAttributes().get(App.USER_ATTR);
boolean ok = true;
List<String> failures = new ArrayList<String>();
for (Map<String,DBInfo> map : lists) {
for (DBInfo dbinfo : map.values()) {
DB db = dbinfo.getDB();
if (dbNames.size()>0 && !dbNames.contains(db.getName())) {
continue;
}
File dbDir = new File(dir,db.getName());
boolean needsCleanup = false;
try {
Storage storage = storageFactory.getStorage(db);
File zipFile = new File(dir,db.getName()+".zip");
if (!dbDir.exists() && zipFile.exists()) {
// This is what we want but it doesn't work
//introspectionURI = new URI("jar:"+zipFile.toURI()+"!/_introspection_.xml");
getLogger().info("Extracting backup for restore...");