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; } }
protected PdfObjectTreeNode(PdfObject object) { super(null, getCaption(object)); this.object = object; switch (object.type()) { case PdfObject.INDIRECT: if (isRecursive()) icon = IconFetcher.getIcon("ref_recursive.png"); else icon = IconFetcher.getIcon("ref.png"); return; case PdfObject.ARRAY: icon = IconFetcher.getIcon("array.png"); return; case PdfObject.DICTIONARY: icon = IconFetcher.getIcon("dictionary.png"); return; case PdfObject.STREAM: icon = IconFetcher.getIcon("stream.png"); return; case PdfObject.BOOLEAN: icon = IconFetcher.getIcon("boolean.png"); return; case PdfObject.NAME: icon = IconFetcher.getIcon("name.png"); return; case PdfObject.NULL: icon = IconFetcher.getIcon("null.png"); return; case PdfObject.NUMBER: icon = IconFetcher.getIcon("number.png"); return; case PdfObject.STRING: icon = IconFetcher.getIcon("string.png"); return; } }
public static String getCaption(PdfObject object) { if (object == null) return "null"; switch (object.type()) { case PdfObject.INDIRECT: return "Indirect reference: " + object.toString(); case PdfObject.ARRAY: return "Array"; case PdfObject.STREAM: return "Stream"; case PdfObject.STRING: return ((PdfString) object).toUnicodeString(); } return object.toString(); }
public boolean isIndirectReference() { return object.type() == PdfObject.INDIRECT; }