Skip to content

Commit

Permalink
Changed how Mets path is handled #136
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosjepard authored and hmiguim committed Mar 16, 2023
1 parent b579743 commit 4936a07
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ protected static MetsWrapper processMainMets(IPInterface ip, Path ipPath) {
addAgentsToMETS(mainMets, ip, null);

ValidationUtils.addInfo(ip.getValidationReport(), ValidationConstants.MAIN_METS_IS_VALID, ipPath, mainMETSFile);
} catch (JAXBException | ParseException | SAXException e) {
} catch (JAXBException | ParseException | SAXException | IOException e) {
mainMets = null;
ValidationUtils.addIssue(ip.getValidationReport(), ValidationConstants.MAIN_METS_NOT_VALID,
ValidationEntry.LEVEL.ERROR, e, ip.getBasePath(), mainMETSFile);
Expand Down Expand Up @@ -414,7 +414,7 @@ protected static MetsWrapper processRepresentationMets(IPInterface ip, Path repr
setRepresentationContentType(representationMets, representation);
ValidationUtils.addInfo(ip.getValidationReport(), ValidationConstants.REPRESENTATION_METS_IS_VALID,
ip.getBasePath(), representationMetsFile);
} catch (JAXBException | ParseException | SAXException e) {
} catch (JAXBException | ParseException | SAXException | IOException e) {
representationMets = null;
ValidationUtils.addIssue(ip.getValidationReport(), ValidationConstants.REPRESENTATION_METS_NOT_VALID,
ValidationEntry.LEVEL.ERROR, e, ip.getBasePath(), representationMetsFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package org.roda_project.commons_ip2.utils;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -49,7 +50,7 @@ private METSUtils() {
// do nothing
}

public static Mets instantiateMETSFromFile(Path metsFile) throws JAXBException, SAXException {
public static Mets instantiateMETSFromFile(Path metsFile) throws JAXBException, SAXException, IOException {
JAXBContext jaxbContext = JAXBContext.newInstance(Mets.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Expand All @@ -59,7 +60,7 @@ public static Mets instantiateMETSFromFile(Path metsFile) throws JAXBException,
Source metsSchemaSource = new StreamSource(metsSchemaInputStream);
Schema schema = factory.newSchema(metsSchemaSource);
jaxbUnmarshaller.setSchema(schema);
return (Mets) jaxbUnmarshaller.unmarshal(metsFile.toFile());
return (Mets) jaxbUnmarshaller.unmarshal(new BufferedInputStream(Files.newInputStream(metsFile.toAbsolutePath())));
}

public static Path marshallMETS(Mets mets, Path tempMETSFile, boolean rootMETS)
Expand Down

0 comments on commit 4936a07

Please sign in to comment.