How to reject Delete Revisions and accept Insert Revisions in java


#1

Hi, I want to reject all delete revisions and accept all the insert revisions in a all the paragraphs. My current understanding of code is as follows:

    ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs();
    for (int i = 0; i < paragraphs.getCount(); i++) {
    	Paragraph p = paragraphs.get(i);
    	RunCollection rns = p.getRuns();
    	for (int j = 0; j < rns.getCount(); j++) {
    		Run rn = rns.get(j);
    		if (rn.isDeleteRevision()) {
    			// reject this change in run node
    		}
    		
    		if (rn.isInsertRevision()){
    			// accept this change in run node
    		}
    	}
    }

Thanks in advance.


#2

@madhukar02001,

Please try using the following code:

Document doc = new Document("E:\\temp\\revtest.docx");

ArrayList listDELETION = new ArrayList();
ArrayList listINSERTION = new ArrayList();

for (Revision rev : doc.getRevisions()) {
    if (rev.getRevisionType() == RevisionType.DELETION) {
        listDELETION.add(rev);
    }
    if (rev.getRevisionType() == RevisionType.INSERTION) {
        listINSERTION.add(rev);
    }
}

for (Revision rev : (Iterable<Revision>) listDELETION) {
    rev.reject();
}

for (Revision rev : (Iterable<Revision>) listINSERTION) {
    rev.accept();
}

doc.save("E:\\temp\\awjava-19.7.docx");

Hope, this helps.