Search in sources :

Example 1 with MdFileFilter

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.");
        }
    }
}
Also used : MdFileFilter(eu.transkribus.core.io.util.MdFileFilter) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) TrpDocMetadata(eu.transkribus.core.model.beans.TrpDocMetadata) IOException(java.io.IOException) File(java.io.File)

Aggregations

MdFileFilter (eu.transkribus.core.io.util.MdFileFilter)1 TrpDocMetadata (eu.transkribus.core.model.beans.TrpDocMetadata)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 JAXBException (javax.xml.bind.JAXBException)1