Search in sources :

Example 6 with FLocat

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);
}
Also used : FLocat(eu.transkribus.core.model.beans.mets.FileType.FLocat)

Aggregations

FLocat (eu.transkribus.core.model.beans.mets.FileType.FLocat)6 FileType (eu.transkribus.core.model.beans.mets.FileType)4 File (java.io.File)4 IOException (java.io.IOException)3 URL (java.net.URL)3 ITrpFile (eu.transkribus.core.model.beans.ITrpFile)2 TrpPage (eu.transkribus.core.model.beans.TrpPage)2 Fptr (eu.transkribus.core.model.beans.mets.DivType.Fptr)2 Date (java.util.Date)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 CorruptImageException (eu.transkribus.core.exceptions.CorruptImageException)1 TrpDocMetadata (eu.transkribus.core.model.beans.TrpDocMetadata)1 TrpTranscriptMetadata (eu.transkribus.core.model.beans.TrpTranscriptMetadata)1 AmdSecType (eu.transkribus.core.model.beans.mets.AmdSecType)1 DivType (eu.transkribus.core.model.beans.mets.DivType)1 FileGrpType (eu.transkribus.core.model.beans.mets.FileGrpType)1 MdSecType (eu.transkribus.core.model.beans.mets.MdSecType)1 Mets (eu.transkribus.core.model.beans.mets.Mets)1 FileSec (eu.transkribus.core.model.beans.mets.MetsType.FileSec)1 FileGrp (eu.transkribus.core.model.beans.mets.MetsType.FileSec.FileGrp)1