use of eu.transkribus.core.model.beans.mets.FileType.FLocat in project TranskribusCore by Transkribus.
the class MetsUtil method getFileNameAndChecksum.
public static Pair<String, String> getFileNameAndChecksum(FileType type) throws IllegalArgumentException {
String name = null;
String checksum = null;
FLocat fLocat = type.getFLocat().get(0);
if (fLocat.getOTHERLOCTYPE() != null && fLocat.getOTHERLOCTYPE().equals("FILE")) {
// localdoc
name = fLocat.getHref();
if (StringUtils.isEmpty(name)) {
throw new IllegalArgumentException("File name is empty on FLocat ID=" + fLocat.getID());
}
if (!type.isSetCHECKSUMTYPE()) {
logger.info("No checksum set!");
} else if (!type.getCHECKSUMTYPE().equals(ChecksumUtils.ChkSumAlg.MD5.toString())) {
logger.info("Unknown checksum algorithm: " + type.getCHECKSUMTYPE());
} else {
checksum = type.getCHECKSUM();
// final String chkSum = ChecksumUtils.getMd5SumHex(file);
// if(!metsChkSum.equals(chkSum)){
// throw new IOException("Checksum error: METS=" + metsChkSum + " <-> FILE=" + chkSum + " | " + file.getAbsolutePath());
// }
// logger.debug("Checksum is correct: " + file.getAbsolutePath());
}
} else {
throw new IllegalArgumentException("METS file does not belong to a local document!");
}
return Pair.of(name, checksum);
}
Aggregations