com.aspose.words
Class DocumentVisitor

java.lang.Object
    extended by com.aspose.words.DocumentVisitor

public abstract class DocumentVisitor 
extends java.lang.Object

Base class for custom document visitors.

With DocumentVisitor you can define and execute custom operations that require enumeration over the document tree.

For example, Aspose.Words uses DocumentVisitor internally for saving Document in various formats and for other operations like finding fields or bookmarks over a fragment of a document.

To use DocumentVisitor:

  1. Create a class derived from DocumentVisitor.
  2. Override and provide implementations for some or all of the VisitXXX methods to perform some custom operations.
  3. Call Node.accept(com.aspose.words.DocumentVisitor) on the Node that you want to start the enumeration from.

DocumentVisitor provides default implementations for all of the VisitXXX methods to make it easier to create new document visitors as only the methods required for the particular visitor need to be overridden. It is not necessary to override all of the visitor methods.

For more information see the Visitor design pattern.


Method Summary
intvisitAbsolutePositionTab(AbsolutePositionTab tab)
           Called when a AbsolutePositionTab node is encountered in the document.
intvisitBodyEnd(Body body)
           Called when enumeration of the main text story in a section has ended.
intvisitBodyStart(Body body)
           Called when enumeration of the main text story in a section has started.
intvisitBookmarkEnd(BookmarkEnd bookmarkEnd)
           Called when an end of a bookmark is encountered in the document.
intvisitBookmarkStart(BookmarkStart bookmarkStart)
           Called when a start of a bookmark is encountered in the document.
intvisitBuildingBlockEnd(BuildingBlock block)
           Called when enumeration of a building block has ended.
intvisitBuildingBlockStart(BuildingBlock block)
           Called when enumeration of a building block has started.
intvisitCommentEnd(Comment comment)
           Called when enumeration of a comment text has ended.
intvisitCommentRangeEnd(CommentRangeEnd commentRangeEnd)
           Called when the end of a commented range of text is encountered.
intvisitCommentRangeStart(CommentRangeStart commentRangeStart)
           Called when the start of a commented range of text is encountered.
intvisitCommentStart(Comment comment)
           Called when enumeration of a comment text has started.
intvisitDocumentEnd(Document doc)
           Called when enumeration of the document has finished.
intvisitDocumentStart(Document doc)
           Called when enumeration of the document has started.
intvisitEditableRangeEnd(EditableRangeEnd editableRangeEnd)
           Called when an end of an editable range is encountered in the document.
intvisitEditableRangeStart(EditableRangeStart editableRangeStart)
           Called when a start of an editable range is encountered in the document.
intvisitFootnoteEnd(Footnote footnote)
           Called when enumeration of a footnote or endnote text has ended.
intvisitFootnoteStart(Footnote footnote)
           Called when enumeration of a footnote or endnote text has started.
intvisitGlossaryDocumentEnd(GlossaryDocument glossary)
           Called when enumeration of a glossary document has ended.
intvisitGlossaryDocumentStart(GlossaryDocument glossary)
           Called when enumeration of a glossary document has started.
intvisitGroupShapeEnd(GroupShape groupShape)
           Called when enumeration of a group shape has ended.
intvisitGroupShapeStart(GroupShape groupShape)
           Called when enumeration of a group shape has started.
intvisitHeaderFooterEnd(HeaderFooter headerFooter)
           Called when enumeration of a header or footer in a section has ended.
intvisitHeaderFooterStart(HeaderFooter headerFooter)
           Called when enumeration of a header or footer in a section has started.
intvisitParagraphEnd(Paragraph paragraph)
           Called when enumeration of a paragraph has ended.
intvisitParagraphStart(Paragraph paragraph)
           Called when enumeration of a paragraph has started.
intvisitRun(Run run)
           Called when a run of text in the is encountered.
intvisitSectionEnd(Section section)
           Called when enumeration of a section has ended.
intvisitSectionStart(Section section)
           Called when enumeration of a section has started.
intvisitShapeEnd(Shape shape)
           Called when enumeration of a shape has ended.
intvisitShapeStart(Shape shape)
           Called when enumeration of a shape has started.
intvisitSpecialChar(SpecialChar specialChar)
           Called when a SpecialChar node is encountered in the document.
intvisitSubDocument(SubDocument subDocument)
           Called when a subDocument is encountered.
 

Method Detail

visitAbsolutePositionTab

public int visitAbsolutePositionTab(AbsolutePositionTab tab)
                            throws java.lang.Exception
Called when a AbsolutePositionTab node is encountered in the document.
Parameters:
tab - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitBodyEnd

public int visitBodyEnd(Body body)
                throws java.lang.Exception
Called when enumeration of the main text story in a section has ended.
Parameters:
body - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitBodyStart

public int visitBodyStart(Body body)
                  throws java.lang.Exception
Called when enumeration of the main text story in a section has started.
Parameters:
body - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitBookmarkEnd

public int visitBookmarkEnd(BookmarkEnd bookmarkEnd)
                    throws java.lang.Exception
Called when an end of a bookmark is encountered in the document.
Parameters:
bookmarkEnd - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitBookmarkStart

public int visitBookmarkStart(BookmarkStart bookmarkStart)
                      throws java.lang.Exception
Called when a start of a bookmark is encountered in the document.
Parameters:
bookmarkStart - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitBuildingBlockEnd

public int visitBuildingBlockEnd(BuildingBlock block)
                         throws java.lang.Exception
Called when enumeration of a building block has ended.

Note: A building block node and its children are not visited when you execute a Visitor over a Document. If you want to execute a Visitor over a building block, you need to execute the visitor over GlossaryDocument or call BuildingBlock.accept(com.aspose.words.DocumentVisitor).

Parameters:
block - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitBuildingBlockStart

public int visitBuildingBlockStart(BuildingBlock block)
                           throws java.lang.Exception
Called when enumeration of a building block has started.

Note: A building block node and its children are not visited when you execute a Visitor over a Document. If you want to execute a Visitor over a building block, you need to execute the visitor over GlossaryDocument or call BuildingBlock.accept(com.aspose.words.DocumentVisitor).

Parameters:
block - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitCommentEnd

public int visitCommentEnd(Comment comment)
                   throws java.lang.Exception
Called when enumeration of a comment text has ended.
Parameters:
comment - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitCommentRangeEnd

public int visitCommentRangeEnd(CommentRangeEnd commentRangeEnd)
                        throws java.lang.Exception
Called when the end of a commented range of text is encountered.
Parameters:
commentRangeEnd - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitCommentRangeStart

public int visitCommentRangeStart(CommentRangeStart commentRangeStart)
                          throws java.lang.Exception
Called when the start of a commented range of text is encountered.
Parameters:
commentRangeStart - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitCommentStart

public int visitCommentStart(Comment comment)
                     throws java.lang.Exception
Called when enumeration of a comment text has started.
Parameters:
comment - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitDocumentEnd

public int visitDocumentEnd(Document doc)
                    throws java.lang.Exception
Called when enumeration of the document has finished.
Parameters:
doc - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitDocumentStart

public int visitDocumentStart(Document doc)
                      throws java.lang.Exception
Called when enumeration of the document has started.
Parameters:
doc - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitEditableRangeEnd

public int visitEditableRangeEnd(EditableRangeEnd editableRangeEnd)
                         throws java.lang.Exception
Called when an end of an editable range is encountered in the document.
Parameters:
editableRangeEnd - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitEditableRangeStart

public int visitEditableRangeStart(EditableRangeStart editableRangeStart)
                           throws java.lang.Exception
Called when a start of an editable range is encountered in the document.
Parameters:
editableRangeStart - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitFootnoteEnd

public int visitFootnoteEnd(Footnote footnote)
                    throws java.lang.Exception
Called when enumeration of a footnote or endnote text has ended.
Parameters:
footnote - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitFootnoteStart

public int visitFootnoteStart(Footnote footnote)
                      throws java.lang.Exception
Called when enumeration of a footnote or endnote text has started.
Parameters:
footnote - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitGlossaryDocumentEnd

public int visitGlossaryDocumentEnd(GlossaryDocument glossary)
                            throws java.lang.Exception
Called when enumeration of a glossary document has ended.

Note: A glossary document node and its children are not visited when you execute a Visitor over a Document. If you want to execute a Visitor over a glossary document, you need to call GlossaryDocument.accept(com.aspose.words.DocumentVisitor).

Parameters:
glossary - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitGlossaryDocumentStart

public int visitGlossaryDocumentStart(GlossaryDocument glossary)
                              throws java.lang.Exception
Called when enumeration of a glossary document has started.

Note: A glossary document node and its children are not visited when you execute a Visitor over a Document. If you want to execute a Visitor over a glossary document, you need to call GlossaryDocument.accept(com.aspose.words.DocumentVisitor).

Parameters:
glossary - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitGroupShapeEnd

public int visitGroupShapeEnd(GroupShape groupShape)
                      throws java.lang.Exception
Called when enumeration of a group shape has ended.
Parameters:
groupShape - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitGroupShapeStart

public int visitGroupShapeStart(GroupShape groupShape)
                        throws java.lang.Exception
Called when enumeration of a group shape has started.
Parameters:
groupShape - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitHeaderFooterEnd

public int visitHeaderFooterEnd(HeaderFooter headerFooter)
                        throws java.lang.Exception
Called when enumeration of a header or footer in a section has ended.
Parameters:
headerFooter - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitHeaderFooterStart

public int visitHeaderFooterStart(HeaderFooter headerFooter)
                          throws java.lang.Exception
Called when enumeration of a header or footer in a section has started.
Parameters:
headerFooter - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitParagraphEnd

public int visitParagraphEnd(Paragraph paragraph)
                     throws java.lang.Exception
Called when enumeration of a paragraph has ended.
Parameters:
paragraph - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitParagraphStart

public int visitParagraphStart(Paragraph paragraph)
                       throws java.lang.Exception
Called when enumeration of a paragraph has started.
Parameters:
paragraph - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitRun

public int visitRun(Run run)
            throws java.lang.Exception
Called when a run of text in the is encountered.
Parameters:
run - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitSectionEnd

public int visitSectionEnd(Section section)
                   throws java.lang.Exception
Called when enumeration of a section has ended.
Parameters:
section - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitSectionStart

public int visitSectionStart(Section section)
                     throws java.lang.Exception
Called when enumeration of a section has started.
Parameters:
section - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitShapeEnd

public int visitShapeEnd(Shape shape)
                 throws java.lang.Exception
Called when enumeration of a shape has ended.
Parameters:
shape - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitShapeStart

public int visitShapeStart(Shape shape)
                   throws java.lang.Exception
Called when enumeration of a shape has started.
Parameters:
shape - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitSpecialChar

public int visitSpecialChar(SpecialChar specialChar)
                    throws java.lang.Exception
Called when a SpecialChar node is encountered in the document. This method is not be called for generic control characters (see ControlChar) that can be present in the document.
Parameters:
specialChar - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitSubDocument

public int visitSubDocument(SubDocument subDocument)
                    throws java.lang.Exception
Called when a subDocument is encountered.
Parameters:
subDocument - The object that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.