Skip to content

Commit

Permalink
Merge pull request #604 from veraPDF/metadata_fixer
Browse files Browse the repository at this point in the history
Update metadata fixer
  • Loading branch information
MaximPlusov authored and Git User committed Nov 1, 2023
1 parent 30cc219 commit b024d65
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit b024d65

Please sign in to comment.