class AcroFields {
/**
* Gets the field names that have signatures and are signed.
*
* @return the field names that have signatures and are signed
*/
public ArrayList<String> getSignatureNames() {
if (sigNames != null)
return new ArrayList<String>(sigNames.keySet());
sigNames = new HashMap<String, int[]>();
ArrayList<Object[]> sorter = new ArrayList<Object[]>();
for (Map.Entry<String, Item> entry: fields.entrySet()) {
Item item = entry.getValue();
PdfDictionary merged = item.getMerged(0);
if (!PdfName.SIG.equals(merged.get(PdfName.FT)))
continue;
PdfDictionary v = merged.getAsDict(PdfName.V);
if (v == null)
continue;
PdfString contents = v.getAsString(PdfName.CONTENTS);
if (contents == null)
continue;
PdfArray ro = v.getAsArray(PdfName.BYTERANGE);
if (ro == null)
continue;
int rangeSize = ro.size();
if (rangeSize < 2)
continue;
int length = ro.getAsNumber(rangeSize - 1).intValue() + ro.getAsNumber(rangeSize - 2).intValue();
sorter.add(new Object[]{entry.getKey(), new int[]{length, 0}});
}
Collections.sort(sorter, new AcroFields.SorterComparator());
if (!sorter.isEmpty()) {
if (((int[])sorter.get(sorter.size() - 1)[1])[0] == reader.getFileLength())
totalRevisions = sorter.size();
else
totalRevisions = sorter.size() + 1;
for (int k = 0; k < sorter.size(); ++k) {
Object objs[] = sorter.get(k);
String name = (String)objs[0];
int p[] = (int[])objs[1];
p[1] = k + 1;
sigNames.put(name, p);
}
}
return new ArrayList<String>(sigNames.keySet());
}
}