use of eu.transkribus.core.io.util.MdFileFilter in project TranskribusCore by Transkribus.
the class LocalDocReader method loadDocMd.
/**
* searches the inputDir for files ending in XmlFileFilter.mdFileEnding,
* which is e.g. "metadata.xml". If a file is found, it is parsed into a
* TrpDocMetadata Object.
*
* @param inputDir
* where the document is stored
* @return TrpDocMetadata Object or null if no mdFile is found.
* @throws IOException
* If more than one mdFile is on the path
*/
public static TrpDocMetadata loadDocMd(File inputDir) throws IOException {
final File[] mdFiles = inputDir.listFiles(new MdFileFilter());
if (mdFiles == null || mdFiles.length == 0) {
// no file => no metadata
throw new FileNotFoundException("No metadata XML was found on path: " + inputDir.getAbsolutePath());
} else {
final File mdFile = mdFiles[0];
logger.info("Found md File " + mdFile.getAbsolutePath());
try {
TrpDocMetadata docMd = JaxbUtils.unmarshal(mdFile, TrpDocMetadata.class);
// set ID to -1 in order to create confusion
docMd.setDocId(-1);
return docMd;
} catch (JAXBException je) {
// this file will be ignored
throw new IOException("The md File " + mdFile.getName() + " did not obey the correct format. " + "A doc without metadata will be provided.");
}
}
}
Aggregations