Skip to content

Commit

Permalink
Arlington. Add new methods
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Nov 5, 2023
1 parent 1e6901e commit 97a2fa3
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@

import org.verapdf.as.ASAtom;
import org.verapdf.cos.COSDocument;
import org.verapdf.gf.model.impl.arlington.*;
import org.verapdf.parser.PDFFlavour;
import org.verapdf.pd.PDCatalog;
import org.verapdf.tools.StaticResources;
import org.verapdf.xmp.XMPException;
import org.verapdf.xmp.impl.VeraPDFMeta;
import org.verapdf.ReleaseDetails;
import org.verapdf.pdfa.flavours.PDFAFlavours;
import org.verapdf.gf.model.impl.arlington.GFAFileTrailer;
import org.verapdf.component.ComponentDetails;
import org.verapdf.component.Components;
import org.verapdf.core.EncryptedPdfException;
Expand Down Expand Up @@ -263,7 +263,8 @@ public PDDocument getPDDocument() {
public org.verapdf.model.baselayer.Object getRoot() {
if (PDFAFlavour.ARLINGTON1_0.getPart().getFamily().equals(this.flavour.getPart().getFamily()) ||
PDFAFlavour.ARLINGTON2_0.getPart().getFamily().equals(this.flavour.getPart().getFamily())) {
return new GFAFileTrailer(this.document.getDocument().getTrailer().getObject().getDirectBase(), null, null);
GFAObject.clearAllContainers();
return new GFADocument(null, null, null);
}
return new GFCosDocument(this.document.getDocument());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
package org.verapdf.gf.model.impl.arlington;

import org.verapdf.cos.*;
import org.verapdf.model.alayer.*;
import org.verapdf.gf.model.impl.containers.StaticContainers;
import org.verapdf.tools.StaticResources;
import java.util.*;
import org.verapdf.pd.PDNameTreeNode;
import org.verapdf.as.ASAtom;
import java.util.stream.Collectors;
import org.verapdf.pd.structure.PDNumberTreeNode;

public class GFADocument extends GFAObject implements ADocument {

public GFADocument(COSBase baseObject, COSBase parentObject, String keyName) {
super(baseObject, parentObject, keyName, "ADocument");
}

@Override
public List<? extends org.verapdf.model.baselayer.Object> getLinkedObjects(String link) {
switch (link) {
case "FileTrailer":
return getFileTrailer();
case "LinearizationParameterDict":
return getLinearizationParameterDict();
case "ObjectStreams":
return getObjectStreams();
case "XRefStream":
return getXRefStream();
default:
return super.getLinkedObjects(link);
}
}

private List<AFileTrailer> getFileTrailer() {
return getFileTrailer1_0();
}

private List<AFileTrailer> getFileTrailer1_0() {
COSObject object = getFileTrailerValue();
if (object == null) {
return Collections.emptyList();
}
if (object.getType() == COSObjType.COS_DICT) {
List<AFileTrailer> list = new ArrayList<>(1);
list.add(new GFAFileTrailer((COSDictionary)object.getDirectBase(), this.baseObject, "FileTrailer"));
return Collections.unmodifiableList(list);
}
return Collections.emptyList();
}

private List<ALinearizationParameterDict> getLinearizationParameterDict() {
switch (StaticContainers.getFlavour()) {
case ARLINGTON1_2:
case ARLINGTON1_3:
case ARLINGTON1_4:
case ARLINGTON1_5:
case ARLINGTON1_6:
case ARLINGTON1_7:
case ARLINGTON2_0:
return getLinearizationParameterDict1_2();
default:
return Collections.emptyList();
}
}

private List<ALinearizationParameterDict> getLinearizationParameterDict1_2() {
COSObject object = getLinearizationParameterDictValue();
if (object == null) {
return Collections.emptyList();
}
if (object.getType() == COSObjType.COS_DICT) {
List<ALinearizationParameterDict> list = new ArrayList<>(1);
list.add(new GFALinearizationParameterDict((COSDictionary)object.getDirectBase(), this.baseObject, "LinearizationParameterDict"));
return Collections.unmodifiableList(list);
}
return Collections.emptyList();
}

private List<AArrayOfObjectStreams> getObjectStreams() {
switch (StaticContainers.getFlavour()) {
case ARLINGTON1_5:
case ARLINGTON1_6:
case ARLINGTON1_7:
case ARLINGTON2_0:
return getObjectStreams1_5();
default:
return Collections.emptyList();
}
}

private List<AArrayOfObjectStreams> getObjectStreams1_5() {
COSObject object = getObjectStreamsValue();
if (object == null) {
return Collections.emptyList();
}
if (object.getType() == COSObjType.COS_ARRAY) {
List<AArrayOfObjectStreams> list = new ArrayList<>(1);
list.add(new GFAArrayOfObjectStreams((COSArray)object.getDirectBase(), this.baseObject, "ObjectStreams"));
return Collections.unmodifiableList(list);
}
return Collections.emptyList();
}

private List<AXRefStream> getXRefStream() {
switch (StaticContainers.getFlavour()) {
case ARLINGTON1_5:
case ARLINGTON1_6:
case ARLINGTON1_7:
case ARLINGTON2_0:
return getXRefStream1_5();
default:
return Collections.emptyList();
}
}

private List<AXRefStream> getXRefStream1_5() {
COSObject object = getXRefStreamValue();
if (object == null) {
return Collections.emptyList();
}
if (object.getType() == COSObjType.COS_STREAM) {
List<AXRefStream> list = new ArrayList<>(1);
list.add(new GFAXRefStream((COSStream)object.getDirectBase(), this.baseObject, "XRefStream"));
return Collections.unmodifiableList(list);
}
return Collections.emptyList();
}

@Override
public Boolean getcontainsFileTrailer() {
return getFileTrailerValue() != null;
}

public COSObject getFileTrailerValue() {
if (StaticResources.getDocument().getDocument().getLastXRefStream() == null) {
return null;
}
COSObject object = StaticResources.getDocument().getDocument().getTrailer().getObject();
return object;
}

@Override
public String getFileTrailerType() {
COSObject FileTrailer = getFileTrailerValue();
return getObjectType(FileTrailer);
}

@Override
public Boolean getFileTrailerHasTypeDictionary() {
COSObject FileTrailer = getFileTrailerValue();
return getHasTypeDictionary(FileTrailer);
}

@Override
public Boolean getcontainsLinearizationParameterDict() {
return getLinearizationParameterDictValue() != null;
}

public COSObject getLinearizationParameterDictValue() {
COSObject object = StaticResources.getDocument().getDocument().getLinearizationDictionary();
return object;
}

@Override
public Boolean getcontainsObjectStreams() {
return getObjectStreamsValue() != null;
}

public COSObject getObjectStreamsValue() {
COSObject object = new COSObject(new COSArray(StaticResources.getDocument().getDocument().getObjectStreamsList()));
return object;
}

@Override
public Boolean getcontainsXRefStream() {
return getXRefStreamValue() != null;
}

public COSObject getXRefStreamValue() {
COSObject object = StaticResources.getDocument().getDocument().getLastXRefStream();
return object;
}

@Override
public String getXRefStreamType() {
COSObject XRefStream = getXRefStreamValue();
return getObjectType(XRefStream);
}

@Override
public Boolean getXRefStreamHasTypeStream() {
COSObject XRefStream = getXRefStreamValue();
return getHasTypeStream(XRefStream);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class GFAFileTrailer extends GFAObject implements AFileTrailer {

public GFAFileTrailer(COSBase baseObject, COSBase parentObject, String keyName) {
super(baseObject, parentObject, keyName, "AFileTrailer");
GFAObject.clearAllContainers();
}

@Override
Expand All @@ -28,10 +27,6 @@ public List<? extends org.verapdf.model.baselayer.Object> getLinkedObjects(Strin
return getentryID();
case "Info":
return getInfo();
case "LinearizationParameterDict":
return getLinearizationParameterDict();
case "ObjectStreams":
return getObjectStreams();
case "Root":
return getRoot();
case "XRefStream":
Expand Down Expand Up @@ -162,59 +157,6 @@ private List<ADocInfo> getInfo1_0() {
return Collections.emptyList();
}

private List<ALinearizationParameterDict> getLinearizationParameterDict() {
switch (StaticContainers.getFlavour()) {
case ARLINGTON1_2:
case ARLINGTON1_3:
case ARLINGTON1_4:
case ARLINGTON1_5:
case ARLINGTON1_6:
case ARLINGTON1_7:
case ARLINGTON2_0:
return getLinearizationParameterDict1_2();
default:
return Collections.emptyList();
}
}

private List<ALinearizationParameterDict> getLinearizationParameterDict1_2() {
COSObject object = getLinearizationParameterDictValue();
if (object == null) {
return Collections.emptyList();
}
if (object.getType() == COSObjType.COS_DICT) {
List<ALinearizationParameterDict> list = new ArrayList<>(1);
list.add(new GFALinearizationParameterDict((COSDictionary)object.getDirectBase(), this.baseObject, "LinearizationParameterDict"));
return Collections.unmodifiableList(list);
}
return Collections.emptyList();
}

private List<AArrayOfObjectStreams> getObjectStreams() {
switch (StaticContainers.getFlavour()) {
case ARLINGTON1_5:
case ARLINGTON1_6:
case ARLINGTON1_7:
case ARLINGTON2_0:
return getObjectStreams1_5();
default:
return Collections.emptyList();
}
}

private List<AArrayOfObjectStreams> getObjectStreams1_5() {
COSObject object = getObjectStreamsValue();
if (object == null) {
return Collections.emptyList();
}
if (object.getType() == COSObjType.COS_ARRAY) {
List<AArrayOfObjectStreams> list = new ArrayList<>(1);
list.add(new GFAArrayOfObjectStreams((COSArray)object.getDirectBase(), this.baseObject, "ObjectStreams"));
return Collections.unmodifiableList(list);
}
return Collections.emptyList();
}

private List<ACatalog> getRoot() {
return getRoot1_0();
}
Expand Down Expand Up @@ -363,16 +305,6 @@ public Boolean getInfoHasTypeDictionary() {
return getHasTypeDictionary(Info);
}

public COSObject getLinearizationParameterDictValue() {
COSObject object = StaticResources.getDocument().getDocument().getLinearizationDictionary();
return object;
}

public COSObject getObjectStreamsValue() {
COSObject object = new COSObject(new COSArray(StaticResources.getDocument().getDocument().getObjectStreamsList()));
return object;
}

@Override
public Boolean getcontainsPrev() {
return this.baseObject.knownKey(ASAtom.getASAtom("Prev"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public GFAObject(COSBase baseObject, COSBase parentObject, String keyName, Strin

@Override
public String getID() {
COSKey key = baseObject.getObjectKey();
COSKey key = baseObject != null ? baseObject.getObjectKey() : null;
return key != null ? (getObjectType() + " " + key.toString()) : null;
}

Expand Down

0 comments on commit 97a2fa3

Please sign in to comment.