コード例 #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;
   }
 }
コード例 #2
0
 private void addNodes(PdfObjectTreeNode parent, PdfObjectTreeNode child) {
   try {
     parent.add(child);
   } catch (IllegalArgumentException iae) {
     parent.setRecursive(true);
   }
 }
コード例 #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;
 }
コード例 #4
0
 public PdfObjectTreeNode getAncestor() {
   if (isRecursive()) {
     PdfObjectTreeNode node = this;
     while (true) {
       node = (PdfObjectTreeNode) node.getParent();
       if (node.isIndirectReference() && node.getNumber() == getNumber()) {
         return node;
       }
     }
   }
   return null;
 }
コード例 #5
0
ファイル: FormTreeNode.java プロジェクト: kjella/iText-4.2.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");
     }
   }
 }
コード例 #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));
   }
 }
コード例 #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;
 }
コード例 #8
0
 public static PdfObjectTreeNode getInstance(PdfDictionary dict, PdfName key) {
   PdfObjectTreeNode node = getInstance(dict.get(key));
   node.setUserObject(getDictionaryEntryCaption(dict, key));
   node.key = key;
   return node;
 }
コード例 #9
0
 public static PdfObjectTreeNode getInstance(PdfObject object, int number) {
   PdfObjectTreeNode node = getInstance(object);
   node.number = number;
   return node;
 }