use of org.mycore.mets.validator.validators.ValidationException in project mycore by MyCoRe-Org.
the class MCRMetsCommands method validateSelectedMets.
@MCRCommand(syntax = "validate selected mets", help = "validates all mets.xml of selected derivates", order = 10)
public static void validateSelectedMets() {
List<String> selectedObjectIDs = MCRObjectCommands.getSelectedObjectIDs();
for (String objectID : selectedObjectIDs) {
LOGGER.info("Validate mets.xml of {}", objectID);
MCRPath metsFile = MCRPath.getPath(objectID, "/mets.xml");
if (Files.exists(metsFile)) {
try {
MCRContent content = new MCRPathContent(metsFile);
InputStream metsIS = content.getInputStream();
METSValidator mv = new METSValidator(metsIS);
List<ValidationException> validationExceptionList = mv.validate();
if (validationExceptionList.size() > 0) {
invalidMetsQueue.add(objectID);
}
for (ValidationException validationException : validationExceptionList) {
LOGGER.error(validationException.getMessage());
}
} catch (IOException e) {
LOGGER.error("Error while reading mets.xml of {}", objectID, e);
} catch (JDOMException e) {
LOGGER.error("Error while parsing mets.xml of {}", objectID, e);
}
}
}
}
use of org.mycore.mets.validator.validators.ValidationException in project mycore by MyCoRe-Org.
the class MCRSwordMediaHandler method validate.
@Override
public MCRSwordUtil.MCRValidationResult validate(Path pathToFile) {
// single added file name are remapped to mets.xml -> swordv2_*mets.xml
if (pathToFile.getFileName().toString().endsWith("mets.xml")) {
try (InputStream is = Files.newInputStream(pathToFile)) {
METSValidator validator = new METSValidator(is);
List<ValidationException> validateResult = validator.validate();
if (validateResult.size() > 0) {
String result = validateResult.stream().map(Throwable::getMessage).collect(Collectors.joining(System.lineSeparator()));
return new MCRSwordUtil.MCRValidationResult(false, result);
} else {
return new MCRSwordUtil.MCRValidationResult(true, null);
}
} catch (IOException | JDOMException e) {
return new MCRSwordUtil.MCRValidationResult(false, "Could not read mets.xml: " + e.getMessage());
}
} else {
return new MCRSwordUtil.MCRValidationResult(true, null);
}
}
Aggregations