public DocumentDigest computeDocumentDigest(Document doc) throws Exception {
try {
JSONObject json = doc.getJSONObject();
// Initialize digest
DocumentDigest dd = new DocumentDigest();
dd.setType(DIGEST_COMPUTER_TYPE);
// Compute digest of main document
String mainDigest = this.computeDigestFromJsonObject(json);
dd.setDocDigest(mainDigest);
// Process each attachment
Collection<Attachment> attachments = doc.getAttachments();
if( null != attachments ) {
for(Attachment attachment : attachments){
String digest = computeAttachmentDigest(attachment);
dd.addAttachmentDigest(attachment.getName(), digest);
}
}
return dd;