Skip to content

Commit

Permalink
Add StaticCoreContainers
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Jun 3, 2024
1 parent a8fb80e commit 8f3aae8
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.verapdf.containers;

import org.verapdf.pdfa.flavours.PDFAFlavour;

public class StaticCoreContainers {

private static final ThreadLocal<PDFAFlavour> flavour = new ThreadLocal<>();

public static void clearAllContainers() {
flavour.set(null);
}

public static PDFAFlavour getFlavour() {
return flavour.get();
}

public static void setFlavour(PDFAFlavour flavour) {
StaticCoreContainers.flavour.set(flavour);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.verapdf.model.tools.xmp.validators.SimpleTypeValidator;
import org.verapdf.model.tools.xmp.validators.URITypeValidator;
import org.verapdf.model.xmplayer.ExtensionSchemaDefinition;
import org.verapdf.pdfa.flavours.PDFAFlavour;

import java.util.*;

Expand All @@ -47,8 +46,8 @@ public class AXLExtensionSchemaDefinition extends AXLExtensionSchemaObject imple
private static final String VALUE_TYPE = "valueType";
private static final Set<String> validChildNames = new HashSet<>();

public AXLExtensionSchemaDefinition(VeraPDFXMPNode xmpNode, ValidatorsContainer containerForPDFA_1, ValidatorsContainer containerForPDFA_2_3, PDFAFlavour flavour) {
super(EXTENSION_SCHEMA_DEFINITION, xmpNode, containerForPDFA_1, containerForPDFA_2_3, flavour);
public AXLExtensionSchemaDefinition(VeraPDFXMPNode xmpNode, ValidatorsContainer containerForPDFA_1, ValidatorsContainer containerForPDFA_2_3) {
super(EXTENSION_SCHEMA_DEFINITION, xmpNode, containerForPDFA_1, containerForPDFA_2_3);
}

/**
Expand All @@ -74,7 +73,7 @@ private List<AXLExtensionSchemaValueType> getExtensionSchemaValueType() {
if (XMPConst.NS_PDFA_SCHEMA.equals(child.getNamespaceURI()) && VALUE_TYPE.equals(child.getName())) {
if (child.getOptions().isArray()) {
for (VeraPDFXMPNode node : child.getChildren()) {
res.add(new AXLExtensionSchemaValueType(node, this.containerForPDFA_1, this.containerForPDFA_2_3, this.flavour));
res.add(new AXLExtensionSchemaValueType(node, this.containerForPDFA_1, this.containerForPDFA_2_3));
}
}
break;
Expand All @@ -92,7 +91,7 @@ private List<AXLExtensionSchemaProperty> getExtensionSchemaProperties() {
if (XMPConst.NS_PDFA_SCHEMA.equals(child.getNamespaceURI()) && PROPERTY.equals(child.getName())) {
if (child.getOptions().isArray()) {
for (VeraPDFXMPNode node : child.getChildren()) {
res.add(new AXLExtensionSchemaProperty(node, this.containerForPDFA_1, this.containerForPDFA_2_3, this.flavour));
res.add(new AXLExtensionSchemaProperty(node, this.containerForPDFA_1, this.containerForPDFA_2_3));
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
package org.verapdf.model.impl.axl;

import org.verapdf.containers.StaticCoreContainers;
import org.verapdf.pdfa.flavours.PDFFlavours;
import org.verapdf.xmp.XMPConst;
import org.verapdf.xmp.impl.VeraPDFXMPNode;
import org.verapdf.model.tools.xmp.ValidatorsContainer;
Expand All @@ -41,8 +43,8 @@ public class AXLExtensionSchemaField extends AXLExtensionSchemaObject implements
private static final String VALUE_TYPE = "valueType";
private static final Set<String> validChildNames = new HashSet<>();

public AXLExtensionSchemaField(VeraPDFXMPNode xmpNode, ValidatorsContainer containerForPDFA_1, ValidatorsContainer containerForPDFA_2_3, PDFAFlavour flavour) {
super(EXTENSION_SCHEMA_FIELD, xmpNode, containerForPDFA_1, containerForPDFA_2_3, flavour);
public AXLExtensionSchemaField(VeraPDFXMPNode xmpNode, ValidatorsContainer containerForPDFA_1, ValidatorsContainer containerForPDFA_2_3) {
super(EXTENSION_SCHEMA_FIELD, xmpNode, containerForPDFA_1, containerForPDFA_2_3);
}

@Override
Expand Down Expand Up @@ -77,7 +79,7 @@ public Boolean getisValueTypeValidText() {

@Override
public Boolean getisValueTypeDefined() {
if (this.flavour != null && this.flavour.getPart() == PDFAFlavour.Specification.ISO_19005_1) {
if (PDFFlavours.isFlavourPart(StaticCoreContainers.getFlavour(), PDFAFlavour.Specification.ISO_19005_1)) {
return isValueTypeValidForPDFA_1();
}
return isValueTypeValidForPDFA_2_3();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.verapdf.xmp.impl.VeraPDFXMPNode;
import org.verapdf.model.tools.xmp.ValidatorsContainer;
import org.verapdf.model.xmplayer.ExtensionSchemaObject;
import org.verapdf.pdfa.flavours.PDFAFlavour;

import java.util.LinkedList;
import java.util.List;
Expand All @@ -37,14 +36,12 @@ public abstract class AXLExtensionSchemaObject extends AXLXMPObject implements E
protected final VeraPDFXMPNode xmpNode;
protected final ValidatorsContainer containerForPDFA_1;
protected final ValidatorsContainer containerForPDFA_2_3;
protected final PDFAFlavour flavour;

public AXLExtensionSchemaObject(String type, VeraPDFXMPNode xmpNode, ValidatorsContainer containerForPDFA_1, ValidatorsContainer containerForPDFA_2_3, PDFAFlavour flavour) {
public AXLExtensionSchemaObject(String type, VeraPDFXMPNode xmpNode, ValidatorsContainer containerForPDFA_1, ValidatorsContainer containerForPDFA_2_3) {
super(type);
this.xmpNode = xmpNode;
this.containerForPDFA_1 = containerForPDFA_1;
this.containerForPDFA_2_3 = containerForPDFA_2_3;
this.flavour = flavour;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
package org.verapdf.model.impl.axl;

import org.verapdf.containers.StaticCoreContainers;
import org.verapdf.xmp.XMPConst;
import org.verapdf.xmp.impl.VeraPDFXMPNode;
import org.verapdf.model.tools.xmp.ValidatorsContainer;
Expand All @@ -42,8 +43,8 @@ public class AXLExtensionSchemaProperty extends AXLExtensionSchemaObject impleme
private static final String VALUE_TYPE = "valueType";
private static final Set<String> validChildNames = new HashSet<>();

public AXLExtensionSchemaProperty(VeraPDFXMPNode xmpNode, ValidatorsContainer containerForPDFA_1, ValidatorsContainer containerForPDFA_2_3, PDFAFlavour flavour) {
super(EXTENSION_SCHEMA_PROPERTY, xmpNode, containerForPDFA_1, containerForPDFA_2_3, flavour);
public AXLExtensionSchemaProperty(VeraPDFXMPNode xmpNode, ValidatorsContainer containerForPDFA_1, ValidatorsContainer containerForPDFA_2_3) {
super(EXTENSION_SCHEMA_PROPERTY, xmpNode, containerForPDFA_1, containerForPDFA_2_3);
}

@Override
Expand Down Expand Up @@ -98,7 +99,7 @@ public Boolean getisValueTypeValidText() {

@Override
public Boolean getisValueTypeDefined() {
if (this.flavour != null && this.flavour.getPart() == PDFAFlavour.Specification.ISO_19005_1) {
if (StaticCoreContainers.getFlavour() != null && StaticCoreContainers.getFlavour().getPart() == PDFAFlavour.Specification.ISO_19005_1) {
return isValueTypeValidForPDFA_1();
}
return isValueTypeValidForPDFA_2_3();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.verapdf.model.tools.xmp.validators.SimpleTypeValidator;
import org.verapdf.model.tools.xmp.validators.URITypeValidator;
import org.verapdf.model.xmplayer.ExtensionSchemaValueType;
import org.verapdf.pdfa.flavours.PDFAFlavour;

import java.util.*;

Expand All @@ -47,8 +46,8 @@ public class AXLExtensionSchemaValueType extends AXLExtensionSchemaObject implem
private static final String TYPE = "type";
private static final Set<String> validChildNames = new HashSet<>();

public AXLExtensionSchemaValueType(VeraPDFXMPNode xmpNode, ValidatorsContainer containerForPDFA_1, ValidatorsContainer containerForPDFA_2_3, PDFAFlavour flavour) {
super(EXTENSION_SCHEMA_VALUE_TYPE, xmpNode, containerForPDFA_1, containerForPDFA_2_3, flavour);
public AXLExtensionSchemaValueType(VeraPDFXMPNode xmpNode, ValidatorsContainer containerForPDFA_1, ValidatorsContainer containerForPDFA_2_3) {
super(EXTENSION_SCHEMA_VALUE_TYPE, xmpNode, containerForPDFA_1, containerForPDFA_2_3);
}

/**
Expand All @@ -72,7 +71,7 @@ private List<AXLExtensionSchemaField> getExtensionSchemaFields() {
if (XMPConst.NS_PDFA_TYPE.equals(child.getNamespaceURI()) && FIELD.equals(child.getName())) {
if (child.getOptions().isArray()) {
for (VeraPDFXMPNode node : child.getChildren()) {
res.add(new AXLExtensionSchemaField(node, this.containerForPDFA_1, this.containerForPDFA_2_3, this.flavour));
res.add(new AXLExtensionSchemaField(node, this.containerForPDFA_1, this.containerForPDFA_2_3));
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.verapdf.model.tools.xmp.ValidatorsContainer;
import org.verapdf.model.tools.xmp.ValidatorsContainerCreator;
import org.verapdf.model.xmplayer.ExtensionSchemasContainer;
import org.verapdf.pdfa.flavours.PDFAFlavour;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -47,14 +46,12 @@ public class AXLExtensionSchemasContainer extends AXLXMPObject implements Extens
protected final VeraPDFXMPNode xmpNode;
protected final Map<String, SchemasDefinition> containerForPDFA_1;
protected final Map<String, SchemasDefinition> containerForPDFA_2_3;
protected final PDFAFlavour flavour;

public AXLExtensionSchemasContainer(VeraPDFXMPNode xmpNode, Map<String, SchemasDefinition> containerForPDFA_1, Map<String, SchemasDefinition> containerForPDFA_2_3, PDFAFlavour flavour) {
public AXLExtensionSchemasContainer(VeraPDFXMPNode xmpNode, Map<String, SchemasDefinition> containerForPDFA_1, Map<String, SchemasDefinition> containerForPDFA_2_3) {
super(EXTENSION_SCHEMAS_CONTAINER);
this.xmpNode = xmpNode;
this.containerForPDFA_1 = containerForPDFA_1;
this.containerForPDFA_2_3 = containerForPDFA_2_3;
this.flavour = flavour;
}

/**
Expand Down Expand Up @@ -90,7 +87,7 @@ private List<AXLExtensionSchemaDefinition> getExtensionSchemaDefinitions() {
}
}
}
res.add(new AXLExtensionSchemaDefinition(node, containerForPDFA_1, containerForPDFA_2_3, this.flavour));
res.add(new AXLExtensionSchemaDefinition(node, containerForPDFA_1, containerForPDFA_2_3));
}
return Collections.unmodifiableList(res);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.verapdf.xmp.impl.VeraPDFXMPNode;
import org.verapdf.model.baselayer.Object;
import org.verapdf.model.xmplayer.MainXMPPackage;
import org.verapdf.pdfa.flavours.PDFAFlavour;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -51,12 +50,12 @@ public class AXLMainXMPPackage extends AXLXMPPackage implements MainXMPPackage {
* @param xmpMetadata object that represents this package
* @param isSerializationValid true if metadata is valid
*/
public AXLMainXMPPackage(VeraPDFMeta xmpMetadata, boolean isSerializationValid, PDFAFlavour flavour) {
super(xmpMetadata, isSerializationValid, true, false, null, MAIN_XMP_PACKAGE_TYPE, flavour);
public AXLMainXMPPackage(VeraPDFMeta xmpMetadata, boolean isSerializationValid) {
super(xmpMetadata, isSerializationValid, true, false, null, MAIN_XMP_PACKAGE_TYPE);
}

public AXLMainXMPPackage(VeraPDFMeta xmpMetadata, boolean isSerializationValid, boolean isClosedChoiceCheck, PDFAFlavour flavour) {
super(xmpMetadata, isSerializationValid, true, isClosedChoiceCheck, null, MAIN_XMP_PACKAGE_TYPE, flavour);
public AXLMainXMPPackage(VeraPDFMeta xmpMetadata, boolean isSerializationValid, boolean isClosedChoiceCheck) {
super(xmpMetadata, isSerializationValid, true, isClosedChoiceCheck, null, MAIN_XMP_PACKAGE_TYPE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.verapdf.xmp.impl.XMPNode;
import org.verapdf.model.tools.xmp.SchemasDefinition;
import org.verapdf.model.xmplayer.XMPLangAlt;
import org.verapdf.pdfa.flavours.PDFAFlavour;

import java.util.List;

Expand All @@ -36,8 +35,8 @@ public class AXLXMPLangAlt extends AXLXMPProperty implements XMPLangAlt {

public static final String XMPMM_LANGUAGE_ALTERNATIVE_PROPERTY_TYPE = "XMPLangAlt";

public AXLXMPLangAlt(VeraPDFXMPNode xmpNode, boolean isMainMetadata, boolean isClosedChoiceCheck, SchemasDefinition mainPackageSchemasDefinition, SchemasDefinition currentSchemasDefinitionPDFA_1, SchemasDefinition currentSchemasDefinitionPDFA_2_3, PDFAFlavour flavour) {
super(xmpNode, XMPMM_LANGUAGE_ALTERNATIVE_PROPERTY_TYPE, isMainMetadata, isClosedChoiceCheck, mainPackageSchemasDefinition, currentSchemasDefinitionPDFA_1, currentSchemasDefinitionPDFA_2_3, flavour);
public AXLXMPLangAlt(VeraPDFXMPNode xmpNode, boolean isMainMetadata, boolean isClosedChoiceCheck, SchemasDefinition mainPackageSchemasDefinition, SchemasDefinition currentSchemasDefinitionPDFA_1, SchemasDefinition currentSchemasDefinitionPDFA_2_3) {
super(xmpNode, XMPMM_LANGUAGE_ALTERNATIVE_PROPERTY_TYPE, isMainMetadata, isClosedChoiceCheck, mainPackageSchemasDefinition, currentSchemasDefinitionPDFA_1, currentSchemasDefinitionPDFA_2_3);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.verapdf.model.tools.xmp.SchemasDefinition;
import org.verapdf.model.xmplayer.XMPMMHistoryProperty;
import org.verapdf.model.xmplayer.XMPMMHistoryResourceEvent;
import org.verapdf.pdfa.flavours.PDFAFlavour;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -40,8 +39,8 @@ public class AXLXMPMMHistoryProperty extends AXLXMPProperty implements XMPMMHist

public static final String RESOURCE_EVENTS = "ResourceEvents";

public AXLXMPMMHistoryProperty(VeraPDFXMPNode xmpNode, boolean isMainMetadata, boolean isClosedChoiceCheck, SchemasDefinition mainPackageSchemasDefinition, SchemasDefinition currentSchemasDefinitionPDFA_1, SchemasDefinition currentSchemasDefinitionPDFA_2_3, PDFAFlavour flavour) {
super(xmpNode, XMPMM_HISTORY_PROPERTY_TYPE, isMainMetadata, isClosedChoiceCheck, mainPackageSchemasDefinition, currentSchemasDefinitionPDFA_1, currentSchemasDefinitionPDFA_2_3, flavour);
public AXLXMPMMHistoryProperty(VeraPDFXMPNode xmpNode, boolean isMainMetadata, boolean isClosedChoiceCheck, SchemasDefinition mainPackageSchemasDefinition, SchemasDefinition currentSchemasDefinitionPDFA_1, SchemasDefinition currentSchemasDefinitionPDFA_2_3) {
super(xmpNode, XMPMM_HISTORY_PROPERTY_TYPE, isMainMetadata, isClosedChoiceCheck, mainPackageSchemasDefinition, currentSchemasDefinitionPDFA_1, currentSchemasDefinitionPDFA_2_3);
}

/**
Expand Down
26 changes: 9 additions & 17 deletions core/src/main/java/org/verapdf/model/impl/axl/AXLXMPPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.verapdf.model.tools.xmp.SchemasDefinition;
import org.verapdf.model.tools.xmp.SchemasDefinitionCreator;
import org.verapdf.model.xmplayer.XMPPackage;
import org.verapdf.pdfa.flavours.PDFAFlavour;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -57,30 +56,28 @@ public class AXLXMPPackage extends AXLXMPObject implements XMPPackage {
//------------------------------------------------------------------------------ veraPDF: additional field for actual encoding
private final String actualEncoding;
private final boolean isMainMetadata;
private final PDFAFlavour flavour;
private final boolean isClosedChoiceCheck;
private Map<String, SchemasDefinition> mainPackageSchemasDefinition;
private Map<String, SchemasDefinition> currentSchemasDefinitionPDFA_1;
private Map<String, SchemasDefinition> currentSchemasDefinitionPDFA_2_3;

public AXLXMPPackage(VeraPDFMeta xmpMetadata, boolean isSerializationValid,
boolean isClosedChoiceCheck,
VeraPDFXMPNode mainPackageExtensionNode, PDFAFlavour flavour) {
VeraPDFXMPNode mainPackageExtensionNode) {
this(xmpMetadata, isSerializationValid, false, isClosedChoiceCheck,
mainPackageExtensionNode, XMP_PACKAGE_TYPE, flavour);
mainPackageExtensionNode, XMP_PACKAGE_TYPE);
}

public AXLXMPPackage(VeraPDFMeta xmpMetadata, boolean isSerializationValid,
VeraPDFXMPNode mainPackageExtensionNode, PDFAFlavour flavour) {
VeraPDFXMPNode mainPackageExtensionNode) {
this(xmpMetadata, isSerializationValid, false, false,
mainPackageExtensionNode, XMP_PACKAGE_TYPE, flavour);
mainPackageExtensionNode, XMP_PACKAGE_TYPE);
}

protected AXLXMPPackage(VeraPDFMeta xmpMetadata,
boolean isSerializationValid, boolean isMainMetadata,
boolean isClosedChoiceCheck,
VeraPDFXMPNode mainPackageExtensionNode, final String type,
PDFAFlavour flavour) {
VeraPDFXMPNode mainPackageExtensionNode, final String type) {
super(type);
this.xmpMetadata = xmpMetadata;
this.isSerializationValid = isSerializationValid;
Expand All @@ -91,7 +88,6 @@ protected AXLXMPPackage(VeraPDFMeta xmpMetadata,
this.mainPackageSchemasDefinition = SchemasDefinitionCreator
.createExtendedSchemasDefinitionForPDFA_2_3(
mainPackageExtensionNode, this.isClosedChoiceCheck);
this.flavour = flavour;
}

/**
Expand All @@ -117,8 +113,7 @@ private List<AXLExtensionSchemasContainer> getExtensionSchemasContainers() {
List<AXLExtensionSchemasContainer> res = new ArrayList<>(1);
res.add(new AXLExtensionSchemasContainer(this.getXmpMetadata()
.getExtensionSchemasNode(), getCurrentSchemasDefinitionPDFA_1(),
getCurrentSchemasDefinitionPDFA_2_3(),
this.flavour));
getCurrentSchemasDefinitionPDFA_2_3()));
return Collections.unmodifiableList(res);
}

Expand Down Expand Up @@ -146,23 +141,20 @@ private AXLXMPProperty createProperty(VeraPDFXMPNode node) {
this.isClosedChoiceCheck,
this.getMainPackageSchemasDefinitionForNS(namespaceURI),
this.getCurrentSchemasDefinitionPDFA_1ForNS(namespaceURI),
this.getCurrentSchemasDefinitionPDFA_2_3ForNS(namespaceURI),
this.flavour);
this.getCurrentSchemasDefinitionPDFA_2_3ForNS(namespaceURI));
}
if (node.isLanguageAlternative()) {
return new AXLXMPLangAlt(node, this.isMainMetadata,
this.isClosedChoiceCheck,
this.getMainPackageSchemasDefinitionForNS(namespaceURI),
this.getCurrentSchemasDefinitionPDFA_1ForNS(namespaceURI),
this.getCurrentSchemasDefinitionPDFA_2_3ForNS(namespaceURI),
this.flavour);
this.getCurrentSchemasDefinitionPDFA_2_3ForNS(namespaceURI));
}
return new AXLXMPProperty(node, this.isMainMetadata,
this.isClosedChoiceCheck,
this.getMainPackageSchemasDefinitionForNS(namespaceURI),
this.getCurrentSchemasDefinitionPDFA_1ForNS(namespaceURI),
this.getCurrentSchemasDefinitionPDFA_2_3ForNS(namespaceURI),
this.flavour);
this.getCurrentSchemasDefinitionPDFA_2_3ForNS(namespaceURI));
}

protected VeraPDFMeta getXmpMetadata() {
Expand Down
Loading

0 comments on commit 8f3aae8

Please sign in to comment.