private static String getCOSObjectID(COSObject cosObject) { if (cosObject != null) { COSKey mapObjectKey = cosObject.getObjectKey(); if (mapObjectKey != null) { return mapObjectKey.toString(); } else { return String.valueOf(cosObject.hashCode()); } } return NULL; }
protected PDFormField(COSObject obj, Set<COSKey> parents) { super(obj); COSKey objectKey = obj.getObjectKey(); this.parents = new HashSet<>(parents); if (objectKey != null) { if (this.parents.contains(objectKey)) { throw new LoopedException("Loop form field tree"); } else { this.parents.add(objectKey); } } }
private PDNameTreeNode(COSObject obj, Set<COSKey> parents) { super(obj); COSKey objectKey = obj.getObjectKey(); this.parents = new HashSet<>(parents); if (objectKey != null) { if (parents.contains(objectKey)) { throw new LoopedException("Loop in name tree"); } else { this.parents.add(objectKey); } } }
public COSKey getKeyForObject(COSObject obj) { if (obj.isIndirect()) { return obj.getObjectKey(); } else { for (COSKey key : this.table.keySet()) { if (this.table.get(key) == obj) { return key; } } return null; } } }
private List<COSKey> prepareAddedObjects(List<COSObject> addedObjects) { int cosKeyNumber = this.document.getLastKeyNumber() + 1; List<COSKey> res = new ArrayList<>(); for (COSObject obj : addedObjects) { if (!obj.isIndirect()) { COSObject indirect = COSIndirect.construct(obj, this.document); res.add(indirect.getObjectKey()); } else { res.add(obj.getObjectKey()); } } addedObjects.clear(); return res; }
/** * Caches structure name space. Key is chosen to be indirect reference key * of this namespace dictionary. * * @param nameSpace is PD structure name space to cache. */ public static void cacheStructureNameSpace(PDStructureNameSpace nameSpace) { checkForNull(structureNameSpaceCache); COSKey key = nameSpace.getObject().getObjectKey(); StaticResources.structureNameSpaceCache.get().put(key, nameSpace); }
private COSKey getObjectKey(final COSObject base) { COSKey res = null; if (base.isIndirect()) { COSObject item = base; while (item.isIndirect()) { res = item.getObjectKey(); item = base.getDirect(); } } else { res = base.getObjectKey(); } return res; }
/** * Gets object with given key from this node and it's kids recursively. * * @param key is integer that is a key for COSObject. * @return object for given key from this number tree node and it's kids or * null if object can't be found. */ public COSObject getObject(Long key) { HashSet<COSKey> visitedKeys = new HashSet<>(); COSKey objectKey = getObject().getObjectKey(); if (objectKey != null) { visitedKeys.add(objectKey); } return getObject(key, visitedKeys); }
private Set<COSKey> parentKeysForChildren() { Set<COSKey> res = new HashSet<>(); PDPageTreeNode curr = this; while (curr != null) { COSObject object = curr.getObject(); COSKey objectKey = object.getObjectKey(); if (res.contains(objectKey)) { throw new LoopedException("Page tree loop found"); } res.add(objectKey); curr = this.getParent(); } return Collections.unmodifiableSet(res); }
private static void addVisited(StructureType type) { ASAtom structType = type.getType(); PDStructureNameSpace nameSpace = type.getNameSpace(); if (nameSpace != null) { COSKey key = nameSpace.getObject().getObjectKey(); Set<COSKey> nameSpaces; if (visitedWithNS.containsKey(structType)) { nameSpaces = visitedWithNS.get(structType); } else { nameSpaces = new HashSet<>(); visitedWithNS.put(structType, nameSpaces); } nameSpaces.add(key); } else { visitedWithoutNS.add(structType); } }
private static boolean isVisited(StructureType type) { ASAtom structType = type.getType(); PDStructureNameSpace nameSpace = type.getNameSpace(); if (nameSpace != null) { if (visitedWithNS.containsKey(structType)) { Set<COSKey> nameSpaces = visitedWithNS.get(structType); COSKey key = nameSpace.getObject().getObjectKey(); return nameSpaces.contains(key); } else { return false; } } else { return visitedWithoutNS.contains(structType); } }
public GFPDSignature(org.verapdf.pd.PDSignature pdSignature, COSObject signatureReference) { super(pdSignature, SIGNATURE_TYPE); if(signatureReference.isIndirect().booleanValue()) { COSKey key = signatureReference.getObjectKey(); this.signatureOffset = StaticContainers.getDocument().getDocument().getOffset(key).longValue(); } contents = pdSignature.getContents(); }
@Override public Integer getKeyNumber() { if (outline != null && !outline.empty()) { COSObject cosObject = outline.getObject(); COSKey objectKey = cosObject.getObjectKey(); if (objectKey != null) { return objectKey.getNumber(); } } return null; }
public void writeIncrementalUpdate(List<COSObject> changedObjects, List<COSObject> addedObjects) { List<COSKey> objectsToWrite = new ArrayList<>(); for (COSObject obj : changedObjects) { COSKey key = obj.getObjectKey(); if (key != null) { objectsToWrite.add(obj.getObjectKey()); } } changedObjects.clear(); objectsToWrite.addAll(prepareAddedObjects(addedObjects)); this.addToWrite(objectsToWrite); this.writeBody(); COSTrailer trailer = document.getTrailer(); // document.getLastTrailerOffset() + 1 point EXACTLY at first byte of xref this.setTrailer(trailer, document.getLastTrailerOffset() + 1); this.writeXRefInfo(); this.clear(); }
public ASAtom getFT() { Set<COSKey> visitedKeys = new HashSet<>(); COSObject curr = getObject(); while (curr != null && curr.getType().isDictionaryBased()) { COSKey key = curr.getObjectKey(); if (key != null) { if (visitedKeys.contains(key)) { throw new LoopedException("Loop in field tree"); } visitedKeys.add(key); } if (curr.knownKey(ASAtom.FT)) { return curr.getNameKey(ASAtom.FT); } curr = curr.getKey(ASAtom.PARENT); } return null; }
private void processNavigationNodeActions(PDNavigationNode navNode, Set<COSKey> visitedKeys) { if (navNode != null) { COSKey objectKey = navNode.getObject().getObjectKey(); if (visitedKeys.contains(objectKey)) { return; } visitedKeys.add(objectKey); reportAction(navNode.getNA(), ActionFeaturesObjectAdapter.Location.PAGE); reportAction(navNode.getPA(), ActionFeaturesObjectAdapter.Location.PAGE); processNavigationNodeActions(navNode.getNext(), visitedKeys); processNavigationNodeActions(navNode.getPrev(), visitedKeys); } }
public GFPDObject(PDContentStream contentStream, final String type) { super(type); this.contentStream = contentStream; COSObject simpleObject = ((org.verapdf.pd.PDObject) contentStream).getObject(); if (simpleObject != null && !simpleObject.empty()) { COSKey key = simpleObject.getObjectKey(); id = key != null ? key.getNumber() + " " + key.getGeneration() + " obj " + this.getObjectType() : super.getID(); } }
private String getCMapID() { if (this.getObject().getType() == COSObjType.COS_STREAM) { return "CMap " + getObject().getObjectKey().toString(); } else if (this.getObject().getType() == COSObjType.COS_NAME) { return getObject().getString(); } return ""; }
public GFPDObject(org.verapdf.pd.PDObject simplePDObject, final String type) { super(type); this.simplePDObject = simplePDObject; if (simplePDObject != null && !simplePDObject.getObject().empty()) { this.simpleCOSObject = simplePDObject.getObject(); COSKey key = simplePDObject.getObject().getObjectKey(); id = key != null ? key.getNumber() + " " + key.getGeneration() + " obj " + this.getObjectType() : super.getID(); } }
public GFPDObject(PDCMap pdcMap, final String type) { super(type); this.pdcMap = pdcMap; this.simplePDObject = pdcMap; if (simplePDObject != null && !simplePDObject.getObject().empty()) { this.simpleCOSObject = simplePDObject.getObject(); COSKey key = simplePDObject.getObject().getObjectKey(); id = key != null ? key.getNumber() + " " + key.getGeneration() + " obj " + this.getObjectType() : super.getID(); } }