public class Footnote extends InlineStory
To learn more, visit the Working with Footnote and Endnote documentation article.
Remarks:
The Footnote class is used to represent both footnotes and endnotes in a Word document.
Footnote is an inline-level node and can only be a child of Paragraph.
Footnote can contain Paragraph and Table child nodes.
Examples:
Shows how to insert and customize footnotes.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add text, and reference it with a footnote. This footnote will place a small superscript reference
// mark after the text that it references and create an entry below the main body text at the bottom of the page.
// This entry will contain the footnote's reference mark and the reference text,
// which we will pass to the document builder's "InsertFootnote" method.
builder.write("Main body text.");
Footnote footnote = builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text.");
// If this property is set to "true", then our footnote's reference mark
// will be its index among all the section's footnotes.
// This is the first footnote, so the reference mark will be "1".
Assert.assertTrue(footnote.isAuto());
// We can move the document builder inside the footnote to edit its reference text.
builder.moveTo(footnote.getFirstParagraph());
builder.write(" More text added by a DocumentBuilder.");
builder.moveToDocumentEnd();
Assert.assertEquals(footnote.getParagraphs().get(0).toString(SaveFormat.TEXT).trim(), "Footnote text. More text added by a DocumentBuilder.");
builder.write(" More main body text.");
footnote = builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text.");
// We can set a custom reference mark which the footnote will use instead of its index number.
footnote.setReferenceMark("RefMark");
Assert.assertFalse(footnote.isAuto());
// A bookmark with the "IsAuto" flag set to true will still show its real index
// even if previous bookmarks display custom reference marks, so this bookmark's reference mark will be a "3".
builder.write(" More main body text.");
footnote = builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text.");
Assert.assertTrue(footnote.isAuto());
doc.save(getArtifactsDir() + "InlineStory.AddFootnote.docx");
| Constructor and Description |
|---|
Footnote(DocumentBase doc,
int footnoteType)
Initializes a new instance of this class.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
accept(DocumentVisitor visitor)
Accepts a visitor.
|
int |
acceptEnd(DocumentVisitor visitor)
Accepts a visitor for visiting the end of the footnote.
|
int |
acceptStart(DocumentVisitor visitor)
Accepts a visitor for visiting the start of the footnote.
|
java.lang.String |
getActualReferenceMark()
Gets the actual text of the reference mark displayed in the document for this footnote.
|
int |
getFootnoteType()
Returns a value that specifies whether this is a footnote or endnote.
|
int |
getNodeType()
Returns
NodeType.FOOTNOTE. |
java.lang.String |
getReferenceMark()
Gets/sets custom reference mark to be used for this footnote.
|
int |
getStoryType()
Returns
StoryType.FOOTNOTES or StoryType.ENDNOTES. |
boolean |
isAuto()
Holds a value that specifies whether this is a auto-numbered footnote or footnote with user defined custom reference mark.
|
void |
isAuto(boolean value)
Holds a value that specifies whether this is a auto-numbered footnote or footnote with user defined custom reference mark.
|
void |
removeMoveRevisions() |
void |
setReferenceMark(java.lang.String value)
Gets/sets custom reference mark to be used for this footnote.
|
clearRunAttrs, ensureMinimum, fetchInheritedRunAttr, getDirectRunAttr, getDirectRunAttr, getDocument_IInline, getFirstParagraph, getFont, getLastParagraph, getParagraphs, getParentParagraph_IInline, getParentParagraph, getTables, isDeleteRevision, isInsertRevision, isMoveFromRevision, isMoveToRevision, removeRunAttr, setRunAttracceptChildren, acceptCore, appendChild, coreRemoveSelfOnly, getChild, getChildNodes, getContainer, getCount, getCurrentNode, getFirstChild, getLastChild, getNextMatchingNode, getText, hasChildNodes, indexOf, insertAfter, insertBefore, isComposite, iterator, prependChild, removeAllChildren, removeChild, removeSmartTags, selectNodes, selectSingleNodedeepClone, getAncestor, getAncestor, getCustomNodeId, getDocument, getNextSibling, getParentNode, getPreviousSibling, getRange, memberwiseClone, nextPreOrder, nodeTypeToString, previousPreOrder, remove, setCustomNodeId, toString, toString, toString, visitorActionToBoolpublic Footnote(DocumentBase doc, int footnoteType)
public int getNodeType()
NodeType.FOOTNOTE.
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.FOOTNOTE. The returned value is one of NodeType constants.public int getStoryType()
StoryType.FOOTNOTES or StoryType.ENDNOTES.
Examples:
Shows how to insert InlineStory nodes.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Footnote footnote = builder.insertFootnote(FootnoteType.FOOTNOTE, null);
// Table nodes have an "EnsureMinimum()" method that makes sure the table has at least one cell.
Table table = new Table(doc);
table.ensureMinimum();
// We can place a table inside a footnote, which will make it appear at the referencing page's footer.
Assert.assertEquals(footnote.getTables().getCount(), 0);
footnote.appendChild(table);
Assert.assertEquals(footnote.getTables().getCount(), 1);
Assert.assertEquals(footnote.getLastChild().getNodeType(), NodeType.TABLE);
// An InlineStory has an "EnsureMinimum()" method as well, but in this case,
// it makes sure the last child of the node is a paragraph,
// for us to be able to click and write text easily in Microsoft Word.
footnote.ensureMinimum();
Assert.assertEquals(footnote.getLastChild().getNodeType(), NodeType.PARAGRAPH);
// Edit the appearance of the anchor, which is the small superscript number
// in the main text that points to the footnote.
footnote.getFont().setName("Arial");
footnote.getFont().setColor(Color.GREEN);
// All inline story nodes have their respective story types.
Assert.assertEquals(footnote.getStoryType(), StoryType.FOOTNOTES);
// A comment is another type of inline story.
Comment comment = (Comment) builder.getCurrentParagraph().appendChild(new Comment(doc, "John Doe", "J. D.", new Date()));
// The parent paragraph of an inline story node will be the one from the main document body.
Assert.assertEquals(doc.getFirstSection().getBody().getFirstParagraph(), comment.getParentParagraph());
// However, the last paragraph is the one from the comment text contents,
// which will be outside the main document body in a speech bubble.
// A comment will not have any child nodes by default,
// so we can apply the EnsureMinimum() method to place a paragraph here as well.
Assert.assertNull(comment.getLastParagraph());
comment.ensureMinimum();
Assert.assertEquals(comment.getLastChild().getNodeType(), NodeType.PARAGRAPH);
// Once we have a paragraph, we can move the builder to do it and write our comment.
builder.moveTo(comment.getLastParagraph());
builder.write("My comment.");
Assert.assertEquals(comment.getStoryType(), StoryType.COMMENTS);
doc.save(getArtifactsDir() + "InlineStory.InsertInlineStoryNodes.docx");
getStoryType in class InlineStoryStoryType.FOOTNOTES or StoryType.ENDNOTES. The returned value is one of StoryType constants.public int getFootnoteType()
Examples:
Shows the difference between footnotes and endnotes.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Below are two ways of attaching numbered references to the text. Both these references will add a
// small superscript reference mark at the location that we insert them.
// The reference mark, by default, is the index number of the reference among all the references in the document.
// Each reference will also create an entry, which will have the same reference mark as in the body text
// and reference text, which we will pass to the document builder's "InsertFootnote" method.
// 1 - A footnote, whose entry will appear on the same page as the text that it references:
builder.write("Footnote referenced main body text.");
Footnote footnote = builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text, will appear at the bottom of the page that contains the referenced text.");
// 2 - An endnote, whose entry will appear at the end of the document:
builder.write("Endnote referenced main body text.");
Footnote endnote = builder.insertFootnote(FootnoteType.ENDNOTE, "Endnote text, will appear at the very end of the document.");
builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
Assert.assertEquals(footnote.getFootnoteType(), FootnoteType.FOOTNOTE);
Assert.assertEquals(endnote.getFootnoteType(), FootnoteType.ENDNOTE);
doc.save(getArtifactsDir() + "InlineStory.FootnoteEndnote.docx");
FootnoteType constants.public boolean isAuto()
Remarks:
getReferenceMark() / setReferenceMark(java.lang.String) initialized with empty string if isAuto() / isAuto(boolean) set to false.
Examples:
Shows how to insert and customize footnotes.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add text, and reference it with a footnote. This footnote will place a small superscript reference
// mark after the text that it references and create an entry below the main body text at the bottom of the page.
// This entry will contain the footnote's reference mark and the reference text,
// which we will pass to the document builder's "InsertFootnote" method.
builder.write("Main body text.");
Footnote footnote = builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text.");
// If this property is set to "true", then our footnote's reference mark
// will be its index among all the section's footnotes.
// This is the first footnote, so the reference mark will be "1".
Assert.assertTrue(footnote.isAuto());
// We can move the document builder inside the footnote to edit its reference text.
builder.moveTo(footnote.getFirstParagraph());
builder.write(" More text added by a DocumentBuilder.");
builder.moveToDocumentEnd();
Assert.assertEquals(footnote.getParagraphs().get(0).toString(SaveFormat.TEXT).trim(), "Footnote text. More text added by a DocumentBuilder.");
builder.write(" More main body text.");
footnote = builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text.");
// We can set a custom reference mark which the footnote will use instead of its index number.
footnote.setReferenceMark("RefMark");
Assert.assertFalse(footnote.isAuto());
// A bookmark with the "IsAuto" flag set to true will still show its real index
// even if previous bookmarks display custom reference marks, so this bookmark's reference mark will be a "3".
builder.write(" More main body text.");
footnote = builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text.");
Assert.assertTrue(footnote.isAuto());
doc.save(getArtifactsDir() + "InlineStory.AddFootnote.docx");
boolean value.public void isAuto(boolean value)
Remarks:
getReferenceMark() / setReferenceMark(java.lang.String) initialized with empty string if isAuto() / isAuto(boolean) set to false.
Examples:
Shows how to insert and customize footnotes.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add text, and reference it with a footnote. This footnote will place a small superscript reference
// mark after the text that it references and create an entry below the main body text at the bottom of the page.
// This entry will contain the footnote's reference mark and the reference text,
// which we will pass to the document builder's "InsertFootnote" method.
builder.write("Main body text.");
Footnote footnote = builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text.");
// If this property is set to "true", then our footnote's reference mark
// will be its index among all the section's footnotes.
// This is the first footnote, so the reference mark will be "1".
Assert.assertTrue(footnote.isAuto());
// We can move the document builder inside the footnote to edit its reference text.
builder.moveTo(footnote.getFirstParagraph());
builder.write(" More text added by a DocumentBuilder.");
builder.moveToDocumentEnd();
Assert.assertEquals(footnote.getParagraphs().get(0).toString(SaveFormat.TEXT).trim(), "Footnote text. More text added by a DocumentBuilder.");
builder.write(" More main body text.");
footnote = builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text.");
// We can set a custom reference mark which the footnote will use instead of its index number.
footnote.setReferenceMark("RefMark");
Assert.assertFalse(footnote.isAuto());
// A bookmark with the "IsAuto" flag set to true will still show its real index
// even if previous bookmarks display custom reference marks, so this bookmark's reference mark will be a "3".
builder.write(" More main body text.");
footnote = builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text.");
Assert.assertTrue(footnote.isAuto());
doc.save(getArtifactsDir() + "InlineStory.AddFootnote.docx");
value - The corresponding boolean value.public java.lang.String getReferenceMark()
Remarks:
If this property is set to empty string or null, then isAuto() / isAuto(boolean) property will automatically be set to true, if set to anything else then isAuto() / isAuto(boolean) will be set to false.
RTF-format can only store 1 symbol as custom reference mark, so upon export only the first symbol will be written others will be discard.
Examples:
Shows how to insert and customize footnotes.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add text, and reference it with a footnote. This footnote will place a small superscript reference
// mark after the text that it references and create an entry below the main body text at the bottom of the page.
// This entry will contain the footnote's reference mark and the reference text,
// which we will pass to the document builder's "InsertFootnote" method.
builder.write("Main body text.");
Footnote footnote = builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text.");
// If this property is set to "true", then our footnote's reference mark
// will be its index among all the section's footnotes.
// This is the first footnote, so the reference mark will be "1".
Assert.assertTrue(footnote.isAuto());
// We can move the document builder inside the footnote to edit its reference text.
builder.moveTo(footnote.getFirstParagraph());
builder.write(" More text added by a DocumentBuilder.");
builder.moveToDocumentEnd();
Assert.assertEquals(footnote.getParagraphs().get(0).toString(SaveFormat.TEXT).trim(), "Footnote text. More text added by a DocumentBuilder.");
builder.write(" More main body text.");
footnote = builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text.");
// We can set a custom reference mark which the footnote will use instead of its index number.
footnote.setReferenceMark("RefMark");
Assert.assertFalse(footnote.isAuto());
// A bookmark with the "IsAuto" flag set to true will still show its real index
// even if previous bookmarks display custom reference marks, so this bookmark's reference mark will be a "3".
builder.write(" More main body text.");
footnote = builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text.");
Assert.assertTrue(footnote.isAuto());
doc.save(getArtifactsDir() + "InlineStory.AddFootnote.docx");
String value.public void setReferenceMark(java.lang.String value)
Remarks:
If this property is set to empty string or null, then isAuto() / isAuto(boolean) property will automatically be set to true, if set to anything else then isAuto() / isAuto(boolean) will be set to false.
RTF-format can only store 1 symbol as custom reference mark, so upon export only the first symbol will be written others will be discard.
Examples:
Shows how to insert and customize footnotes.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add text, and reference it with a footnote. This footnote will place a small superscript reference
// mark after the text that it references and create an entry below the main body text at the bottom of the page.
// This entry will contain the footnote's reference mark and the reference text,
// which we will pass to the document builder's "InsertFootnote" method.
builder.write("Main body text.");
Footnote footnote = builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text.");
// If this property is set to "true", then our footnote's reference mark
// will be its index among all the section's footnotes.
// This is the first footnote, so the reference mark will be "1".
Assert.assertTrue(footnote.isAuto());
// We can move the document builder inside the footnote to edit its reference text.
builder.moveTo(footnote.getFirstParagraph());
builder.write(" More text added by a DocumentBuilder.");
builder.moveToDocumentEnd();
Assert.assertEquals(footnote.getParagraphs().get(0).toString(SaveFormat.TEXT).trim(), "Footnote text. More text added by a DocumentBuilder.");
builder.write(" More main body text.");
footnote = builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text.");
// We can set a custom reference mark which the footnote will use instead of its index number.
footnote.setReferenceMark("RefMark");
Assert.assertFalse(footnote.isAuto());
// A bookmark with the "IsAuto" flag set to true will still show its real index
// even if previous bookmarks display custom reference marks, so this bookmark's reference mark will be a "3".
builder.write(" More main body text.");
footnote = builder.insertFootnote(FootnoteType.FOOTNOTE, "Footnote text.");
Assert.assertTrue(footnote.isAuto());
doc.save(getArtifactsDir() + "InlineStory.AddFootnote.docx");
value - The corresponding String value.public java.lang.String getActualReferenceMark()
Remarks:
To initially populate values of this property for all reference marks of the document, or to update the values after changes in the document that might affect the reference marks, you must execute the Document.updateActualReferenceMarks() method. Updating fields ( Document.updateFields()) may also be necessary to get the correct result.
Examples:
Shows how to get actual footnote reference mark.
Document doc = new Document(getMyDir() + "Footnotes and endnotes.docx");
Footnote footnote = (Footnote)doc.getChild(NodeType.FOOTNOTE, 1, true);
doc.updateFields();
doc.updateActualReferenceMarks();
Assert.assertEquals("1", footnote.getActualReferenceMark());
public boolean accept(DocumentVisitor visitor) throws java.lang.Exception
Remarks:
Enumerates over this node and all of its children. Each node calls a corresponding method on DocumentVisitor.
For more info see the Visitor design pattern.
Calls DocumentVisitor.VisitFootnoteStart, then calls Accept for all child nodes of the footnote and calls DocumentVisitor.VisitFootnoteEnd at the end.
Examples:
Shows how to print the node structure of every footnote in a document.
public void footnoteToText() throws Exception {
Document doc = new Document(getMyDir() + "DocumentVisitor-compatible features.docx");
FootnoteStructurePrinter visitor = new FootnoteStructurePrinter();
// When we get a composite node to accept a document visitor, the visitor visits the accepting node,
// and then traverses all the node's children in a depth-first manner.
// The visitor can read and modify each visited node.
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Traverses a node's non-binary tree of child nodes.
/// Creates a map in the form of a string of all encountered Footnote nodes and their children.
/// </summary>
public static class FootnoteStructurePrinter extends DocumentVisitor {
public FootnoteStructurePrinter() {
mBuilder = new StringBuilder();
mVisitorIsInsideFootnote = 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 Footnote node is encountered in the document.
/// </summary>
public int visitFootnoteStart(final Footnote footnote) {
indentAndAppendLine("[Footnote start] Type: " + footnote.getFootnoteType());
mDocTraversalDepth++;
mVisitorIsInsideFootnote = true;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called after all the child nodes of a Footnote node have been visited.
/// </summary>
public int visitFootnoteEnd(final Footnote footnote) {
mDocTraversalDepth--;
indentAndAppendLine("[Footnote end]");
mVisitorIsInsideFootnote = false;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a Run node is encountered in the document.
/// </summary>
public int visitRun(final Run run) {
if (mVisitorIsInsideFootnote) {
indentAndAppendLine("[Run] \"" + run.getText() + "\"");
}
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(final String text) {
for (int i = 0; i < mDocTraversalDepth; i++) {
mBuilder.append("| ");
}
mBuilder.append(text + "\r\n");
}
private boolean mVisitorIsInsideFootnote;
private int mDocTraversalDepth;
private final StringBuilder mBuilder;
}
accept in class Nodevisitor - The visitor that will visit the nodes.DocumentVisitor stopped the operation before visiting all nodes.java.lang.Exceptionpublic int acceptStart(DocumentVisitor visitor) throws java.lang.Exception
Examples:
Shows how to print the node structure of every footnote in a document.
public void footnoteToText() throws Exception {
Document doc = new Document(getMyDir() + "DocumentVisitor-compatible features.docx");
FootnoteStructurePrinter visitor = new FootnoteStructurePrinter();
// When we get a composite node to accept a document visitor, the visitor visits the accepting node,
// and then traverses all the node's children in a depth-first manner.
// The visitor can read and modify each visited node.
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Traverses a node's non-binary tree of child nodes.
/// Creates a map in the form of a string of all encountered Footnote nodes and their children.
/// </summary>
public static class FootnoteStructurePrinter extends DocumentVisitor {
public FootnoteStructurePrinter() {
mBuilder = new StringBuilder();
mVisitorIsInsideFootnote = 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 Footnote node is encountered in the document.
/// </summary>
public int visitFootnoteStart(final Footnote footnote) {
indentAndAppendLine("[Footnote start] Type: " + footnote.getFootnoteType());
mDocTraversalDepth++;
mVisitorIsInsideFootnote = true;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called after all the child nodes of a Footnote node have been visited.
/// </summary>
public int visitFootnoteEnd(final Footnote footnote) {
mDocTraversalDepth--;
indentAndAppendLine("[Footnote end]");
mVisitorIsInsideFootnote = false;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a Run node is encountered in the document.
/// </summary>
public int visitRun(final Run run) {
if (mVisitorIsInsideFootnote) {
indentAndAppendLine("[Run] \"" + run.getText() + "\"");
}
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(final String text) {
for (int i = 0; i < mDocTraversalDepth; i++) {
mBuilder.append("| ");
}
mBuilder.append(text + "\r\n");
}
private boolean mVisitorIsInsideFootnote;
private int mDocTraversalDepth;
private final StringBuilder mBuilder;
}
acceptStart in class CompositeNodevisitor - The document visitor.VisitorAction constants.java.lang.Exceptionpublic int acceptEnd(DocumentVisitor visitor) throws java.lang.Exception
Examples:
Shows how to print the node structure of every footnote in a document.
public void footnoteToText() throws Exception {
Document doc = new Document(getMyDir() + "DocumentVisitor-compatible features.docx");
FootnoteStructurePrinter visitor = new FootnoteStructurePrinter();
// When we get a composite node to accept a document visitor, the visitor visits the accepting node,
// and then traverses all the node's children in a depth-first manner.
// The visitor can read and modify each visited node.
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Traverses a node's non-binary tree of child nodes.
/// Creates a map in the form of a string of all encountered Footnote nodes and their children.
/// </summary>
public static class FootnoteStructurePrinter extends DocumentVisitor {
public FootnoteStructurePrinter() {
mBuilder = new StringBuilder();
mVisitorIsInsideFootnote = 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 Footnote node is encountered in the document.
/// </summary>
public int visitFootnoteStart(final Footnote footnote) {
indentAndAppendLine("[Footnote start] Type: " + footnote.getFootnoteType());
mDocTraversalDepth++;
mVisitorIsInsideFootnote = true;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called after all the child nodes of a Footnote node have been visited.
/// </summary>
public int visitFootnoteEnd(final Footnote footnote) {
mDocTraversalDepth--;
indentAndAppendLine("[Footnote end]");
mVisitorIsInsideFootnote = false;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a Run node is encountered in the document.
/// </summary>
public int visitRun(final Run run) {
if (mVisitorIsInsideFootnote) {
indentAndAppendLine("[Run] \"" + run.getText() + "\"");
}
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(final String text) {
for (int i = 0; i < mDocTraversalDepth; i++) {
mBuilder.append("| ");
}
mBuilder.append(text + "\r\n");
}
private boolean mVisitorIsInsideFootnote;
private int mDocTraversalDepth;
private final StringBuilder mBuilder;
}
acceptEnd in class CompositeNodevisitor - The document visitor.VisitorAction constants.java.lang.Exceptionpublic void removeMoveRevisions()