Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update metadata fixer #604

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -147,29 +147,41 @@ public void addPDFIdentificationSchema(MetadataFixerResultImpl.Builder resultBui
addPDFUAIdentificationSchema(resultBuilder, flavour);
} else {
addPDFAIdentificationSchema(resultBuilder, flavour);
checkAndFixPrefixes(resultBuilder, flavour);
checkAndFixPDFAPrefixes(resultBuilder, flavour);
}
fixRevProperty(resultBuilder, flavour);
}

public void checkAndFixPrefixes(MetadataFixerResultImpl.Builder resultBuilder, PDFAFlavour flavour) {
public void checkAndFixPDFAPrefixes(MetadataFixerResultImpl.Builder resultBuilder, PDFAFlavour flavour) {
if (flavour.getPart() == PDFAFlavour.Specification.ISO_19005_1 ||
flavour.getPart() == PDFAFlavour.Specification.ISO_19005_2 ||
flavour.getPart() == PDFAFlavour.Specification.ISO_19005_3) {
fixPropertyPrefix(resultBuilder, VeraPDFMeta.PART, VeraPDFMeta.PDFAID_PREFIX);
fixPropertyPrefix(resultBuilder, VeraPDFMeta.CONFORMANCE, VeraPDFMeta.PDFAID_PREFIX);
fixPropertyPrefix(resultBuilder, VeraPDFMeta.AMD, VeraPDFMeta.PDFAID_PREFIX);
fixPropertyPrefix(resultBuilder, VeraPDFMeta.PART, XMPConst.NS_PDFA_ID, VeraPDFMeta.PDFAID_PREFIX);
fixPropertyPrefix(resultBuilder, VeraPDFMeta.CONFORMANCE, XMPConst.NS_PDFA_ID, VeraPDFMeta.PDFAID_PREFIX);
fixPropertyPrefix(resultBuilder, VeraPDFMeta.AMD, XMPConst.NS_PDFA_ID, VeraPDFMeta.PDFAID_PREFIX);
if (flavour.getPart() != PDFAFlavour.Specification.ISO_19005_1) {
fixPropertyPrefix(resultBuilder, VeraPDFMeta.CORR, VeraPDFMeta.PDFAID_PREFIX);
fixPropertyPrefix(resultBuilder, VeraPDFMeta.CORR, XMPConst.NS_PDFA_ID, VeraPDFMeta.PDFAID_PREFIX);
}
} else if (flavour.getPart() == PDFAFlavour.Specification.ISO_19005_4) {
fixPropertyPrefix(resultBuilder, VeraPDFMeta.PART, VeraPDFMeta.PDFAID_PREFIX);
fixPropertyPrefix(resultBuilder, VeraPDFMeta.REVISION_YEAR, VeraPDFMeta.PDFAID_PREFIX);
fixPropertyPrefix(resultBuilder, VeraPDFMeta.PART, XMPConst.NS_PDFA_ID, VeraPDFMeta.PDFAID_PREFIX);
fixPropertyPrefix(resultBuilder, VeraPDFMeta.REVISION_YEAR, XMPConst.NS_PDFA_ID, VeraPDFMeta.PDFAID_PREFIX);
}
}

private void fixPropertyPrefix(MetadataFixerResultImpl.Builder resultBuilder, String propertyName, String propertyPrefix) {
VeraPDFXMPNode property = this.metadata.getProperty(XMPConst.NS_PDFA_ID, propertyName);
public void checkAndFixPDFUAPrefixes(MetadataFixerResultImpl.Builder resultBuilder, PDFAFlavour flavour) {
if (flavour.getPart() == PDFAFlavour.Specification.ISO_14289_1) {
fixPropertyPrefix(resultBuilder, VeraPDFMeta.PART, XMPConst.NS_PDFUA_ID, VeraPDFMeta.PDFUAID_PREFIX);
fixPropertyPrefix(resultBuilder, VeraPDFMeta.CORR, XMPConst.NS_PDFUA_ID, VeraPDFMeta.PDFUAID_PREFIX);
fixPropertyPrefix(resultBuilder, VeraPDFMeta.AMD, XMPConst.NS_PDFUA_ID, VeraPDFMeta.PDFUAID_PREFIX);
} else if (flavour.getPart() == PDFAFlavour.Specification.ISO_14289_2) {
fixPropertyPrefix(resultBuilder, VeraPDFMeta.PART, XMPConst.NS_PDFUA_ID, VeraPDFMeta.PDFUAID_PREFIX);
fixPropertyPrefix(resultBuilder, VeraPDFMeta.REVISION_YEAR, XMPConst.NS_PDFUA_ID, VeraPDFMeta.PDFUAID_PREFIX);
}
}

private void fixPropertyPrefix(MetadataFixerResultImpl.Builder resultBuilder, String propertyName, String schemaId,
String propertyPrefix) {
VeraPDFXMPNode property = this.metadata.getProperty(schemaId, propertyName);
if (property != null && !propertyPrefix.equals(property.getPrefix())) {
property.setPrefix(propertyPrefix);
this.setNeedToBeUpdated(true);
@@ -198,15 +210,20 @@ public void addPDFAIdentificationSchema(MetadataFixerResultImpl.Builder resultBu
int part = flavour.getPart().getPartNumber();
String conformance = flavour != PDFAFlavour.PDFA_4 ? flavour.getLevel().getCode().toUpperCase() : null;
try {
resultBuilder.addFix(String.format(this.metadata.getPDFAIdentificationPart() == null ?
ADD_PROPERTY_MESSAGE : SET_PROPERTY_MESSAGE, VeraPDFMeta.PART, part));
this.metadata.setPDFAIdentificationPart(part);
if (!Objects.equals(this.metadata.getPDFAIdentificationPart(), part)) {
resultBuilder.addFix(String.format(this.metadata.getPDFAIdentificationPart() == null ?
ADD_PROPERTY_MESSAGE : SET_PROPERTY_MESSAGE, VeraPDFMeta.PART, part));
this.metadata.setPDFAIdentificationPart(part);
this.setNeedToBeUpdated(true);
}

resultBuilder.addFix(String.format(this.metadata.getPDFAIdentificationConformance() == null ?
ADD_PROPERTY_MESSAGE : (conformance == null ? REMOVE_PROPERTY_MESSAGE : SET_PROPERTY_MESSAGE),
VeraPDFMeta.CONFORMANCE, conformance));
this.metadata.setPDFAIdentificationConformance(conformance);
this.setNeedToBeUpdated(true);
if (isWrongPDFAIdentification(flavour)) {
resultBuilder.addFix(String.format(this.metadata.getPDFAIdentificationConformance() == null ?
ADD_PROPERTY_MESSAGE : (conformance == null ? REMOVE_PROPERTY_MESSAGE : SET_PROPERTY_MESSAGE),
VeraPDFMeta.CONFORMANCE, conformance));
this.metadata.setPDFAIdentificationConformance(conformance);
this.setNeedToBeUpdated(true);
}
} catch (XMPException e) {
LOGGER.log(Level.FINE, "Can not obtain identification fields.", e);
}
Original file line number Diff line number Diff line change
@@ -180,8 +180,7 @@ private static PDFAFlavour obtainFlavour(PDDocument document, PDFAFlavour defaul
identificationConformance = "";
}
PDFAFlavour pdfaFlavour = PDFAFlavour.byFlavourId(prefix + identificationPart + identificationConformance);
// TODO: remove that logic after updating NO_FLAVOUR into base pdf validation flavour
if (pdfaFlavour == PDFAFlavour.NO_FLAVOUR) {
if (pdfaFlavour == PDFAFlavour.NO_FLAVOUR || pdfaFlavour == PDFAFlavour.PDFUA_2) {
return defaultFlavour;
}
return pdfaFlavour;
Original file line number Diff line number Diff line change
@@ -47,9 +47,9 @@ public static boolean containsStringKey(ASAtom key, GFOpMarkedContent markedCont
Long mcid = markedContent.getInheritedMCID();
COSObject structureElement = accessObject.getStructureElement(parentTreeRoot, mcid);
if (structureElement != null && !structureElement.empty()) {
COSObject actualText = structureElement.getKey(key);
return actualText != null && !actualText.empty() &&
actualText.getType() == COSObjType.COS_STRING;
COSObject value = structureElement.getKey(key);
return value != null && !value.empty() &&
value.getType() == COSObjType.COS_STRING;
}
}
}
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ private static BoundingBox getBoundingBox(PDAnnotation annotation) {
}

private static Integer getAnnotationPageNumber(PDAnnotation annotation) {
Integer pageNumber = getPageNumber(annotation.getParent());
Integer pageNumber = getPageNumber(annotation.getKey(ASAtom.P));
if (pageNumber != null) {
return pageNumber;
}