From ccaf8b8e2860ba0ee84d67084d4a6cf558682c8e Mon Sep 17 00:00:00 2001 From: Maxim Date: Sun, 26 Nov 2023 13:54:49 +0300 Subject: [PATCH] Move standard structure types methods to parser --- .../verapdf/gf/model/impl/pd/GFPDAnnot.java | 4 +- .../gf/model/impl/pd/GFPDStructElem.java | 8 ++-- .../impl/pd/annotations/GFPDWidgetAnnot.java | 2 +- .../gf/model/impl/pd/gfse/GFSEFactory.java | 39 +------------------ .../pd/gfse/contents/GFSEGroupedContent.java | 4 +- .../gf/model/impl/sa/GFSAStructElem.java | 5 ++- .../impl/sa/structelems/GFSAFactory.java | 10 +---- 7 files changed, 15 insertions(+), 57 deletions(-) diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDAnnot.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDAnnot.java index 6a7892d90..859aff9fb 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDAnnot.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDAnnot.java @@ -197,7 +197,7 @@ public String getstructParentStandardType() { COSObject parentDictionary = getParentDictionary(); if (parentDictionary != null) { PDStructElem structElem = new PDStructElem(parentDictionary, taggedPDFRoleMapHelper.getRoleMap()); - return GFSEFactory.getStructureElementStandardType(structElem); + return PDStructElem.getStructureElementStandardType(structElem); } } return null; @@ -331,7 +331,7 @@ public Boolean getisArtifact() { if (parentDictionary != null) { PDStructElem structElem = new PDStructElem(parentDictionary, taggedPDFRoleMapHelper.getRoleMap()); while (structElem != null) { - if (TaggedPDFConstants.ARTIFACT.equals(GFSEFactory.getStructureElementStandardType(structElem))) { + if (TaggedPDFConstants.ARTIFACT.equals(PDStructElem.getStructureElementStandardType(structElem))) { return true; } structElem = structElem.getParent(); diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDStructElem.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDStructElem.java index e45441138..6c2498902 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDStructElem.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/GFPDStructElem.java @@ -111,17 +111,17 @@ public String getType() { public String getparentStandardType() { org.verapdf.pd.structure.PDStructElem parent = ((org.verapdf.pd.structure.PDStructElem) simplePDObject).getParent(); if (parent != null) { - StructureType parentStandardStructureType = GFSEFactory.getStructureElementStandardStructureType(parent); + StructureType parentStandardStructureType = org.verapdf.pd.structure.PDStructElem.getStructureElementStandardStructureType(parent); String parentStandardType = parentStandardStructureType != null ? parentStandardStructureType.getType().getValue() : null; while (TaggedPDFConstants.NON_STRUCT.equals(parentStandardType) || TaggedPDFConstants.DIV.equals(parentStandardType)) { parent = parent.getParent(); if (parent == null) { return null; } - parentStandardStructureType = GFSEFactory.getStructureElementStandardStructureType(parent); + parentStandardStructureType = org.verapdf.pd.structure.PDStructElem.getStructureElementStandardStructureType(parent); parentStandardType = parentStandardStructureType != null ? parentStandardStructureType.getType().getValue() : null; } - if (GFSEFactory.isMathStandardType(parentStandardStructureType)) { + if (org.verapdf.pd.structure.PDStructElem.isMathStandardType(parentStandardStructureType)) { return TaggedPDFConstants.MATH_ML; } return parentStandardType; @@ -141,7 +141,7 @@ public String getstandardType() { } public String getStandardTypeNamespaceURL() { - StructureType standardStructureType = GFSEFactory.getStructureElementStandardStructureType( + StructureType standardStructureType = org.verapdf.pd.structure.PDStructElem.getStructureElementStandardStructureType( (org.verapdf.pd.structure.PDStructElem) this.simplePDObject); return standardStructureType != null ? standardStructureType.getNameSpaceURI() : null; } diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/annotations/GFPDWidgetAnnot.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/annotations/GFPDWidgetAnnot.java index d06f61fde..cd9c6b166 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/annotations/GFPDWidgetAnnot.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/annotations/GFPDWidgetAnnot.java @@ -82,7 +82,7 @@ public Boolean getcontainsLbl() { if (parent != null) { PDStructElem parentStructElem = new PDStructElem(parent, taggedPDFRoleMapHelper.getRoleMap()); for (PDStructElem child : parentStructElem.getStructChildren()) { - if (TaggedPDFConstants.LBL.equals(GFSEFactory.getStructureElementStandardType(child)) && + if (TaggedPDFConstants.LBL.equals(PDStructElem.getStructureElementStandardType(child)) && !child.getChildren().isEmpty()) { return true; } diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEFactory.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEFactory.java index f70496355..b7cffb43a 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEFactory.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/GFSEFactory.java @@ -20,21 +20,17 @@ */ package org.verapdf.gf.model.impl.pd.gfse; -import org.verapdf.as.ASAtom; -import org.verapdf.gf.model.impl.containers.StaticContainers; import org.verapdf.gf.model.impl.pd.GFPDStructElem; import org.verapdf.pd.structure.PDStructElem; import org.verapdf.pd.structure.StructureType; -import org.verapdf.pdfa.flavours.PDFAFlavour; -import org.verapdf.tools.StaticResources; import org.verapdf.tools.TaggedPDFConstants; public class GFSEFactory { public static GFPDStructElem createTypedStructElem(PDStructElem structElemDictionary){ - StructureType standardStructureType = getStructureElementStandardStructureType(structElemDictionary); + StructureType standardStructureType = PDStructElem.getStructureElementStandardStructureType(structElemDictionary); String standardType = standardStructureType != null ? standardStructureType.getType().getValue() : null; - if (isMathStandardType(standardStructureType)) { + if (PDStructElem.isMathStandardType(standardStructureType)) { return new GFSEMathMLStructElem(structElemDictionary); } if (standardType == null) { @@ -152,35 +148,4 @@ public static GFPDStructElem createTypedStructElem(PDStructElem structElemDictio } } } - - public static StructureType getStructureElementStandardStructureType(PDStructElem pdStructElem) { - if (StaticContainers.getFlavour() != null && (StaticContainers.getFlavour().getPart() == - PDFAFlavour.Specification.ISO_19005_4 || StaticContainers.getFlavour().getPart() == - PDFAFlavour.Specification.ISO_14289_2 || StaticContainers.getFlavour().getPart() == - PDFAFlavour.Specification.WCAG_2_1)) { - StructureType defaultStructureType = pdStructElem.getDefaultStructureType(); - if (defaultStructureType != null) { - return defaultStructureType; - } - } - if (StaticContainers.getFlavour() == null || (StaticContainers.getFlavour().getPart() != - PDFAFlavour.Specification.ISO_19005_4 && StaticContainers.getFlavour().getPart() != - PDFAFlavour.Specification.ISO_14289_2)) { - StructureType type = pdStructElem.getStructureType(); - if (type != null) { - return StructureType.createStructureType(ASAtom.getASAtom(StaticResources.getRoleMapHelper().getStandardType(type.getType()))); - } - } - return null; - } - - public static String getStructureElementStandardType(PDStructElem pdStructElem) { - StructureType type = getStructureElementStandardStructureType(pdStructElem); - return type != null ? type.getType().getValue() : null; - } - - public static boolean isMathStandardType(StructureType standardStructureType) { - return StaticContainers.getFlavour() == PDFAFlavour.PDFUA_2 && standardStructureType != null && - TaggedPDFConstants.MATH_ML_NAMESPACE.equals(standardStructureType.getNameSpaceURI()); - } } diff --git a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/contents/GFSEGroupedContent.java b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/contents/GFSEGroupedContent.java index c84697e74..3fcd393f6 100644 --- a/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/contents/GFSEGroupedContent.java +++ b/validation-model/src/main/java/org/verapdf/gf/model/impl/pd/gfse/contents/GFSEGroupedContent.java @@ -64,7 +64,7 @@ public String getparentStandardTag() { TaggedPDFRoleMapHelper taggedPDFRoleMapHelper = StaticResources.getRoleMapHelper(); if (parentStructElem != null && taggedPDFRoleMapHelper != null) { PDStructElem structElem = new PDStructElem(parentStructElem, taggedPDFRoleMapHelper.getRoleMap()); - return GFSEFactory.getStructureElementStandardType(structElem); + return PDStructElem.getStructureElementStandardType(structElem); } return null; } @@ -88,7 +88,7 @@ protected Boolean hasParentWithStandardType(String standardType) { if (parentStructElem != null && taggedPDFRoleMapHelper != null) { PDStructElem structElem = new PDStructElem(parentStructElem, taggedPDFRoleMapHelper.getRoleMap()); while (structElem != null) { - if (standardType.equals(GFSEFactory.getStructureElementStandardType(structElem))) { + if (standardType.equals(PDStructElem.getStructureElementStandardType(structElem))) { return true; } structElem = structElem.getParent(); diff --git a/wcag-validation/src/main/java/org/verapdf/gf/model/impl/sa/GFSAStructElem.java b/wcag-validation/src/main/java/org/verapdf/gf/model/impl/sa/GFSAStructElem.java index 4cb3c165f..e37bdcd4c 100644 --- a/wcag-validation/src/main/java/org/verapdf/gf/model/impl/sa/GFSAStructElem.java +++ b/wcag-validation/src/main/java/org/verapdf/gf/model/impl/sa/GFSAStructElem.java @@ -29,6 +29,7 @@ import org.verapdf.pd.PDAnnotation; import org.verapdf.pd.structure.PDMCRDictionary; import org.verapdf.pd.structure.PDOBJRDictionary; +import org.verapdf.pd.structure.PDStructElem; import org.verapdf.tools.TaggedPDFConstants; import org.verapdf.wcag.algorithms.entities.*; import org.verapdf.wcag.algorithms.entities.content.IChunk; @@ -291,13 +292,13 @@ private static List getChildrenStandardTypes(GFSAStructElem element) { public String getparentStandardType() { org.verapdf.pd.structure.PDStructElem parent = this.structElemDictionary.getParent(); if (parent != null) { - String parentStandardType = GFSAFactory.getStructureElementStandardType(parent); + String parentStandardType = PDStructElem.getStructureElementStandardType(parent); while (TaggedPDFConstants.NON_STRUCT.equals(parentStandardType) || TaggedPDFConstants.DIV.equals(parentStandardType)) { parent = parent.getParent(); if (parent == null) { return null; } - parentStandardType = GFSAFactory.getStructureElementStandardType(parent); + parentStandardType = PDStructElem.getStructureElementStandardType(parent); } return parentStandardType; } diff --git a/wcag-validation/src/main/java/org/verapdf/gf/model/impl/sa/structelems/GFSAFactory.java b/wcag-validation/src/main/java/org/verapdf/gf/model/impl/sa/structelems/GFSAFactory.java index 313de1176..ba6c8427f 100644 --- a/wcag-validation/src/main/java/org/verapdf/gf/model/impl/sa/structelems/GFSAFactory.java +++ b/wcag-validation/src/main/java/org/verapdf/gf/model/impl/sa/structelems/GFSAFactory.java @@ -29,7 +29,7 @@ public class GFSAFactory { public static GFSAStructElem createTypedStructElem(PDStructElem structElemDictionary, String parentsStandardTypes){ - String standardType = getStructureElementStandardType(structElemDictionary); + String standardType = PDStructElem.getStructureElementStandardType(structElemDictionary); if (standardType == null) { return new GFSANonStandard(structElemDictionary, null, parentsStandardTypes); @@ -146,12 +146,4 @@ public static GFSAStructElem createTypedStructElem(PDStructElem structElemDictio } } } - - public static String getStructureElementStandardType(PDStructElem pdStructElem){ - StructureType type = pdStructElem.getStructureType(); - if (type != null) { - return StaticResources.getRoleMapHelper().getStandardType(type.getType()); - } - return null; - } }