public static PDNameTreeNode create(COSObject object) { if (object == null || !object.getType().isDictionaryBased()) { throw new IllegalArgumentException("Argument object shall be dictionary or stream type"); } return new PDNameTreeNode(object, new HashSet<COSKey>()); }
public List<PDNameTreeNode> getKids() { if (this.kids == null) { this.kids = parseKids(); } return Collections.unmodifiableList(this.kids); }
public Map<String, COSObject> getNames() { if (this.names == null) { this.names = parseNames(); } return Collections.unmodifiableMap(this.names); }
private void getNamesEmbeddedFiles(List<CosFileSpecification> files, PDNameTreeNode node) { Map<String, COSObject> names = node.getNames(); for (COSObject value : names.values()) { if (value != null && value.getType().isDictionaryBased()) { files.add(new GFCosFileSpecification((COSDictionary) value.getDirectBase())); } } for (PDNameTreeNode kid : node.getKids()) { getNamesEmbeddedFiles(files, kid); } }
private PDNameTreeNode getNameTreeByName(ASAtom name) { COSObject base = getKey(name); if (base != null && base.getType() == COSObjType.COS_DICT) { return PDNameTreeNode.create(base); } return null; } }
private List<PDNameTreeNode> parseKids() { COSObject kids = getKey(ASAtom.KIDS); if (kids != null && kids.getType() == COSObjType.COS_ARRAY) { List<PDNameTreeNode> res = new ArrayList<>(); for (COSObject obj : (COSArray) kids.getDirectBase()) { if (obj != null && obj.getType().isDictionaryBased()) { res.add(new PDNameTreeNode(obj, this.parents)); } } return res; } return Collections.emptyList(); }
private Map<String, COSObject> parseNames() { COSObject names = getKey(ASAtom.NAMES); if (names != null && names.getType() == COSObjType.COS_ARRAY) { Map<String, COSObject> res = new LinkedHashMap<>(); for (int i = 0; i < names.size(); i+=2) { COSObject keyObj = names.at(i); String key = keyObj == null ? null : keyObj.getString(); if (key != null) { COSObject value = names.at(i+1); res.put(key, value); } } return res; } return Collections.emptyMap(); } }
private void reportJavaScripts(final PDNameTreeNode node) { Map<String, COSObject> names = node.getNames(); for (COSObject value : names.values()) { if (value != null && value.getType().isDictionaryBased()) { reportAction(new PDAction(value), ActionFeaturesObjectAdapter.Location.DOCUMENT); } } for (PDNameTreeNode kid : node.getKids()) { reportJavaScripts(kid); } }
/** * @return list of embedded files */ private List<CosFileSpecification> getEmbeddedFiles() { if (this.catalog != null) { COSObject buffer = this.catalog.getKey(ASAtom.NAMES); if (!buffer.empty()) { COSObject base = buffer.getKey(ASAtom.EMBEDDED_FILES); if (base != null && base.getType() == COSObjType.COS_DICT) { List<CosFileSpecification> files = new ArrayList<>(); this.getNamesEmbeddedFiles(files, PDNameTreeNode.create(base)); return Collections.unmodifiableList(files); } } } return Collections.emptyList(); }
private int reportEmbeddedFileNode(final PDNameTreeNode node, final int index) { int res = index; Map<String, COSObject> names = node.getNames(); for (COSObject value : names.values()) { if (value != null && value.getType().isDictionaryBased()) { reporter.report(GFFeaturesObjectCreator.createEmbeddedFileFeaturesObject(value, ++res)); } } for (PDNameTreeNode kid : node.getKids()) { res = reportEmbeddedFileNode(kid, res); } return res; }