Code with Finding: |
class PdfCopyFieldsImp {
@SuppressWarnings("unchecked")
protected PdfArray branchForm(HashMap<String, Object> level, PdfIndirectReference parent, String fname) throws IOException {
PdfArray arr = new PdfArray();
for (Map.Entry<String, Object> entry: level.entrySet()) {
String name = entry.getKey();
Object obj = entry.getValue();
PdfIndirectReference ind = getPdfIndirectReference();
PdfDictionary dic = new PdfDictionary();
if (parent != null)
dic.put(PdfName.PARENT, parent);
dic.put(PdfName.T, new PdfString(name, PdfObject.TEXT_UNICODE));
String fname2 = fname + "." + name;
int coidx = calculationOrder.indexOf(fname2);
if (coidx >= 0)
calculationOrderRefs.set(coidx, ind);
if (obj instanceof HashMap) {
dic.put(PdfName.KIDS, branchForm((HashMap<String, Object>)obj, ind, fname2));
arr.add(ind);
addToBody(dic, ind);
}
else {
ArrayList<Object> list = (ArrayList<Object>)obj;
dic.mergeDifferent((PdfDictionary)list.get(0));
if (list.size() == 3) {
dic.mergeDifferent((PdfDictionary)list.get(2));
int page = ((Integer)list.get(1)).intValue();
PdfDictionary pageDic = pageDics.get(page - 1);
PdfArray annots = pageDic.getAsArray(PdfName.ANNOTS);
if (annots == null) {
annots = new PdfArray();
pageDic.put(PdfName.ANNOTS, annots);
}
PdfNumber nn = (PdfNumber)dic.get(iTextTag);
dic.remove(iTextTag);
adjustTabOrder(annots, ind, nn);
}
else {
PdfArray kids = new PdfArray();
for (int k = 1; k < list.size(); k += 2) {
int page = ((Integer)list.get(k)).intValue();
PdfDictionary pageDic = pageDics.get(page - 1);
PdfArray annots = pageDic.getAsArray(PdfName.ANNOTS);
if (annots == null) {
annots = new PdfArray();
pageDic.put(PdfName.ANNOTS, annots);
}
PdfDictionary widget = new PdfDictionary();
widget.merge((PdfDictionary)list.get(k + 1));
widget.put(PdfName.PARENT, ind);
PdfNumber nn = (PdfNumber)widget.get(iTextTag);
widget.remove(iTextTag);
PdfIndirectReference wref = addToBody(widget).getIndirectReference();
adjustTabOrder(annots, wref, nn);
kids.add(wref);
propagate(widget, null, false);
}
dic.put(PdfName.KIDS, kids);
}
arr.add(ind);
addToBody(dic, ind);
propagate(dic, null, false);
}
}
return arr;
}
}
|