use of eu.transkribus.core.model.beans.ITrpFile 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;
}
Aggregations