public void expandNode(PdfObjectTreeNode node) { if (node.getChildCount() > 0) { return; } PdfObject object = node.getPdfObject(); PdfObjectTreeNode leaf; switch (object.type()) { case PdfObject.INDIRECT: PdfIndirectReference ref = (PdfIndirectReference) object; leaf = getNode(ref.getNumber()); addNodes(node, leaf); if (leaf instanceof PdfPagesTreeNode) expandNode(leaf); return; case PdfObject.ARRAY: PdfArray array = (PdfArray) object; for (Iterator<PdfObject> it = array.listIterator(); it.hasNext(); ) { leaf = PdfObjectTreeNode.getInstance(it.next()); addNodes(node, leaf); expandNode(leaf); } return; case PdfObject.DICTIONARY: case PdfObject.STREAM: PdfDictionary dict = (PdfDictionary) object; for (Iterator<PdfName> it = dict.getKeys().iterator(); it.hasNext(); ) { leaf = PdfObjectTreeNode.getInstance(dict, it.next()); addNodes(node, leaf); expandNode(leaf); } return; } }
private void addNodes(PdfObjectTreeNode parent, PdfObjectTreeNode child) { try { parent.add(child); } catch (IllegalArgumentException iae) { parent.setRecursive(true); } }
public PdfObjectTreeNode getNode(int ref) { int idx = objects.getIndexByRef(ref); PdfObjectTreeNode node = nodes.get(idx); if (node.getPdfObject().isNull()) { node = PdfObjectTreeNode.getInstance(objects.loadObjectByReference(ref), ref); nodes.set(idx, node); } return node; }
public PdfObjectTreeNode getAncestor() { if (isRecursive()) { PdfObjectTreeNode node = this; while (true) { node = (PdfObjectTreeNode) node.getParent(); if (node.isIndirectReference() && node.getNumber() == getNumber()) { return node; } } } return null; }
/** * Creates a node corresponding with a node in the PdfTree. * * @param node a corresponding node */ public FormTreeNode(PdfObjectTreeNode node) { super("form.png"); this.object_node = node; if (node.isDictionary()) { PdfDictionary dict = (PdfDictionary) node.getPdfObject(); PdfObject fieldname = dict.get(PdfName.T); if (fieldname != null) { this.setUserObject(fieldname); } else { this.setUserObject("unnamed field"); } } }
public TreeNodeFactory(IndirectObjectFactory objects) { this.objects = objects; for (int i = 0; i < objects.size(); i++) { int ref = objects.getRefByIndex(i); nodes.add(PdfObjectTreeNode.getInstance(PdfNull.PDFNULL, ref)); } }
@SuppressWarnings("unchecked") public PdfObjectTreeNode getChildNode(PdfObjectTreeNode node, PdfName key) { Enumeration<PdfObjectTreeNode> children = node.breadthFirstEnumeration(); PdfObjectTreeNode child; while (children.hasMoreElements()) { child = children.nextElement(); if (child.isDictionaryNode(key)) { if (child.isIndirectReference()) { expandNode(child); child = (PdfObjectTreeNode) child.getFirstChild(); } expandNode(child); return child; } } return null; }
public static PdfObjectTreeNode getInstance(PdfDictionary dict, PdfName key) { PdfObjectTreeNode node = getInstance(dict.get(key)); node.setUserObject(getDictionaryEntryCaption(dict, key)); node.key = key; return node; }
public static PdfObjectTreeNode getInstance(PdfObject object, int number) { PdfObjectTreeNode node = getInstance(object); node.number = number; return node; }