Search in sources :

Example 1 with FimgStoreFileMd

use of org.dea.fimgstoreclient.beans.FimgStoreFileMd in project TranskribusCore by Transkribus.

the class FimgStoreReadConnection method getImgMd.

public static FimgStoreImgMd getImgMd(URL url) throws IOException {
    FimgStoreFileMd md = getFileMd(url);
    if (!(md instanceof FimgStoreImgMd)) {
        throw new IOException("File with key " + md.getKey() + " is not an image!");
    }
    FimgStoreImgMd imgMd = (FimgStoreImgMd) md;
    return imgMd;
}
Also used : FimgStoreImgMd(org.dea.fimgstoreclient.beans.FimgStoreImgMd) FimgStoreFileMd(org.dea.fimgstoreclient.beans.FimgStoreFileMd) IOException(java.io.IOException)

Example 2 with FimgStoreFileMd

use of org.dea.fimgstoreclient.beans.FimgStoreFileMd in project TranskribusCore by Transkribus.

the class TrpMetsBuilder method buildFileType.

/**
 * @param localFolder null if isLocalDoc
 * @param id
 * @param o
 * @param client
 * @return
 * @throws IOException
 */
private static FileType buildFileType(File localFolder, String id, ITrpFile o, final int seq, FimgStoreGetClient client) throws IOException {
    FileType fType = new FileType();
    fType.setID(id);
    String mime = null;
    Date date = null;
    FLocat fLocat = new FLocat();
    String loc = null;
    if (localFolder != null) {
        URL url = o.getUrl();
        if (!url.getProtocol().contains("file")) {
            throw new IOException("Doc contains local folder reference but an URL refers to a non-local file! " + url.toString());
        }
        final String path = FileUtils.toFile(url).getAbsolutePath();
        File f = new File(path);
        mime = MimeTypes.getMimeType(FilenameUtils.getExtension(f.getName()));
        date = new Date(f.lastModified());
        fLocat.setLOCTYPE("OTHER");
        fLocat.setOTHERLOCTYPE("FILE");
        // remove protocol and localfolder, i.e. get relative path to this file
        // loc = path.substring(localFolder.getAbsolutePath().length() + 1); // BUG: localFolder != path!!
        loc = FilenameUtils.getName(path);
        if (id.startsWith(PAGE_GROUP_ID)) {
            // append relative folder for PAGE XML files
            loc = "page/" + loc;
        }
        logger.debug("loc = " + loc);
        if (o.getMd5Sum() != null) {
            fType.setCHECKSUMTYPE(ChecksumUtils.ChkSumAlg.MD5.toString());
            fType.setCHECKSUM(o.getMd5Sum());
        }
    } else {
        try {
            FimgStoreFileMd fMd = client.getFileMd(o.getKey());
            date = fMd.getUploadDate();
            mime = fMd.getMimetype();
            fLocat.setLOCTYPE("URL");
            // full URL in case of remote file
            loc = o.getUrl().toString();
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
            throw new IOException("FileMetadata could not be retrieved from imagestore for key: " + o.getKey());
        }
    }
    fType.setMIMETYPE(mime);
    XMLGregorianCalendar cal = JaxbUtils.getXmlCalendar(date);
    fType.setCREATED(cal);
    fType.setSEQ(seq);
    fLocat.setHref(loc);
    fType.getFLocat().add(fLocat);
    return fType;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) FileType(eu.transkribus.core.model.beans.mets.FileType) FLocat(eu.transkribus.core.model.beans.mets.FileType.FLocat) IOException(java.io.IOException) FimgStoreFileMd(org.dea.fimgstoreclient.beans.FimgStoreFileMd) ITrpFile(eu.transkribus.core.model.beans.ITrpFile) File(java.io.File) Date(java.util.Date) URL(java.net.URL)

Aggregations

IOException (java.io.IOException)2 FimgStoreFileMd (org.dea.fimgstoreclient.beans.FimgStoreFileMd)2 ITrpFile (eu.transkribus.core.model.beans.ITrpFile)1 FileType (eu.transkribus.core.model.beans.mets.FileType)1 FLocat (eu.transkribus.core.model.beans.mets.FileType.FLocat)1 File (java.io.File)1 URL (java.net.URL)1 Date (java.util.Date)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 FimgStoreImgMd (org.dea.fimgstoreclient.beans.FimgStoreImgMd)1