Esempio n. 1
0
 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;
   }
 }
Esempio n. 2
0
 private void addNodes(PdfObjectTreeNode parent, PdfObjectTreeNode child) {
   try {
     parent.add(child);
   } catch (IllegalArgumentException iae) {
     parent.setRecursive(true);
   }
 }
Esempio n. 3
0
 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;
 }
Esempio n. 5
0
 /**
  * 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");
     }
   }
 }
Esempio n. 6
0
 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));
   }
 }
Esempio n. 7
0
 @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;
 }