ASPOSE home

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
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.
intvisitCellEnd(Cell cell)
           Called when enumeration of a table cell has ended.
intvisitCellStart(Cell cell)
           Called when enumeration of a table cell has started.
intvisitCommentEnd(Comment comment)
           Called when enumeration of a comment text has ended.
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.
intvisitFieldEnd(FieldEnd fieldEnd)
           Called when a field ends in the document.
intvisitFieldSeparator(FieldSeparator fieldSeparator)
           Called when a field separator is encountered in the document.
intvisitFieldStart(FieldStart fieldStart)
           Called when a field starts 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.
intvisitFormField(FormField formField)
           Called when a form field is encountered in the document.
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.
intvisitRowEnd(Row row)
           Called when enumeration of a table row has ended.
intvisitRowStart(Row row)
           Called when enumeration of a table row 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.
intvisitTableEnd(Table table)
           Called when enumeration of a table has ended.
intvisitTableStart(Table table)
           Called when enumeration of a table has started.
 

Method Detail

visitSpecialChar

public int visitSpecialChar(SpecialChar specialChar)
                    throws java.lang.Exception
Called when a SpecialChar node is encountered in the document.
Parameters:
specialChar - The SpecialChar node 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 GroupShape node 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 GroupShape node 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 Shape node 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 Shape node 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 Comment node 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 Comment node 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 Footnote node 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 Footnote node 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 BookmarkEnd node 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 BookmarkStart node that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitFormField

public int visitFormField(FormField formField)
                  throws java.lang.Exception
Called when a form field is encountered in the document.
Parameters:
formField - The FormField node that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitFieldEnd

public int visitFieldEnd(FieldEnd fieldEnd)
                 throws java.lang.Exception
Called when a field ends in the document.

For more info see visitFieldStart(com.aspose.words.FieldStart)

Parameters:
fieldEnd - The FieldEnd node that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitFieldSeparator

public int visitFieldSeparator(FieldSeparator fieldSeparator)
                       throws java.lang.Exception
Called when a field separator is encountered in the document.

The field separator separates field code from field value in the document. Note that some fields have only field code and do not have field separator and field value.

For more info see visitFieldStart(com.aspose.words.FieldStart)

Parameters:
fieldSeparator - The FieldSeparator node that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitFieldStart

public int visitFieldStart(FieldStart fieldStart)
                   throws java.lang.Exception
Called when a field starts in the document.

A field in a Word Word document consists of a field code and field value.

For example, a field that displays a page number can be represented as follows:

[FieldStart]PAGE[FieldSeparator]98[FieldEnd]

The field separator separates field code from field value in the document. Note that some fields have only field code and do not have field separator and field value.

Fields can be nested.

Parameters:
fieldStart - The FieldStart node 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 Run node that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitCellEnd

public int visitCellEnd(Cell cell)
                throws java.lang.Exception
Called when enumeration of a table cell has ended.
Parameters:
cell - The Cell node that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitCellStart

public int visitCellStart(Cell cell)
                  throws java.lang.Exception
Called when enumeration of a table cell has started.
Parameters:
cell - The Cell node that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitRowEnd

public int visitRowEnd(Row row)
               throws java.lang.Exception
Called when enumeration of a table row has ended.
Parameters:
row - The Row node that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitRowStart

public int visitRowStart(Row row)
                 throws java.lang.Exception
Called when enumeration of a table row has started.
Parameters:
row - The Row node that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

visitTableEnd

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

visitTableStart

public int visitTableStart(Table table)
                   throws java.lang.Exception
Called when enumeration of a table has started.
Parameters:
table - The Table node 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 Paragraph node 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 Paragraph node 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 HeaderFooter node 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 HeaderFooter node 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 Body node 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 Body node 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 Section 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 Section 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 Document 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 Document that is being visited.
Returns:
A VisitorAction value that specifies how to continue the enumeration.

See Also:
          Wiki - the home page for the Aspose.Words Product Documentation that includes Programmer's Guide, Knowledge Base and other articles.
          Aspose.Words Support Forum - our preferred method of support.
          Aspose.Words Team - contact Aspose.Words Team.


ASPOSE home