possibleFormatsString = null;
/**
* DROID is used for file identification.
*/
FormatIdentification ident = null;
String filename = tempDigitalObjects.get(rec);
if (filename == null || "".equals(filename)) {
SampleObject rec2 = em.merge(rec);
ident = DROIDIntegration.getInstance().identifyFormat(rec2.getData().getData(), rec2.getFullname());
} else {
ident = DROIDIntegration.getInstance().identify(filename);
}
if (ident.getResult() == FormatIdentificationResult.ERROR) {
/*
* DROID could not identify this file.
*/
log.error(ident.getInfo());
formatMessage = "DROID could not identify the format of the file." + ident.getInfo();
} else if (ident.getResult() == FormatIdentificationResult.NOHIT) {
/*
* DROID could not identify this file.
*/
log.info(ident.getInfo());
formatMessage = "DROID could not identify the format of the file." + ident.getInfo();
} else if ((ident.getResult() == FormatIdentificationResult.POSITIVE) &&
(ident.getFormatHits().size() == 1)){
/*
* exact match, format identification successful
*/
rec.getFormatInfo().assignValues(ident.getFormatHits().get(0).getFormat());
rec.touch();
formatMessage = ident.getInfo();
} else {
/*
* Here, we either have more than one POSITIVE hit or any number of TENTATIVE hits.
* DROID provides only some guesses as it cannot identify it, the user has to decide.
*/
formatMessage = "Droid identified several potential formats of this file. " + ident.getInfo() + " Please choose the most adequate one:";
for (FormatHit hit : ident.getFormatHits()){
String key = hit.getFormat().getName();
if (hit.getFormat().getVersion() != null)
key = key + ' ' + hit.getFormat().getVersion();
possibleFormats.put(key, hit);
}
possibleFormatsString = possibleFormats.keySet().toArray(new String[]{});
// set format info to first entry in the list - as the drop down box suggests
selectedFormat.setValue(possibleFormatsString[0]);
rec.getFormatInfo().assignValues(possibleFormats.get(selectedFormat.getValue()).getFormat());
rec.touch();
FacesMessages.instance().add(FacesMessage.SEVERITY_INFO, ident.getInfo());
}
} catch (Exception e) {
/*
* An error occured, maybe it would help to try it again.
*/