public class CommentRangeStart extends Node
To learn more, visit the Working with Comments documentation article.
Remarks:
To create a comment anchored to a region of text, you need to create a Comment and then create CommentRangeStart and CommentRangeEnd and set their identifiers to the same Comment.getId() / Comment.setId(int) value.
CommentRangeStart is an inline-level node and can only be a child of Paragraph.
Examples:
Shows how print the contents of all comments and their comment ranges using a document visitor.
public void createCommentsAndPrintAllInfo() throws Exception {
Document doc = new Document();
Comment newComment = new Comment(doc);
{
newComment.setAuthor("VDeryushev");
newComment.setInitial("VD");
newComment.setDateTime(new Date());
}
newComment.setText("Comment regarding text.");
// Add text to the document, warp it in a comment range, and then add your comment.
Paragraph para = doc.getFirstSection().getBody().getFirstParagraph();
para.appendChild(new CommentRangeStart(doc, newComment.getId()));
para.appendChild(new Run(doc, "Commented text."));
para.appendChild(new CommentRangeEnd(doc, newComment.getId()));
para.appendChild(newComment);
// Add two replies to the comment.
newComment.addReply("John Doe", "JD", new Date(), "New reply.");
newComment.addReply("John Doe", "JD", new Date(), "Another reply.");
printAllCommentInfo(doc.getChildNodes(NodeType.COMMENT, true));
}
/// <summary>
/// Iterates over every top-level comment and prints its comment range, contents, and replies.
/// </summary>
private static void printAllCommentInfo(NodeCollection comments) throws Exception {
CommentInfoPrinter commentVisitor = new CommentInfoPrinter();
// Iterate over all top-level comments. Unlike reply-type comments, top-level comments have no ancestor.
for (Comment comment : (Iterable<Comment>) comments) {
if (comment.getAncestor() == null) {
// First, visit the start of the comment range.
CommentRangeStart commentRangeStart = (CommentRangeStart) comment.getPreviousSibling().getPreviousSibling().getPreviousSibling();
commentRangeStart.accept(commentVisitor);
// Then, visit the comment, and any replies that it may have.
comment.accept(commentVisitor);
for (Comment reply : comment.getReplies())
reply.accept(commentVisitor);
// Finally, visit the end of the comment range, and then print the visitor's text contents.
CommentRangeEnd commentRangeEnd = (CommentRangeEnd) comment.getPreviousSibling();
commentRangeEnd.accept(commentVisitor);
System.out.println(commentVisitor.getText());
}
}
}
/// <summary>
/// Prints information and contents of all comments and comment ranges encountered in the document.
/// </summary>
public static class CommentInfoPrinter extends DocumentVisitor {
public CommentInfoPrinter() {
mBuilder = new StringBuilder();
mVisitorIsInsideComment = false;
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
/// <summary>
/// Called when a Run node is encountered in the document.
/// </summary>
public int visitRun(Run run) {
if (mVisitorIsInsideComment) indentAndAppendLine("[Run] \"" + run.getText() + "\"");
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a CommentRangeStart node is encountered in the document.
/// </summary>
public int visitCommentRangeStart(CommentRangeStart commentRangeStart) {
indentAndAppendLine("[Comment range start] ID: " + commentRangeStart.getId());
mDocTraversalDepth++;
mVisitorIsInsideComment = true;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a CommentRangeEnd node is encountered in the document.
/// </summary>
public int visitCommentRangeEnd(CommentRangeEnd commentRangeEnd) {
mDocTraversalDepth--;
indentAndAppendLine("[Comment range end] ID: " + commentRangeEnd.getId() + "\n");
mVisitorIsInsideComment = false;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a Comment node is encountered in the document.
/// </summary>
public int visitCommentStart(Comment comment) {
indentAndAppendLine(MessageFormat.format("[Comment start] For comment range ID {0}, By {1} on {2}", comment.getId(),
comment.getAuthor(), comment.getDateTime()));
mDocTraversalDepth++;
mVisitorIsInsideComment = true;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when the visiting of a Comment node is ended in the document.
/// </summary>
public int visitCommentEnd(Comment comment) {
mDocTraversalDepth--;
indentAndAppendLine("[Comment end]");
mVisitorIsInsideComment = false;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Append a line to the StringBuilder and indent it depending on how deep the visitor is into the document tree.
/// </summary>
/// <param name="text"></param>
private void indentAndAppendLine(String text) {
for (int i = 0; i < mDocTraversalDepth; i++) {
mBuilder.append("| ");
}
mBuilder.append(text + "\r\n");
}
private boolean mVisitorIsInsideComment;
private int mDocTraversalDepth;
private final StringBuilder mBuilder;
}
Comment,
CommentRangeEnd| Constructor and Description |
|---|
CommentRangeStart(DocumentBase doc,
int id)
Initializes a new instance of this class.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
accept(DocumentVisitor visitor)
Accepts a visitor.
|
int |
getDisplacedByCustomXml() |
int |
getId()
Specifies the identifier of the comment to which this region is linked.
|
int |
getIdInternal() |
int |
getNodeType()
Returns
NodeType.COMMENT_RANGE_START. |
int |
getParentIdInternal() |
void |
setDisplacedByCustomXml(int value) |
void |
setId(int value)
Specifies the identifier of the comment to which this region is linked.
|
void |
setIdInternal(int value) |
void |
setParentIdInternal(int value) |
deepClone, getAncestor, getAncestor, getCustomNodeId, getDocument, getNextSibling, getParentNode, getPreviousSibling, getRange, getText, isComposite, memberwiseClone, nextPreOrder, nodeTypeToString, previousPreOrder, remove, setCustomNodeId, toString, toString, toString, visitorActionToBoolpublic CommentRangeStart(DocumentBase doc, int id)
Remarks:
When CommentRangeStart is created, it belongs to the specified document, but is not yet part of the document and Node.getParentNode() is null.
To append a CommentRangeStart to the document use InsertAfter or InsertBefore on the paragraph where you want the comment inserted.
Examples:
Shows how print the contents of all comments and their comment ranges using a document visitor.
public void createCommentsAndPrintAllInfo() throws Exception {
Document doc = new Document();
Comment newComment = new Comment(doc);
{
newComment.setAuthor("VDeryushev");
newComment.setInitial("VD");
newComment.setDateTime(new Date());
}
newComment.setText("Comment regarding text.");
// Add text to the document, warp it in a comment range, and then add your comment.
Paragraph para = doc.getFirstSection().getBody().getFirstParagraph();
para.appendChild(new CommentRangeStart(doc, newComment.getId()));
para.appendChild(new Run(doc, "Commented text."));
para.appendChild(new CommentRangeEnd(doc, newComment.getId()));
para.appendChild(newComment);
// Add two replies to the comment.
newComment.addReply("John Doe", "JD", new Date(), "New reply.");
newComment.addReply("John Doe", "JD", new Date(), "Another reply.");
printAllCommentInfo(doc.getChildNodes(NodeType.COMMENT, true));
}
/// <summary>
/// Iterates over every top-level comment and prints its comment range, contents, and replies.
/// </summary>
private static void printAllCommentInfo(NodeCollection comments) throws Exception {
CommentInfoPrinter commentVisitor = new CommentInfoPrinter();
// Iterate over all top-level comments. Unlike reply-type comments, top-level comments have no ancestor.
for (Comment comment : (Iterable<Comment>) comments) {
if (comment.getAncestor() == null) {
// First, visit the start of the comment range.
CommentRangeStart commentRangeStart = (CommentRangeStart) comment.getPreviousSibling().getPreviousSibling().getPreviousSibling();
commentRangeStart.accept(commentVisitor);
// Then, visit the comment, and any replies that it may have.
comment.accept(commentVisitor);
for (Comment reply : comment.getReplies())
reply.accept(commentVisitor);
// Finally, visit the end of the comment range, and then print the visitor's text contents.
CommentRangeEnd commentRangeEnd = (CommentRangeEnd) comment.getPreviousSibling();
commentRangeEnd.accept(commentVisitor);
System.out.println(commentVisitor.getText());
}
}
}
/// <summary>
/// Prints information and contents of all comments and comment ranges encountered in the document.
/// </summary>
public static class CommentInfoPrinter extends DocumentVisitor {
public CommentInfoPrinter() {
mBuilder = new StringBuilder();
mVisitorIsInsideComment = false;
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
/// <summary>
/// Called when a Run node is encountered in the document.
/// </summary>
public int visitRun(Run run) {
if (mVisitorIsInsideComment) indentAndAppendLine("[Run] \"" + run.getText() + "\"");
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a CommentRangeStart node is encountered in the document.
/// </summary>
public int visitCommentRangeStart(CommentRangeStart commentRangeStart) {
indentAndAppendLine("[Comment range start] ID: " + commentRangeStart.getId());
mDocTraversalDepth++;
mVisitorIsInsideComment = true;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a CommentRangeEnd node is encountered in the document.
/// </summary>
public int visitCommentRangeEnd(CommentRangeEnd commentRangeEnd) {
mDocTraversalDepth--;
indentAndAppendLine("[Comment range end] ID: " + commentRangeEnd.getId() + "\n");
mVisitorIsInsideComment = false;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a Comment node is encountered in the document.
/// </summary>
public int visitCommentStart(Comment comment) {
indentAndAppendLine(MessageFormat.format("[Comment start] For comment range ID {0}, By {1} on {2}", comment.getId(),
comment.getAuthor(), comment.getDateTime()));
mDocTraversalDepth++;
mVisitorIsInsideComment = true;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when the visiting of a Comment node is ended in the document.
/// </summary>
public int visitCommentEnd(Comment comment) {
mDocTraversalDepth--;
indentAndAppendLine("[Comment end]");
mVisitorIsInsideComment = false;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Append a line to the StringBuilder and indent it depending on how deep the visitor is into the document tree.
/// </summary>
/// <param name="text"></param>
private void indentAndAppendLine(String text) {
for (int i = 0; i < mDocTraversalDepth; i++) {
mBuilder.append("| ");
}
mBuilder.append(text + "\r\n");
}
private boolean mVisitorIsInsideComment;
private int mDocTraversalDepth;
private final StringBuilder mBuilder;
}
doc - The owner document.id - The comment identifier to which this object is linked.public int getId()
Examples:
Shows how print the contents of all comments and their comment ranges using a document visitor.
public void createCommentsAndPrintAllInfo() throws Exception {
Document doc = new Document();
Comment newComment = new Comment(doc);
{
newComment.setAuthor("VDeryushev");
newComment.setInitial("VD");
newComment.setDateTime(new Date());
}
newComment.setText("Comment regarding text.");
// Add text to the document, warp it in a comment range, and then add your comment.
Paragraph para = doc.getFirstSection().getBody().getFirstParagraph();
para.appendChild(new CommentRangeStart(doc, newComment.getId()));
para.appendChild(new Run(doc, "Commented text."));
para.appendChild(new CommentRangeEnd(doc, newComment.getId()));
para.appendChild(newComment);
// Add two replies to the comment.
newComment.addReply("John Doe", "JD", new Date(), "New reply.");
newComment.addReply("John Doe", "JD", new Date(), "Another reply.");
printAllCommentInfo(doc.getChildNodes(NodeType.COMMENT, true));
}
/// <summary>
/// Iterates over every top-level comment and prints its comment range, contents, and replies.
/// </summary>
private static void printAllCommentInfo(NodeCollection comments) throws Exception {
CommentInfoPrinter commentVisitor = new CommentInfoPrinter();
// Iterate over all top-level comments. Unlike reply-type comments, top-level comments have no ancestor.
for (Comment comment : (Iterable<Comment>) comments) {
if (comment.getAncestor() == null) {
// First, visit the start of the comment range.
CommentRangeStart commentRangeStart = (CommentRangeStart) comment.getPreviousSibling().getPreviousSibling().getPreviousSibling();
commentRangeStart.accept(commentVisitor);
// Then, visit the comment, and any replies that it may have.
comment.accept(commentVisitor);
for (Comment reply : comment.getReplies())
reply.accept(commentVisitor);
// Finally, visit the end of the comment range, and then print the visitor's text contents.
CommentRangeEnd commentRangeEnd = (CommentRangeEnd) comment.getPreviousSibling();
commentRangeEnd.accept(commentVisitor);
System.out.println(commentVisitor.getText());
}
}
}
/// <summary>
/// Prints information and contents of all comments and comment ranges encountered in the document.
/// </summary>
public static class CommentInfoPrinter extends DocumentVisitor {
public CommentInfoPrinter() {
mBuilder = new StringBuilder();
mVisitorIsInsideComment = false;
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
/// <summary>
/// Called when a Run node is encountered in the document.
/// </summary>
public int visitRun(Run run) {
if (mVisitorIsInsideComment) indentAndAppendLine("[Run] \"" + run.getText() + "\"");
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a CommentRangeStart node is encountered in the document.
/// </summary>
public int visitCommentRangeStart(CommentRangeStart commentRangeStart) {
indentAndAppendLine("[Comment range start] ID: " + commentRangeStart.getId());
mDocTraversalDepth++;
mVisitorIsInsideComment = true;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a CommentRangeEnd node is encountered in the document.
/// </summary>
public int visitCommentRangeEnd(CommentRangeEnd commentRangeEnd) {
mDocTraversalDepth--;
indentAndAppendLine("[Comment range end] ID: " + commentRangeEnd.getId() + "\n");
mVisitorIsInsideComment = false;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a Comment node is encountered in the document.
/// </summary>
public int visitCommentStart(Comment comment) {
indentAndAppendLine(MessageFormat.format("[Comment start] For comment range ID {0}, By {1} on {2}", comment.getId(),
comment.getAuthor(), comment.getDateTime()));
mDocTraversalDepth++;
mVisitorIsInsideComment = true;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when the visiting of a Comment node is ended in the document.
/// </summary>
public int visitCommentEnd(Comment comment) {
mDocTraversalDepth--;
indentAndAppendLine("[Comment end]");
mVisitorIsInsideComment = false;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Append a line to the StringBuilder and indent it depending on how deep the visitor is into the document tree.
/// </summary>
/// <param name="text"></param>
private void indentAndAppendLine(String text) {
for (int i = 0; i < mDocTraversalDepth; i++) {
mBuilder.append("| ");
}
mBuilder.append(text + "\r\n");
}
private boolean mVisitorIsInsideComment;
private int mDocTraversalDepth;
private final StringBuilder mBuilder;
}
int value.public void setId(int value)
Examples:
Shows how print the contents of all comments and their comment ranges using a document visitor.
public void createCommentsAndPrintAllInfo() throws Exception {
Document doc = new Document();
Comment newComment = new Comment(doc);
{
newComment.setAuthor("VDeryushev");
newComment.setInitial("VD");
newComment.setDateTime(new Date());
}
newComment.setText("Comment regarding text.");
// Add text to the document, warp it in a comment range, and then add your comment.
Paragraph para = doc.getFirstSection().getBody().getFirstParagraph();
para.appendChild(new CommentRangeStart(doc, newComment.getId()));
para.appendChild(new Run(doc, "Commented text."));
para.appendChild(new CommentRangeEnd(doc, newComment.getId()));
para.appendChild(newComment);
// Add two replies to the comment.
newComment.addReply("John Doe", "JD", new Date(), "New reply.");
newComment.addReply("John Doe", "JD", new Date(), "Another reply.");
printAllCommentInfo(doc.getChildNodes(NodeType.COMMENT, true));
}
/// <summary>
/// Iterates over every top-level comment and prints its comment range, contents, and replies.
/// </summary>
private static void printAllCommentInfo(NodeCollection comments) throws Exception {
CommentInfoPrinter commentVisitor = new CommentInfoPrinter();
// Iterate over all top-level comments. Unlike reply-type comments, top-level comments have no ancestor.
for (Comment comment : (Iterable<Comment>) comments) {
if (comment.getAncestor() == null) {
// First, visit the start of the comment range.
CommentRangeStart commentRangeStart = (CommentRangeStart) comment.getPreviousSibling().getPreviousSibling().getPreviousSibling();
commentRangeStart.accept(commentVisitor);
// Then, visit the comment, and any replies that it may have.
comment.accept(commentVisitor);
for (Comment reply : comment.getReplies())
reply.accept(commentVisitor);
// Finally, visit the end of the comment range, and then print the visitor's text contents.
CommentRangeEnd commentRangeEnd = (CommentRangeEnd) comment.getPreviousSibling();
commentRangeEnd.accept(commentVisitor);
System.out.println(commentVisitor.getText());
}
}
}
/// <summary>
/// Prints information and contents of all comments and comment ranges encountered in the document.
/// </summary>
public static class CommentInfoPrinter extends DocumentVisitor {
public CommentInfoPrinter() {
mBuilder = new StringBuilder();
mVisitorIsInsideComment = false;
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
/// <summary>
/// Called when a Run node is encountered in the document.
/// </summary>
public int visitRun(Run run) {
if (mVisitorIsInsideComment) indentAndAppendLine("[Run] \"" + run.getText() + "\"");
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a CommentRangeStart node is encountered in the document.
/// </summary>
public int visitCommentRangeStart(CommentRangeStart commentRangeStart) {
indentAndAppendLine("[Comment range start] ID: " + commentRangeStart.getId());
mDocTraversalDepth++;
mVisitorIsInsideComment = true;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a CommentRangeEnd node is encountered in the document.
/// </summary>
public int visitCommentRangeEnd(CommentRangeEnd commentRangeEnd) {
mDocTraversalDepth--;
indentAndAppendLine("[Comment range end] ID: " + commentRangeEnd.getId() + "\n");
mVisitorIsInsideComment = false;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a Comment node is encountered in the document.
/// </summary>
public int visitCommentStart(Comment comment) {
indentAndAppendLine(MessageFormat.format("[Comment start] For comment range ID {0}, By {1} on {2}", comment.getId(),
comment.getAuthor(), comment.getDateTime()));
mDocTraversalDepth++;
mVisitorIsInsideComment = true;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when the visiting of a Comment node is ended in the document.
/// </summary>
public int visitCommentEnd(Comment comment) {
mDocTraversalDepth--;
indentAndAppendLine("[Comment end]");
mVisitorIsInsideComment = false;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Append a line to the StringBuilder and indent it depending on how deep the visitor is into the document tree.
/// </summary>
/// <param name="text"></param>
private void indentAndAppendLine(String text) {
for (int i = 0; i < mDocTraversalDepth; i++) {
mBuilder.append("| ");
}
mBuilder.append(text + "\r\n");
}
private boolean mVisitorIsInsideComment;
private int mDocTraversalDepth;
private final StringBuilder mBuilder;
}
value - The corresponding int value.public int getDisplacedByCustomXml()
public void setDisplacedByCustomXml(int value)
public int getIdInternal()
public void setIdInternal(int value)
public int getParentIdInternal()
public void setParentIdInternal(int value)
public int getNodeType()
NodeType.COMMENT_RANGE_START.
Examples:
Shows how to traverse a composite node's tree of child nodes.
public void recurseChildren() throws Exception {
Document doc = new Document(getMyDir() + "Paragraphs.docx");
// Any node that can contain child nodes, such as the document itself, is composite.
Assert.assertTrue(doc.isComposite());
// Invoke the recursive function that will go through and print all the child nodes of a composite node.
traverseAllNodes(doc, 0);
}
/// <summary>
/// Recursively traverses a node tree while printing the type of each node
/// with an indent depending on depth as well as the contents of all inline nodes.
/// </summary>
public void traverseAllNodes(CompositeNode parentNode, int depth) {
for (Node childNode = parentNode.getFirstChild(); childNode != null; childNode = childNode.getNextSibling()) {
System.out.println(MessageFormat.format("{0}{1}", String.format(" ", depth), Node.nodeTypeToString(childNode.getNodeType())));
// Recurse into the node if it is a composite node. Otherwise, print its contents if it is an inline node.
if (childNode.isComposite()) {
System.out.println();
traverseAllNodes((CompositeNode) childNode, depth + 1);
} else if (childNode instanceof Inline) {
System.out.println(MessageFormat.format(" - \"{0}\"", childNode.getText().trim()));
} else {
System.out.println();
}
}
}
getNodeType in class NodeNodeType.COMMENT_RANGE_START. The returned value is one of NodeType constants.public boolean accept(DocumentVisitor visitor) throws java.lang.Exception
Remarks:
Calls DocumentVisitor.visitCommentRangeStart(com.aspose.words.CommentRangeStart).
For more info see the Visitor design pattern.
Examples:
Shows how print the contents of all comments and their comment ranges using a document visitor.
public void createCommentsAndPrintAllInfo() throws Exception {
Document doc = new Document();
Comment newComment = new Comment(doc);
{
newComment.setAuthor("VDeryushev");
newComment.setInitial("VD");
newComment.setDateTime(new Date());
}
newComment.setText("Comment regarding text.");
// Add text to the document, warp it in a comment range, and then add your comment.
Paragraph para = doc.getFirstSection().getBody().getFirstParagraph();
para.appendChild(new CommentRangeStart(doc, newComment.getId()));
para.appendChild(new Run(doc, "Commented text."));
para.appendChild(new CommentRangeEnd(doc, newComment.getId()));
para.appendChild(newComment);
// Add two replies to the comment.
newComment.addReply("John Doe", "JD", new Date(), "New reply.");
newComment.addReply("John Doe", "JD", new Date(), "Another reply.");
printAllCommentInfo(doc.getChildNodes(NodeType.COMMENT, true));
}
/// <summary>
/// Iterates over every top-level comment and prints its comment range, contents, and replies.
/// </summary>
private static void printAllCommentInfo(NodeCollection comments) throws Exception {
CommentInfoPrinter commentVisitor = new CommentInfoPrinter();
// Iterate over all top-level comments. Unlike reply-type comments, top-level comments have no ancestor.
for (Comment comment : (Iterable<Comment>) comments) {
if (comment.getAncestor() == null) {
// First, visit the start of the comment range.
CommentRangeStart commentRangeStart = (CommentRangeStart) comment.getPreviousSibling().getPreviousSibling().getPreviousSibling();
commentRangeStart.accept(commentVisitor);
// Then, visit the comment, and any replies that it may have.
comment.accept(commentVisitor);
for (Comment reply : comment.getReplies())
reply.accept(commentVisitor);
// Finally, visit the end of the comment range, and then print the visitor's text contents.
CommentRangeEnd commentRangeEnd = (CommentRangeEnd) comment.getPreviousSibling();
commentRangeEnd.accept(commentVisitor);
System.out.println(commentVisitor.getText());
}
}
}
/// <summary>
/// Prints information and contents of all comments and comment ranges encountered in the document.
/// </summary>
public static class CommentInfoPrinter extends DocumentVisitor {
public CommentInfoPrinter() {
mBuilder = new StringBuilder();
mVisitorIsInsideComment = false;
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
/// <summary>
/// Called when a Run node is encountered in the document.
/// </summary>
public int visitRun(Run run) {
if (mVisitorIsInsideComment) indentAndAppendLine("[Run] \"" + run.getText() + "\"");
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a CommentRangeStart node is encountered in the document.
/// </summary>
public int visitCommentRangeStart(CommentRangeStart commentRangeStart) {
indentAndAppendLine("[Comment range start] ID: " + commentRangeStart.getId());
mDocTraversalDepth++;
mVisitorIsInsideComment = true;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a CommentRangeEnd node is encountered in the document.
/// </summary>
public int visitCommentRangeEnd(CommentRangeEnd commentRangeEnd) {
mDocTraversalDepth--;
indentAndAppendLine("[Comment range end] ID: " + commentRangeEnd.getId() + "\n");
mVisitorIsInsideComment = false;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a Comment node is encountered in the document.
/// </summary>
public int visitCommentStart(Comment comment) {
indentAndAppendLine(MessageFormat.format("[Comment start] For comment range ID {0}, By {1} on {2}", comment.getId(),
comment.getAuthor(), comment.getDateTime()));
mDocTraversalDepth++;
mVisitorIsInsideComment = true;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when the visiting of a Comment node is ended in the document.
/// </summary>
public int visitCommentEnd(Comment comment) {
mDocTraversalDepth--;
indentAndAppendLine("[Comment end]");
mVisitorIsInsideComment = false;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Append a line to the StringBuilder and indent it depending on how deep the visitor is into the document tree.
/// </summary>
/// <param name="text"></param>
private void indentAndAppendLine(String text) {
for (int i = 0; i < mDocTraversalDepth; i++) {
mBuilder.append("| ");
}
mBuilder.append(text + "\r\n");
}
private boolean mVisitorIsInsideComment;
private int mDocTraversalDepth;
private final StringBuilder mBuilder;
}