Skip to content

Commit

Permalink
Merge pull request #614 from veraPDF/standard_type
Browse files Browse the repository at this point in the history
Move standard structure types methods to parser
  • Loading branch information
MaximPlusov authored Nov 27, 2023
2 parents 17288cc + ccaf8b8 commit 0a9d69c
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -291,13 +292,13 @@ private static List<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 0a9d69c

Please sign in to comment.