Dear Team,
i am getting array index out of bounds exception while insert comment for the end of the word in the paragraph . I am trying to insert comments based on the word position.
My code
public static void commentRangeOfRuns(Paragraph para,HashMap<String, String>position) {
Document doc = (Document) para.getDocument();
DocumentBuilder builder=new DocumentBuilder(doc);
Node[] runs = para.getChildNodes(21, true).toArray();
for(Map.Entry<String, String> entry:position.entrySet()) {
String commentText=entry.getKey();
String []positionary=entry.getValue().split("_");
int start=Integer.valueOf(positionary[0]);
int end=Integer.valueOf(positionary[1]);
for(int i=start;i<end;i++) {
System.out.print(runs[i].getText());
}
Comment comment = new Comment((DocumentBase) doc, "comment", "LE", new Date());
comment.getParagraphs().add((Node) new Paragraph((DocumentBase) doc));
comment.getFirstParagraph().getRuns().add((Node) new Run((DocumentBase) doc, commentText));
CommentRangeStart commentRangeStart = new CommentRangeStart((DocumentBase) doc, comment.getId());
CommentRangeEnd commentRangeEnd = new CommentRangeEnd((DocumentBase) doc, comment.getId());
runs[start - 0].getParentNode().insertBefore((Node) commentRangeStart, runs[start - 0]);
runs[end - 0].getParentNode().insertBefore((Node) commentRangeEnd, runs[end - 0]);
commentRangeEnd.getParentNode().insertAfter((Node) comment, (Node) commentRangeEnd);
}
}
Thanks in advance
Best regards,
Kesavaraman