com.aspose.words

Class DocumentVisitor

  • java.lang.Object
    • 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.

Example:

Shows how to use the Visitor pattern to add new operations to the Aspose.Words object model. In this case we create a simple document converter into a text format.
public void toText() throws Exception
{
    // Open the document we want to convert.
    Document doc = new Document(getMyDir() + "DocumentVisitor.Destination.docx");

    // Create an object that inherits from the DocumentVisitor class.
    MyDocToTxtWriter myConverter = new MyDocToTxtWriter();

    // This is the well known Visitor pattern. Get the model to accept a visitor.
    // The model will iterate through itself by calling the corresponding methods
    // on the visitor object (this is called visiting).
    //
    // Note that every node in the object model has the Accept method so the visiting
    // can be executed not only for the whole document, but for any node in the document.
    doc.accept(myConverter);

    // Once the visiting is complete, we can retrieve the result of the operation,
    // that in this example, has accumulated in the visitor.
    System.out.println(myConverter.getText());
}

/**
 * Simple implementation of saving a document in the plain text format. Implemented as a Visitor.
 */
public class MyDocToTxtWriter extends DocumentVisitor
{
    public MyDocToTxtWriter()
    {
        mIsSkipText = false;
        mBuilder = new StringBuilder();
    }

    /**
     * Gets the plain text of the document that was accumulated by the visitor.
     */
    public String getText()
    {
        return mBuilder.toString();
    }

    /**
     * Called when a Run node is encountered in the document.
     */
    public int visitRun(Run run) throws Exception
    {
        appendText(run.getText());

        // Let the visitor continue visiting other nodes.
        return VisitorAction.CONTINUE;
    }

    /**
     * Called when a FieldStart node is encountered in the document.
     */
    public int visitFieldStart(FieldStart fieldStart)
    {
        // In Microsoft Word, a field code (such as "MERGEFIELD FieldName") follows
        // after a field start character. We want to skip field codes and output field
        // result only, therefore we use a flag to suspend the output while inside a field code.
        //
        // Note this is a very simplistic implementation and will not work very well
        // if you have nested fields in a document.
        mIsSkipText = true;

        return VisitorAction.CONTINUE;
    }

    /**
     * Called when a FieldSeparator node is encountered in the document.
     */
    public int visitFieldSeparator(FieldSeparator fieldSeparator)
    {
        // Once reached a field separator node, we enable the output because we are
        // now entering the field result nodes.
        mIsSkipText = false;

        return VisitorAction.CONTINUE;
    }

    /**
     * Called when a FieldEnd node is encountered in the document.
     */
    public int visitFieldEnd(FieldEnd fieldEnd)
    {
        // Make sure we enable the output when reached a field end because some fields
        // do not have field separator and do not have field result.
        mIsSkipText = false;

        return VisitorAction.CONTINUE;
    }

    /**
     * Called when visiting of a Paragraph node is ended in the document.
     */
    public int visitParagraphEnd(Paragraph paragraph) throws Exception
    {
        // When outputting to plain text we output Cr+Lf characters.
        appendText(ControlChar.CR_LF);

        return VisitorAction.CONTINUE;
    }

    public int visitBodyStart(Body body)
    {
        // We can detect beginning and end of all composite nodes such as Section, Body,
        // Table, Paragraph etc and provide custom handling for them.
        mBuilder.append("*** Body Started ***\r\n");

        return VisitorAction.CONTINUE;
    }

    public int visitBodyEnd(Body body)
    {
        mBuilder.append("*** Body Ended ***\r\n");
        return VisitorAction.CONTINUE;
    }

    /**
     * Called when a HeaderFooter node is encountered in the document.
     */
    public int visitHeaderFooterStart(HeaderFooter headerFooter)
    {
        // Returning this value from a visitor method causes visiting of this
        // node to stop and move on to visiting the next sibling node.
        // The net effect in this example is that the text of headers and footers
        // is not included in the resulting output.
        return VisitorAction.SKIP_THIS_NODE;
    }

    /**
     * Called when an AbsolutePositionTab is encountered in the document.
     */
    public int visitAbsolutePositionTab(AbsolutePositionTab tab)
    {
        mBuilder.append("\t");
        return VisitorAction.CONTINUE;
    }

    /**
     * Called when a BookmarkStart is encountered in the document.
     */
    public int visitBookmarkStart(BookmarkStart bookmarkStart)
    {
        mBuilder.append("[");
        return VisitorAction.CONTINUE;
    }

    /**
     * Called when a BookmarkEnd is encountered in the document.
     */
    public int visitBookmarkEnd(BookmarkEnd bookmarkEnd)
    {
        mBuilder.append("]");
        return VisitorAction.CONTINUE;
    }

    /**
     * Adds text to the current output. Honours the enabled/disabled output flag.
     */
    private void appendText(String text)
    {
        if (!mIsSkipText) mBuilder.append(text);
    }

    private final StringBuilder mBuilder;
    private boolean mIsSkipText;
}

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.
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.
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.
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.
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.
intvisitOfficeMathEnd(OfficeMath officeMath)
Called when enumeration of a Office Math object has ended.
intvisitOfficeMathStart(OfficeMath officeMath)
Called when enumeration of a Office Math object 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.
intvisitSmartTagEnd(SmartTag smartTag)
Called when enumeration of a smart tag has ended.
intvisitSmartTagStart(SmartTag smartTag)
Called when enumeration of a smart tag has started.
intvisitSpecialChar(SpecialChar specialChar)
Called when a SpecialChar node is encountered in the document.
intvisitStructuredDocumentTagEnd(StructuredDocumentTag sdt)
Called when enumeration of a structured document tag has ended.
intvisitStructuredDocumentTagStart(StructuredDocumentTag sdt)
Called when enumeration of a structured document tag has started.
intvisitSubDocument(SubDocument subDocument)
Called when a subDocument is encountered.
intvisitTableEnd(Table table)
Called when enumeration of a table has ended.
intvisitTableStart(Table table)
Called when enumeration of a table has started.
 

    • 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.

        Example:

        Shows how to use the Visitor pattern to add new operations to the Aspose.Words object model. In this case we create a simple document converter into a text format.
        public void toText() throws Exception
        {
            // Open the document we want to convert.
            Document doc = new Document(getMyDir() + "DocumentVisitor.Destination.docx");
        
            // Create an object that inherits from the DocumentVisitor class.
            MyDocToTxtWriter myConverter = new MyDocToTxtWriter();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
            //
            // Note that every node in the object model has the Accept method so the visiting
            // can be executed not only for the whole document, but for any node in the document.
            doc.accept(myConverter);
        
            // Once the visiting is complete, we can retrieve the result of the operation,
            // that in this example, has accumulated in the visitor.
            System.out.println(myConverter.getText());
        }
        
        /**
         * Simple implementation of saving a document in the plain text format. Implemented as a Visitor.
         */
        public class MyDocToTxtWriter extends DocumentVisitor
        {
            public MyDocToTxtWriter()
            {
                mIsSkipText = false;
                mBuilder = new StringBuilder();
            }
        
            /**
             * Gets the plain text of the document that was accumulated by the visitor.
             */
            public String getText()
            {
                return mBuilder.toString();
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                appendText(run.getText());
        
                // Let the visitor continue visiting other nodes.
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart)
            {
                // In Microsoft Word, a field code (such as "MERGEFIELD FieldName") follows
                // after a field start character. We want to skip field codes and output field
                // result only, therefore we use a flag to suspend the output while inside a field code.
                //
                // Note this is a very simplistic implementation and will not work very well
                // if you have nested fields in a document.
                mIsSkipText = true;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator)
            {
                // Once reached a field separator node, we enable the output because we are
                // now entering the field result nodes.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd)
            {
                // Make sure we enable the output when reached a field end because some fields
                // do not have field separator and do not have field result.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Paragraph node is ended in the document.
             */
            public int visitParagraphEnd(Paragraph paragraph) throws Exception
            {
                // When outputting to plain text we output Cr+Lf characters.
                appendText(ControlChar.CR_LF);
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyStart(Body body)
            {
                // We can detect beginning and end of all composite nodes such as Section, Body,
                // Table, Paragraph etc and provide custom handling for them.
                mBuilder.append("*** Body Started ***\r\n");
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyEnd(Body body)
            {
                mBuilder.append("*** Body Ended ***\r\n");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a HeaderFooter node is encountered in the document.
             */
            public int visitHeaderFooterStart(HeaderFooter headerFooter)
            {
                // Returning this value from a visitor method causes visiting of this
                // node to stop and move on to visiting the next sibling node.
                // The net effect in this example is that the text of headers and footers
                // is not included in the resulting output.
                return VisitorAction.SKIP_THIS_NODE;
            }
        
            /**
             * Called when an AbsolutePositionTab is encountered in the document.
             */
            public int visitAbsolutePositionTab(AbsolutePositionTab tab)
            {
                mBuilder.append("\t");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkStart is encountered in the document.
             */
            public int visitBookmarkStart(BookmarkStart bookmarkStart)
            {
                mBuilder.append("[");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkEnd is encountered in the document.
             */
            public int visitBookmarkEnd(BookmarkEnd bookmarkEnd)
            {
                mBuilder.append("]");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Adds text to the current output. Honours the enabled/disabled output flag.
             */
            private void appendText(String text)
            {
                if (!mIsSkipText) mBuilder.append(text);
            }
        
            private final StringBuilder mBuilder;
            private boolean mIsSkipText;
        }
      • 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.

        Example:

        Shows how to use the Visitor pattern to add new operations to the Aspose.Words object model. In this case we create a simple document converter into a text format.
        public void toText() throws Exception
        {
            // Open the document we want to convert.
            Document doc = new Document(getMyDir() + "DocumentVisitor.Destination.docx");
        
            // Create an object that inherits from the DocumentVisitor class.
            MyDocToTxtWriter myConverter = new MyDocToTxtWriter();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
            //
            // Note that every node in the object model has the Accept method so the visiting
            // can be executed not only for the whole document, but for any node in the document.
            doc.accept(myConverter);
        
            // Once the visiting is complete, we can retrieve the result of the operation,
            // that in this example, has accumulated in the visitor.
            System.out.println(myConverter.getText());
        }
        
        /**
         * Simple implementation of saving a document in the plain text format. Implemented as a Visitor.
         */
        public class MyDocToTxtWriter extends DocumentVisitor
        {
            public MyDocToTxtWriter()
            {
                mIsSkipText = false;
                mBuilder = new StringBuilder();
            }
        
            /**
             * Gets the plain text of the document that was accumulated by the visitor.
             */
            public String getText()
            {
                return mBuilder.toString();
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                appendText(run.getText());
        
                // Let the visitor continue visiting other nodes.
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart)
            {
                // In Microsoft Word, a field code (such as "MERGEFIELD FieldName") follows
                // after a field start character. We want to skip field codes and output field
                // result only, therefore we use a flag to suspend the output while inside a field code.
                //
                // Note this is a very simplistic implementation and will not work very well
                // if you have nested fields in a document.
                mIsSkipText = true;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator)
            {
                // Once reached a field separator node, we enable the output because we are
                // now entering the field result nodes.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd)
            {
                // Make sure we enable the output when reached a field end because some fields
                // do not have field separator and do not have field result.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Paragraph node is ended in the document.
             */
            public int visitParagraphEnd(Paragraph paragraph) throws Exception
            {
                // When outputting to plain text we output Cr+Lf characters.
                appendText(ControlChar.CR_LF);
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyStart(Body body)
            {
                // We can detect beginning and end of all composite nodes such as Section, Body,
                // Table, Paragraph etc and provide custom handling for them.
                mBuilder.append("*** Body Started ***\r\n");
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyEnd(Body body)
            {
                mBuilder.append("*** Body Ended ***\r\n");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a HeaderFooter node is encountered in the document.
             */
            public int visitHeaderFooterStart(HeaderFooter headerFooter)
            {
                // Returning this value from a visitor method causes visiting of this
                // node to stop and move on to visiting the next sibling node.
                // The net effect in this example is that the text of headers and footers
                // is not included in the resulting output.
                return VisitorAction.SKIP_THIS_NODE;
            }
        
            /**
             * Called when an AbsolutePositionTab is encountered in the document.
             */
            public int visitAbsolutePositionTab(AbsolutePositionTab tab)
            {
                mBuilder.append("\t");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkStart is encountered in the document.
             */
            public int visitBookmarkStart(BookmarkStart bookmarkStart)
            {
                mBuilder.append("[");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkEnd is encountered in the document.
             */
            public int visitBookmarkEnd(BookmarkEnd bookmarkEnd)
            {
                mBuilder.append("]");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Adds text to the current output. Honours the enabled/disabled output flag.
             */
            private void appendText(String text)
            {
                if (!mIsSkipText) mBuilder.append(text);
            }
        
            private final StringBuilder mBuilder;
            private boolean mIsSkipText;
        }
      • 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.

        Example:

        Shows how to use the Visitor pattern to add new operations to the Aspose.Words object model. In this case we create a simple document converter into a text format.
        public void toText() throws Exception
        {
            // Open the document we want to convert.
            Document doc = new Document(getMyDir() + "DocumentVisitor.Destination.docx");
        
            // Create an object that inherits from the DocumentVisitor class.
            MyDocToTxtWriter myConverter = new MyDocToTxtWriter();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
            //
            // Note that every node in the object model has the Accept method so the visiting
            // can be executed not only for the whole document, but for any node in the document.
            doc.accept(myConverter);
        
            // Once the visiting is complete, we can retrieve the result of the operation,
            // that in this example, has accumulated in the visitor.
            System.out.println(myConverter.getText());
        }
        
        /**
         * Simple implementation of saving a document in the plain text format. Implemented as a Visitor.
         */
        public class MyDocToTxtWriter extends DocumentVisitor
        {
            public MyDocToTxtWriter()
            {
                mIsSkipText = false;
                mBuilder = new StringBuilder();
            }
        
            /**
             * Gets the plain text of the document that was accumulated by the visitor.
             */
            public String getText()
            {
                return mBuilder.toString();
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                appendText(run.getText());
        
                // Let the visitor continue visiting other nodes.
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart)
            {
                // In Microsoft Word, a field code (such as "MERGEFIELD FieldName") follows
                // after a field start character. We want to skip field codes and output field
                // result only, therefore we use a flag to suspend the output while inside a field code.
                //
                // Note this is a very simplistic implementation and will not work very well
                // if you have nested fields in a document.
                mIsSkipText = true;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator)
            {
                // Once reached a field separator node, we enable the output because we are
                // now entering the field result nodes.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd)
            {
                // Make sure we enable the output when reached a field end because some fields
                // do not have field separator and do not have field result.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Paragraph node is ended in the document.
             */
            public int visitParagraphEnd(Paragraph paragraph) throws Exception
            {
                // When outputting to plain text we output Cr+Lf characters.
                appendText(ControlChar.CR_LF);
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyStart(Body body)
            {
                // We can detect beginning and end of all composite nodes such as Section, Body,
                // Table, Paragraph etc and provide custom handling for them.
                mBuilder.append("*** Body Started ***\r\n");
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyEnd(Body body)
            {
                mBuilder.append("*** Body Ended ***\r\n");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a HeaderFooter node is encountered in the document.
             */
            public int visitHeaderFooterStart(HeaderFooter headerFooter)
            {
                // Returning this value from a visitor method causes visiting of this
                // node to stop and move on to visiting the next sibling node.
                // The net effect in this example is that the text of headers and footers
                // is not included in the resulting output.
                return VisitorAction.SKIP_THIS_NODE;
            }
        
            /**
             * Called when an AbsolutePositionTab is encountered in the document.
             */
            public int visitAbsolutePositionTab(AbsolutePositionTab tab)
            {
                mBuilder.append("\t");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkStart is encountered in the document.
             */
            public int visitBookmarkStart(BookmarkStart bookmarkStart)
            {
                mBuilder.append("[");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkEnd is encountered in the document.
             */
            public int visitBookmarkEnd(BookmarkEnd bookmarkEnd)
            {
                mBuilder.append("]");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Adds text to the current output. Honours the enabled/disabled output flag.
             */
            private void appendText(String text)
            {
                if (!mIsSkipText) mBuilder.append(text);
            }
        
            private final StringBuilder mBuilder;
            private boolean mIsSkipText;
        }
      • 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.

        Example:

        Shows how to use the Visitor pattern to add new operations to the Aspose.Words object model. In this case we create a simple document converter into a text format.
        public void toText() throws Exception
        {
            // Open the document we want to convert.
            Document doc = new Document(getMyDir() + "DocumentVisitor.Destination.docx");
        
            // Create an object that inherits from the DocumentVisitor class.
            MyDocToTxtWriter myConverter = new MyDocToTxtWriter();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
            //
            // Note that every node in the object model has the Accept method so the visiting
            // can be executed not only for the whole document, but for any node in the document.
            doc.accept(myConverter);
        
            // Once the visiting is complete, we can retrieve the result of the operation,
            // that in this example, has accumulated in the visitor.
            System.out.println(myConverter.getText());
        }
        
        /**
         * Simple implementation of saving a document in the plain text format. Implemented as a Visitor.
         */
        public class MyDocToTxtWriter extends DocumentVisitor
        {
            public MyDocToTxtWriter()
            {
                mIsSkipText = false;
                mBuilder = new StringBuilder();
            }
        
            /**
             * Gets the plain text of the document that was accumulated by the visitor.
             */
            public String getText()
            {
                return mBuilder.toString();
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                appendText(run.getText());
        
                // Let the visitor continue visiting other nodes.
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart)
            {
                // In Microsoft Word, a field code (such as "MERGEFIELD FieldName") follows
                // after a field start character. We want to skip field codes and output field
                // result only, therefore we use a flag to suspend the output while inside a field code.
                //
                // Note this is a very simplistic implementation and will not work very well
                // if you have nested fields in a document.
                mIsSkipText = true;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator)
            {
                // Once reached a field separator node, we enable the output because we are
                // now entering the field result nodes.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd)
            {
                // Make sure we enable the output when reached a field end because some fields
                // do not have field separator and do not have field result.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Paragraph node is ended in the document.
             */
            public int visitParagraphEnd(Paragraph paragraph) throws Exception
            {
                // When outputting to plain text we output Cr+Lf characters.
                appendText(ControlChar.CR_LF);
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyStart(Body body)
            {
                // We can detect beginning and end of all composite nodes such as Section, Body,
                // Table, Paragraph etc and provide custom handling for them.
                mBuilder.append("*** Body Started ***\r\n");
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyEnd(Body body)
            {
                mBuilder.append("*** Body Ended ***\r\n");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a HeaderFooter node is encountered in the document.
             */
            public int visitHeaderFooterStart(HeaderFooter headerFooter)
            {
                // Returning this value from a visitor method causes visiting of this
                // node to stop and move on to visiting the next sibling node.
                // The net effect in this example is that the text of headers and footers
                // is not included in the resulting output.
                return VisitorAction.SKIP_THIS_NODE;
            }
        
            /**
             * Called when an AbsolutePositionTab is encountered in the document.
             */
            public int visitAbsolutePositionTab(AbsolutePositionTab tab)
            {
                mBuilder.append("\t");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkStart is encountered in the document.
             */
            public int visitBookmarkStart(BookmarkStart bookmarkStart)
            {
                mBuilder.append("[");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkEnd is encountered in the document.
             */
            public int visitBookmarkEnd(BookmarkEnd bookmarkEnd)
            {
                mBuilder.append("]");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Adds text to the current output. Honours the enabled/disabled output flag.
             */
            private void appendText(String text)
            {
                if (!mIsSkipText) mBuilder.append(text);
            }
        
            private final StringBuilder mBuilder;
            private boolean mIsSkipText;
        }
      • 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.

        Example:

        Shows how to use the Visitor pattern to add new operations to the Aspose.Words object model. In this case we create a simple document converter into a text format.
        public void toText() throws Exception
        {
            // Open the document we want to convert.
            Document doc = new Document(getMyDir() + "DocumentVisitor.Destination.docx");
        
            // Create an object that inherits from the DocumentVisitor class.
            MyDocToTxtWriter myConverter = new MyDocToTxtWriter();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
            //
            // Note that every node in the object model has the Accept method so the visiting
            // can be executed not only for the whole document, but for any node in the document.
            doc.accept(myConverter);
        
            // Once the visiting is complete, we can retrieve the result of the operation,
            // that in this example, has accumulated in the visitor.
            System.out.println(myConverter.getText());
        }
        
        /**
         * Simple implementation of saving a document in the plain text format. Implemented as a Visitor.
         */
        public class MyDocToTxtWriter extends DocumentVisitor
        {
            public MyDocToTxtWriter()
            {
                mIsSkipText = false;
                mBuilder = new StringBuilder();
            }
        
            /**
             * Gets the plain text of the document that was accumulated by the visitor.
             */
            public String getText()
            {
                return mBuilder.toString();
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                appendText(run.getText());
        
                // Let the visitor continue visiting other nodes.
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart)
            {
                // In Microsoft Word, a field code (such as "MERGEFIELD FieldName") follows
                // after a field start character. We want to skip field codes and output field
                // result only, therefore we use a flag to suspend the output while inside a field code.
                //
                // Note this is a very simplistic implementation and will not work very well
                // if you have nested fields in a document.
                mIsSkipText = true;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator)
            {
                // Once reached a field separator node, we enable the output because we are
                // now entering the field result nodes.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd)
            {
                // Make sure we enable the output when reached a field end because some fields
                // do not have field separator and do not have field result.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Paragraph node is ended in the document.
             */
            public int visitParagraphEnd(Paragraph paragraph) throws Exception
            {
                // When outputting to plain text we output Cr+Lf characters.
                appendText(ControlChar.CR_LF);
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyStart(Body body)
            {
                // We can detect beginning and end of all composite nodes such as Section, Body,
                // Table, Paragraph etc and provide custom handling for them.
                mBuilder.append("*** Body Started ***\r\n");
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyEnd(Body body)
            {
                mBuilder.append("*** Body Ended ***\r\n");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a HeaderFooter node is encountered in the document.
             */
            public int visitHeaderFooterStart(HeaderFooter headerFooter)
            {
                // Returning this value from a visitor method causes visiting of this
                // node to stop and move on to visiting the next sibling node.
                // The net effect in this example is that the text of headers and footers
                // is not included in the resulting output.
                return VisitorAction.SKIP_THIS_NODE;
            }
        
            /**
             * Called when an AbsolutePositionTab is encountered in the document.
             */
            public int visitAbsolutePositionTab(AbsolutePositionTab tab)
            {
                mBuilder.append("\t");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkStart is encountered in the document.
             */
            public int visitBookmarkStart(BookmarkStart bookmarkStart)
            {
                mBuilder.append("[");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkEnd is encountered in the document.
             */
            public int visitBookmarkEnd(BookmarkEnd bookmarkEnd)
            {
                mBuilder.append("]");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Adds text to the current output. Honours the enabled/disabled output flag.
             */
            private void appendText(String text)
            {
                if (!mIsSkipText) mBuilder.append(text);
            }
        
            private final StringBuilder mBuilder;
            private boolean mIsSkipText;
        }
      • 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.
      • visitCellEnd

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

        Example:

        Implements the Visitor Pattern to remove all content formatted as hidden from the document.
        public void removeHiddenContentFromDocument() throws Exception
        {
            // Open the document we want to remove hidden content from.
            Document doc = new Document(getMyDir() + "Font.Hidden.doc");
        
            // Create an object that inherits from the DocumentVisitor class.
            RemoveHiddenContentVisitor hiddenContentRemover = new RemoveHiddenContentVisitor();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
        
            // We can run it over the entire the document like so:
            doc.accept(hiddenContentRemover);
        
            // Or we can run it on only a specific node.
            Paragraph para = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 4, true);
            para.accept(hiddenContentRemover);
        
            // Or over a different type of node like below.
            Table table = (Table) doc.getChild(NodeType.TABLE, 0, true);
            table.accept(hiddenContentRemover);
        
            doc.save(getMyDir() + "\\Artifacts\\Font.Hidden.doc");
        
        }
        
        /**
         * This class when executed will remove all hidden content from the Document. Implemented as a Visitor.
         */
        private class RemoveHiddenContentVisitor extends DocumentVisitor
        {
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart) throws Exception
            {
                // If this node is hidden, then remove it.
                if (isHidden(fieldStart)) fieldStart.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd) throws Exception
            {
                if (isHidden(fieldEnd)) fieldEnd.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator) throws Exception
            {
                if (isHidden(fieldSeparator)) fieldSeparator.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                if (isHidden(run)) run.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Paragraph node is encountered in the document.
             */
            public int visitParagraphStart(Paragraph paragraph) throws Exception
            {
                if (isHidden(paragraph)) paragraph.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FormField is encountered in the document.
             */
            public int visitFormField(FormField field) throws Exception
            {
                if (isHidden(field)) field.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a GroupShape is encountered in the document.
             */
            public int visitGroupShapeStart(GroupShape groupShape) throws Exception
            {
                if (isHidden(groupShape)) groupShape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Shape is encountered in the document.
             */
            public int visitShapeStart(Shape shape) throws Exception
            {
                if (isHidden(shape)) shape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Comment is encountered in the document.
             */
            public int visitCommentStart(Comment comment) throws Exception
            {
                if (isHidden(comment)) comment.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Footnote is encountered in the document.
             */
            public int visitFootnoteStart(Footnote footnote) throws Exception
            {
                if (isHidden(footnote)) footnote.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Table node is ended in the document.
             */
            public int visitTableEnd(Table table)
            {
                // At the moment there is no way to tell if a particular Table/Row/Cell is hidden.
                // Instead, if the content of a table is hidden, then all inline child nodes of the table should be
                // hidden and thus removed by previous visits as well. This will result in the container being empty
                // so if this is the case we know to remove the table node.
                //
                // Note that a table which is not hidden but simply has no content will not be affected by this algorthim,
                // as technically they are not completely empty (for example a properly formed Cell will have at least
                // an empty paragraph in it)
                if (!table.hasChildNodes()) table.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Cell node is ended in the document.
             */
            public int visitCellEnd(Cell cell)
            {
                if (!cell.hasChildNodes() && cell.getParentNode() != null) cell.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Row node is ended in the document.
             */
            public int visitRowEnd(Row row)
            {
                if (!row.hasChildNodes() && row.getParentNode() != null) row.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a SpecialCharacter is encountered in the document.
             */
            public int visitSpecialChar(SpecialChar character) throws Exception
            {
                if (isHidden(character)) character.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Returns true if the node passed is set as hidden, returns false if it is visible.
             */
            private boolean isHidden(Node node)
            {
                if (node instanceof Inline)
                {
                    // If the node is Inline then cast it to retrieve the Font property which contains the hidden property
                    Inline currentNode = (Inline) node;
                    return currentNode.getFont().getHidden();
                } else if (node.getNodeType() == NodeType.PARAGRAPH)
                {
                    // If the node is a paragraph cast it to retrieve the ParagraphBreakFont which contains the hidden property
                    Paragraph para = (Paragraph) node;
                    return para.getParagraphBreakFont().getHidden();
                } else if (node instanceof ShapeBase)
                {
                    // Node is a shape or groupshape.
                    ShapeBase shape = (ShapeBase) node;
                    return shape.getFont().getHidden();
                } else if (node instanceof InlineStory)
                {
                    // Node is a comment or footnote.
                    InlineStory inlineStory = (InlineStory) node;
                    return inlineStory.getFont().getHidden();
                }
        
                // A node that is passed to this method which does not contain a hidden property will end up here.
                // By default nodes are not hidden so return false.
                return false;
            }
        }
      • visitCellStart

        public int visitCellStart(Cell cell)
                          throws java.lang.Exception
        Called when enumeration of a table cell has started.
        Parameters:
        cell - 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.

        Example:

        Implements the Visitor Pattern to remove all content formatted as hidden from the document.
        public void removeHiddenContentFromDocument() throws Exception
        {
            // Open the document we want to remove hidden content from.
            Document doc = new Document(getMyDir() + "Font.Hidden.doc");
        
            // Create an object that inherits from the DocumentVisitor class.
            RemoveHiddenContentVisitor hiddenContentRemover = new RemoveHiddenContentVisitor();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
        
            // We can run it over the entire the document like so:
            doc.accept(hiddenContentRemover);
        
            // Or we can run it on only a specific node.
            Paragraph para = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 4, true);
            para.accept(hiddenContentRemover);
        
            // Or over a different type of node like below.
            Table table = (Table) doc.getChild(NodeType.TABLE, 0, true);
            table.accept(hiddenContentRemover);
        
            doc.save(getMyDir() + "\\Artifacts\\Font.Hidden.doc");
        
        }
        
        /**
         * This class when executed will remove all hidden content from the Document. Implemented as a Visitor.
         */
        private class RemoveHiddenContentVisitor extends DocumentVisitor
        {
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart) throws Exception
            {
                // If this node is hidden, then remove it.
                if (isHidden(fieldStart)) fieldStart.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd) throws Exception
            {
                if (isHidden(fieldEnd)) fieldEnd.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator) throws Exception
            {
                if (isHidden(fieldSeparator)) fieldSeparator.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                if (isHidden(run)) run.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Paragraph node is encountered in the document.
             */
            public int visitParagraphStart(Paragraph paragraph) throws Exception
            {
                if (isHidden(paragraph)) paragraph.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FormField is encountered in the document.
             */
            public int visitFormField(FormField field) throws Exception
            {
                if (isHidden(field)) field.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a GroupShape is encountered in the document.
             */
            public int visitGroupShapeStart(GroupShape groupShape) throws Exception
            {
                if (isHidden(groupShape)) groupShape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Shape is encountered in the document.
             */
            public int visitShapeStart(Shape shape) throws Exception
            {
                if (isHidden(shape)) shape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Comment is encountered in the document.
             */
            public int visitCommentStart(Comment comment) throws Exception
            {
                if (isHidden(comment)) comment.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Footnote is encountered in the document.
             */
            public int visitFootnoteStart(Footnote footnote) throws Exception
            {
                if (isHidden(footnote)) footnote.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Table node is ended in the document.
             */
            public int visitTableEnd(Table table)
            {
                // At the moment there is no way to tell if a particular Table/Row/Cell is hidden.
                // Instead, if the content of a table is hidden, then all inline child nodes of the table should be
                // hidden and thus removed by previous visits as well. This will result in the container being empty
                // so if this is the case we know to remove the table node.
                //
                // Note that a table which is not hidden but simply has no content will not be affected by this algorthim,
                // as technically they are not completely empty (for example a properly formed Cell will have at least
                // an empty paragraph in it)
                if (!table.hasChildNodes()) table.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Cell node is ended in the document.
             */
            public int visitCellEnd(Cell cell)
            {
                if (!cell.hasChildNodes() && cell.getParentNode() != null) cell.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Row node is ended in the document.
             */
            public int visitRowEnd(Row row)
            {
                if (!row.hasChildNodes() && row.getParentNode() != null) row.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a SpecialCharacter is encountered in the document.
             */
            public int visitSpecialChar(SpecialChar character) throws Exception
            {
                if (isHidden(character)) character.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Returns true if the node passed is set as hidden, returns false if it is visible.
             */
            private boolean isHidden(Node node)
            {
                if (node instanceof Inline)
                {
                    // If the node is Inline then cast it to retrieve the Font property which contains the hidden property
                    Inline currentNode = (Inline) node;
                    return currentNode.getFont().getHidden();
                } else if (node.getNodeType() == NodeType.PARAGRAPH)
                {
                    // If the node is a paragraph cast it to retrieve the ParagraphBreakFont which contains the hidden property
                    Paragraph para = (Paragraph) node;
                    return para.getParagraphBreakFont().getHidden();
                } else if (node instanceof ShapeBase)
                {
                    // Node is a shape or groupshape.
                    ShapeBase shape = (ShapeBase) node;
                    return shape.getFont().getHidden();
                } else if (node instanceof InlineStory)
                {
                    // Node is a comment or footnote.
                    InlineStory inlineStory = (InlineStory) node;
                    return inlineStory.getFont().getHidden();
                }
        
                // A node that is passed to this method which does not contain a hidden property will end up here.
                // By default nodes are not hidden so return false.
                return false;
            }
        }
      • 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.
      • 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 object that is being visited.
        Returns:
        A VisitorAction value that specifies how to continue the enumeration.

        Example:

        Shows how to use the Visitor pattern to add new operations to the Aspose.Words object model. In this case we create a simple document converter into a text format.
        public void toText() throws Exception
        {
            // Open the document we want to convert.
            Document doc = new Document(getMyDir() + "DocumentVisitor.Destination.docx");
        
            // Create an object that inherits from the DocumentVisitor class.
            MyDocToTxtWriter myConverter = new MyDocToTxtWriter();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
            //
            // Note that every node in the object model has the Accept method so the visiting
            // can be executed not only for the whole document, but for any node in the document.
            doc.accept(myConverter);
        
            // Once the visiting is complete, we can retrieve the result of the operation,
            // that in this example, has accumulated in the visitor.
            System.out.println(myConverter.getText());
        }
        
        /**
         * Simple implementation of saving a document in the plain text format. Implemented as a Visitor.
         */
        public class MyDocToTxtWriter extends DocumentVisitor
        {
            public MyDocToTxtWriter()
            {
                mIsSkipText = false;
                mBuilder = new StringBuilder();
            }
        
            /**
             * Gets the plain text of the document that was accumulated by the visitor.
             */
            public String getText()
            {
                return mBuilder.toString();
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                appendText(run.getText());
        
                // Let the visitor continue visiting other nodes.
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart)
            {
                // In Microsoft Word, a field code (such as "MERGEFIELD FieldName") follows
                // after a field start character. We want to skip field codes and output field
                // result only, therefore we use a flag to suspend the output while inside a field code.
                //
                // Note this is a very simplistic implementation and will not work very well
                // if you have nested fields in a document.
                mIsSkipText = true;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator)
            {
                // Once reached a field separator node, we enable the output because we are
                // now entering the field result nodes.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd)
            {
                // Make sure we enable the output when reached a field end because some fields
                // do not have field separator and do not have field result.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Paragraph node is ended in the document.
             */
            public int visitParagraphEnd(Paragraph paragraph) throws Exception
            {
                // When outputting to plain text we output Cr+Lf characters.
                appendText(ControlChar.CR_LF);
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyStart(Body body)
            {
                // We can detect beginning and end of all composite nodes such as Section, Body,
                // Table, Paragraph etc and provide custom handling for them.
                mBuilder.append("*** Body Started ***\r\n");
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyEnd(Body body)
            {
                mBuilder.append("*** Body Ended ***\r\n");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a HeaderFooter node is encountered in the document.
             */
            public int visitHeaderFooterStart(HeaderFooter headerFooter)
            {
                // Returning this value from a visitor method causes visiting of this
                // node to stop and move on to visiting the next sibling node.
                // The net effect in this example is that the text of headers and footers
                // is not included in the resulting output.
                return VisitorAction.SKIP_THIS_NODE;
            }
        
            /**
             * Called when an AbsolutePositionTab is encountered in the document.
             */
            public int visitAbsolutePositionTab(AbsolutePositionTab tab)
            {
                mBuilder.append("\t");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkStart is encountered in the document.
             */
            public int visitBookmarkStart(BookmarkStart bookmarkStart)
            {
                mBuilder.append("[");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkEnd is encountered in the document.
             */
            public int visitBookmarkEnd(BookmarkEnd bookmarkEnd)
            {
                mBuilder.append("]");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Adds text to the current output. Honours the enabled/disabled output flag.
             */
            private void appendText(String text)
            {
                if (!mIsSkipText) mBuilder.append(text);
            }
        
            private final StringBuilder mBuilder;
            private boolean mIsSkipText;
        }
      • 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 object that is being visited.
        Returns:
        A VisitorAction value that specifies how to continue the enumeration.

        Example:

        Shows how to use the Visitor pattern to add new operations to the Aspose.Words object model. In this case we create a simple document converter into a text format.
        public void toText() throws Exception
        {
            // Open the document we want to convert.
            Document doc = new Document(getMyDir() + "DocumentVisitor.Destination.docx");
        
            // Create an object that inherits from the DocumentVisitor class.
            MyDocToTxtWriter myConverter = new MyDocToTxtWriter();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
            //
            // Note that every node in the object model has the Accept method so the visiting
            // can be executed not only for the whole document, but for any node in the document.
            doc.accept(myConverter);
        
            // Once the visiting is complete, we can retrieve the result of the operation,
            // that in this example, has accumulated in the visitor.
            System.out.println(myConverter.getText());
        }
        
        /**
         * Simple implementation of saving a document in the plain text format. Implemented as a Visitor.
         */
        public class MyDocToTxtWriter extends DocumentVisitor
        {
            public MyDocToTxtWriter()
            {
                mIsSkipText = false;
                mBuilder = new StringBuilder();
            }
        
            /**
             * Gets the plain text of the document that was accumulated by the visitor.
             */
            public String getText()
            {
                return mBuilder.toString();
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                appendText(run.getText());
        
                // Let the visitor continue visiting other nodes.
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart)
            {
                // In Microsoft Word, a field code (such as "MERGEFIELD FieldName") follows
                // after a field start character. We want to skip field codes and output field
                // result only, therefore we use a flag to suspend the output while inside a field code.
                //
                // Note this is a very simplistic implementation and will not work very well
                // if you have nested fields in a document.
                mIsSkipText = true;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator)
            {
                // Once reached a field separator node, we enable the output because we are
                // now entering the field result nodes.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd)
            {
                // Make sure we enable the output when reached a field end because some fields
                // do not have field separator and do not have field result.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Paragraph node is ended in the document.
             */
            public int visitParagraphEnd(Paragraph paragraph) throws Exception
            {
                // When outputting to plain text we output Cr+Lf characters.
                appendText(ControlChar.CR_LF);
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyStart(Body body)
            {
                // We can detect beginning and end of all composite nodes such as Section, Body,
                // Table, Paragraph etc and provide custom handling for them.
                mBuilder.append("*** Body Started ***\r\n");
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyEnd(Body body)
            {
                mBuilder.append("*** Body Ended ***\r\n");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a HeaderFooter node is encountered in the document.
             */
            public int visitHeaderFooterStart(HeaderFooter headerFooter)
            {
                // Returning this value from a visitor method causes visiting of this
                // node to stop and move on to visiting the next sibling node.
                // The net effect in this example is that the text of headers and footers
                // is not included in the resulting output.
                return VisitorAction.SKIP_THIS_NODE;
            }
        
            /**
             * Called when an AbsolutePositionTab is encountered in the document.
             */
            public int visitAbsolutePositionTab(AbsolutePositionTab tab)
            {
                mBuilder.append("\t");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkStart is encountered in the document.
             */
            public int visitBookmarkStart(BookmarkStart bookmarkStart)
            {
                mBuilder.append("[");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkEnd is encountered in the document.
             */
            public int visitBookmarkEnd(BookmarkEnd bookmarkEnd)
            {
                mBuilder.append("]");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Adds text to the current output. Honours the enabled/disabled output flag.
             */
            private void appendText(String text)
            {
                if (!mIsSkipText) mBuilder.append(text);
            }
        
            private final StringBuilder mBuilder;
            private boolean mIsSkipText;
        }
      • 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 object that is being visited.
        Returns:
        A VisitorAction value that specifies how to continue the enumeration.

        Example:

        Shows how to use the Visitor pattern to add new operations to the Aspose.Words object model. In this case we create a simple document converter into a text format.
        public void toText() throws Exception
        {
            // Open the document we want to convert.
            Document doc = new Document(getMyDir() + "DocumentVisitor.Destination.docx");
        
            // Create an object that inherits from the DocumentVisitor class.
            MyDocToTxtWriter myConverter = new MyDocToTxtWriter();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
            //
            // Note that every node in the object model has the Accept method so the visiting
            // can be executed not only for the whole document, but for any node in the document.
            doc.accept(myConverter);
        
            // Once the visiting is complete, we can retrieve the result of the operation,
            // that in this example, has accumulated in the visitor.
            System.out.println(myConverter.getText());
        }
        
        /**
         * Simple implementation of saving a document in the plain text format. Implemented as a Visitor.
         */
        public class MyDocToTxtWriter extends DocumentVisitor
        {
            public MyDocToTxtWriter()
            {
                mIsSkipText = false;
                mBuilder = new StringBuilder();
            }
        
            /**
             * Gets the plain text of the document that was accumulated by the visitor.
             */
            public String getText()
            {
                return mBuilder.toString();
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                appendText(run.getText());
        
                // Let the visitor continue visiting other nodes.
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart)
            {
                // In Microsoft Word, a field code (such as "MERGEFIELD FieldName") follows
                // after a field start character. We want to skip field codes and output field
                // result only, therefore we use a flag to suspend the output while inside a field code.
                //
                // Note this is a very simplistic implementation and will not work very well
                // if you have nested fields in a document.
                mIsSkipText = true;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator)
            {
                // Once reached a field separator node, we enable the output because we are
                // now entering the field result nodes.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd)
            {
                // Make sure we enable the output when reached a field end because some fields
                // do not have field separator and do not have field result.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Paragraph node is ended in the document.
             */
            public int visitParagraphEnd(Paragraph paragraph) throws Exception
            {
                // When outputting to plain text we output Cr+Lf characters.
                appendText(ControlChar.CR_LF);
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyStart(Body body)
            {
                // We can detect beginning and end of all composite nodes such as Section, Body,
                // Table, Paragraph etc and provide custom handling for them.
                mBuilder.append("*** Body Started ***\r\n");
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyEnd(Body body)
            {
                mBuilder.append("*** Body Ended ***\r\n");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a HeaderFooter node is encountered in the document.
             */
            public int visitHeaderFooterStart(HeaderFooter headerFooter)
            {
                // Returning this value from a visitor method causes visiting of this
                // node to stop and move on to visiting the next sibling node.
                // The net effect in this example is that the text of headers and footers
                // is not included in the resulting output.
                return VisitorAction.SKIP_THIS_NODE;
            }
        
            /**
             * Called when an AbsolutePositionTab is encountered in the document.
             */
            public int visitAbsolutePositionTab(AbsolutePositionTab tab)
            {
                mBuilder.append("\t");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkStart is encountered in the document.
             */
            public int visitBookmarkStart(BookmarkStart bookmarkStart)
            {
                mBuilder.append("[");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkEnd is encountered in the document.
             */
            public int visitBookmarkEnd(BookmarkEnd bookmarkEnd)
            {
                mBuilder.append("]");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Adds text to the current output. Honours the enabled/disabled output flag.
             */
            private void appendText(String text)
            {
                if (!mIsSkipText) mBuilder.append(text);
            }
        
            private final StringBuilder mBuilder;
            private boolean mIsSkipText;
        }
      • 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.

        Example:

        Implements the Visitor Pattern to remove all content formatted as hidden from the document.
        public void removeHiddenContentFromDocument() throws Exception
        {
            // Open the document we want to remove hidden content from.
            Document doc = new Document(getMyDir() + "Font.Hidden.doc");
        
            // Create an object that inherits from the DocumentVisitor class.
            RemoveHiddenContentVisitor hiddenContentRemover = new RemoveHiddenContentVisitor();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
        
            // We can run it over the entire the document like so:
            doc.accept(hiddenContentRemover);
        
            // Or we can run it on only a specific node.
            Paragraph para = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 4, true);
            para.accept(hiddenContentRemover);
        
            // Or over a different type of node like below.
            Table table = (Table) doc.getChild(NodeType.TABLE, 0, true);
            table.accept(hiddenContentRemover);
        
            doc.save(getMyDir() + "\\Artifacts\\Font.Hidden.doc");
        
        }
        
        /**
         * This class when executed will remove all hidden content from the Document. Implemented as a Visitor.
         */
        private class RemoveHiddenContentVisitor extends DocumentVisitor
        {
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart) throws Exception
            {
                // If this node is hidden, then remove it.
                if (isHidden(fieldStart)) fieldStart.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd) throws Exception
            {
                if (isHidden(fieldEnd)) fieldEnd.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator) throws Exception
            {
                if (isHidden(fieldSeparator)) fieldSeparator.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                if (isHidden(run)) run.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Paragraph node is encountered in the document.
             */
            public int visitParagraphStart(Paragraph paragraph) throws Exception
            {
                if (isHidden(paragraph)) paragraph.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FormField is encountered in the document.
             */
            public int visitFormField(FormField field) throws Exception
            {
                if (isHidden(field)) field.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a GroupShape is encountered in the document.
             */
            public int visitGroupShapeStart(GroupShape groupShape) throws Exception
            {
                if (isHidden(groupShape)) groupShape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Shape is encountered in the document.
             */
            public int visitShapeStart(Shape shape) throws Exception
            {
                if (isHidden(shape)) shape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Comment is encountered in the document.
             */
            public int visitCommentStart(Comment comment) throws Exception
            {
                if (isHidden(comment)) comment.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Footnote is encountered in the document.
             */
            public int visitFootnoteStart(Footnote footnote) throws Exception
            {
                if (isHidden(footnote)) footnote.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Table node is ended in the document.
             */
            public int visitTableEnd(Table table)
            {
                // At the moment there is no way to tell if a particular Table/Row/Cell is hidden.
                // Instead, if the content of a table is hidden, then all inline child nodes of the table should be
                // hidden and thus removed by previous visits as well. This will result in the container being empty
                // so if this is the case we know to remove the table node.
                //
                // Note that a table which is not hidden but simply has no content will not be affected by this algorthim,
                // as technically they are not completely empty (for example a properly formed Cell will have at least
                // an empty paragraph in it)
                if (!table.hasChildNodes()) table.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Cell node is ended in the document.
             */
            public int visitCellEnd(Cell cell)
            {
                if (!cell.hasChildNodes() && cell.getParentNode() != null) cell.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Row node is ended in the document.
             */
            public int visitRowEnd(Row row)
            {
                if (!row.hasChildNodes() && row.getParentNode() != null) row.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a SpecialCharacter is encountered in the document.
             */
            public int visitSpecialChar(SpecialChar character) throws Exception
            {
                if (isHidden(character)) character.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Returns true if the node passed is set as hidden, returns false if it is visible.
             */
            private boolean isHidden(Node node)
            {
                if (node instanceof Inline)
                {
                    // If the node is Inline then cast it to retrieve the Font property which contains the hidden property
                    Inline currentNode = (Inline) node;
                    return currentNode.getFont().getHidden();
                } else if (node.getNodeType() == NodeType.PARAGRAPH)
                {
                    // If the node is a paragraph cast it to retrieve the ParagraphBreakFont which contains the hidden property
                    Paragraph para = (Paragraph) node;
                    return para.getParagraphBreakFont().getHidden();
                } else if (node instanceof ShapeBase)
                {
                    // Node is a shape or groupshape.
                    ShapeBase shape = (ShapeBase) node;
                    return shape.getFont().getHidden();
                } else if (node instanceof InlineStory)
                {
                    // Node is a comment or footnote.
                    InlineStory inlineStory = (InlineStory) node;
                    return inlineStory.getFont().getHidden();
                }
        
                // A node that is passed to this method which does not contain a hidden property will end up here.
                // By default nodes are not hidden so return false.
                return false;
            }
        }
      • visitFormField

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

        Example:

        Implements the Visitor Pattern to remove all content formatted as hidden from the document.
        public void removeHiddenContentFromDocument() throws Exception
        {
            // Open the document we want to remove hidden content from.
            Document doc = new Document(getMyDir() + "Font.Hidden.doc");
        
            // Create an object that inherits from the DocumentVisitor class.
            RemoveHiddenContentVisitor hiddenContentRemover = new RemoveHiddenContentVisitor();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
        
            // We can run it over the entire the document like so:
            doc.accept(hiddenContentRemover);
        
            // Or we can run it on only a specific node.
            Paragraph para = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 4, true);
            para.accept(hiddenContentRemover);
        
            // Or over a different type of node like below.
            Table table = (Table) doc.getChild(NodeType.TABLE, 0, true);
            table.accept(hiddenContentRemover);
        
            doc.save(getMyDir() + "\\Artifacts\\Font.Hidden.doc");
        
        }
        
        /**
         * This class when executed will remove all hidden content from the Document. Implemented as a Visitor.
         */
        private class RemoveHiddenContentVisitor extends DocumentVisitor
        {
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart) throws Exception
            {
                // If this node is hidden, then remove it.
                if (isHidden(fieldStart)) fieldStart.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd) throws Exception
            {
                if (isHidden(fieldEnd)) fieldEnd.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator) throws Exception
            {
                if (isHidden(fieldSeparator)) fieldSeparator.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                if (isHidden(run)) run.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Paragraph node is encountered in the document.
             */
            public int visitParagraphStart(Paragraph paragraph) throws Exception
            {
                if (isHidden(paragraph)) paragraph.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FormField is encountered in the document.
             */
            public int visitFormField(FormField field) throws Exception
            {
                if (isHidden(field)) field.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a GroupShape is encountered in the document.
             */
            public int visitGroupShapeStart(GroupShape groupShape) throws Exception
            {
                if (isHidden(groupShape)) groupShape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Shape is encountered in the document.
             */
            public int visitShapeStart(Shape shape) throws Exception
            {
                if (isHidden(shape)) shape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Comment is encountered in the document.
             */
            public int visitCommentStart(Comment comment) throws Exception
            {
                if (isHidden(comment)) comment.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Footnote is encountered in the document.
             */
            public int visitFootnoteStart(Footnote footnote) throws Exception
            {
                if (isHidden(footnote)) footnote.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Table node is ended in the document.
             */
            public int visitTableEnd(Table table)
            {
                // At the moment there is no way to tell if a particular Table/Row/Cell is hidden.
                // Instead, if the content of a table is hidden, then all inline child nodes of the table should be
                // hidden and thus removed by previous visits as well. This will result in the container being empty
                // so if this is the case we know to remove the table node.
                //
                // Note that a table which is not hidden but simply has no content will not be affected by this algorthim,
                // as technically they are not completely empty (for example a properly formed Cell will have at least
                // an empty paragraph in it)
                if (!table.hasChildNodes()) table.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Cell node is ended in the document.
             */
            public int visitCellEnd(Cell cell)
            {
                if (!cell.hasChildNodes() && cell.getParentNode() != null) cell.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Row node is ended in the document.
             */
            public int visitRowEnd(Row row)
            {
                if (!row.hasChildNodes() && row.getParentNode() != null) row.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a SpecialCharacter is encountered in the document.
             */
            public int visitSpecialChar(SpecialChar character) throws Exception
            {
                if (isHidden(character)) character.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Returns true if the node passed is set as hidden, returns false if it is visible.
             */
            private boolean isHidden(Node node)
            {
                if (node instanceof Inline)
                {
                    // If the node is Inline then cast it to retrieve the Font property which contains the hidden property
                    Inline currentNode = (Inline) node;
                    return currentNode.getFont().getHidden();
                } else if (node.getNodeType() == NodeType.PARAGRAPH)
                {
                    // If the node is a paragraph cast it to retrieve the ParagraphBreakFont which contains the hidden property
                    Paragraph para = (Paragraph) node;
                    return para.getParagraphBreakFont().getHidden();
                } else if (node instanceof ShapeBase)
                {
                    // Node is a shape or groupshape.
                    ShapeBase shape = (ShapeBase) node;
                    return shape.getFont().getHidden();
                } else if (node instanceof InlineStory)
                {
                    // Node is a comment or footnote.
                    InlineStory inlineStory = (InlineStory) node;
                    return inlineStory.getFont().getHidden();
                }
        
                // A node that is passed to this method which does not contain a hidden property will end up here.
                // By default nodes are not hidden so return false.
                return false;
            }
        }
      • 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.

        Example:

        Implements the Visitor Pattern to remove all content formatted as hidden from the document.
        public void removeHiddenContentFromDocument() throws Exception
        {
            // Open the document we want to remove hidden content from.
            Document doc = new Document(getMyDir() + "Font.Hidden.doc");
        
            // Create an object that inherits from the DocumentVisitor class.
            RemoveHiddenContentVisitor hiddenContentRemover = new RemoveHiddenContentVisitor();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
        
            // We can run it over the entire the document like so:
            doc.accept(hiddenContentRemover);
        
            // Or we can run it on only a specific node.
            Paragraph para = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 4, true);
            para.accept(hiddenContentRemover);
        
            // Or over a different type of node like below.
            Table table = (Table) doc.getChild(NodeType.TABLE, 0, true);
            table.accept(hiddenContentRemover);
        
            doc.save(getMyDir() + "\\Artifacts\\Font.Hidden.doc");
        
        }
        
        /**
         * This class when executed will remove all hidden content from the Document. Implemented as a Visitor.
         */
        private class RemoveHiddenContentVisitor extends DocumentVisitor
        {
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart) throws Exception
            {
                // If this node is hidden, then remove it.
                if (isHidden(fieldStart)) fieldStart.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd) throws Exception
            {
                if (isHidden(fieldEnd)) fieldEnd.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator) throws Exception
            {
                if (isHidden(fieldSeparator)) fieldSeparator.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                if (isHidden(run)) run.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Paragraph node is encountered in the document.
             */
            public int visitParagraphStart(Paragraph paragraph) throws Exception
            {
                if (isHidden(paragraph)) paragraph.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FormField is encountered in the document.
             */
            public int visitFormField(FormField field) throws Exception
            {
                if (isHidden(field)) field.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a GroupShape is encountered in the document.
             */
            public int visitGroupShapeStart(GroupShape groupShape) throws Exception
            {
                if (isHidden(groupShape)) groupShape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Shape is encountered in the document.
             */
            public int visitShapeStart(Shape shape) throws Exception
            {
                if (isHidden(shape)) shape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Comment is encountered in the document.
             */
            public int visitCommentStart(Comment comment) throws Exception
            {
                if (isHidden(comment)) comment.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Footnote is encountered in the document.
             */
            public int visitFootnoteStart(Footnote footnote) throws Exception
            {
                if (isHidden(footnote)) footnote.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Table node is ended in the document.
             */
            public int visitTableEnd(Table table)
            {
                // At the moment there is no way to tell if a particular Table/Row/Cell is hidden.
                // Instead, if the content of a table is hidden, then all inline child nodes of the table should be
                // hidden and thus removed by previous visits as well. This will result in the container being empty
                // so if this is the case we know to remove the table node.
                //
                // Note that a table which is not hidden but simply has no content will not be affected by this algorthim,
                // as technically they are not completely empty (for example a properly formed Cell will have at least
                // an empty paragraph in it)
                if (!table.hasChildNodes()) table.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Cell node is ended in the document.
             */
            public int visitCellEnd(Cell cell)
            {
                if (!cell.hasChildNodes() && cell.getParentNode() != null) cell.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Row node is ended in the document.
             */
            public int visitRowEnd(Row row)
            {
                if (!row.hasChildNodes() && row.getParentNode() != null) row.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a SpecialCharacter is encountered in the document.
             */
            public int visitSpecialChar(SpecialChar character) throws Exception
            {
                if (isHidden(character)) character.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Returns true if the node passed is set as hidden, returns false if it is visible.
             */
            private boolean isHidden(Node node)
            {
                if (node instanceof Inline)
                {
                    // If the node is Inline then cast it to retrieve the Font property which contains the hidden property
                    Inline currentNode = (Inline) node;
                    return currentNode.getFont().getHidden();
                } else if (node.getNodeType() == NodeType.PARAGRAPH)
                {
                    // If the node is a paragraph cast it to retrieve the ParagraphBreakFont which contains the hidden property
                    Paragraph para = (Paragraph) node;
                    return para.getParagraphBreakFont().getHidden();
                } else if (node instanceof ShapeBase)
                {
                    // Node is a shape or groupshape.
                    ShapeBase shape = (ShapeBase) node;
                    return shape.getFont().getHidden();
                } else if (node instanceof InlineStory)
                {
                    // Node is a comment or footnote.
                    InlineStory inlineStory = (InlineStory) node;
                    return inlineStory.getFont().getHidden();
                }
        
                // A node that is passed to this method which does not contain a hidden property will end up here.
                // By default nodes are not hidden so return false.
                return false;
            }
        }
      • 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.

        Example:

        Shows how to use the Visitor pattern to add new operations to the Aspose.Words object model. In this case we create a simple document converter into a text format.
        public void toText() throws Exception
        {
            // Open the document we want to convert.
            Document doc = new Document(getMyDir() + "DocumentVisitor.Destination.docx");
        
            // Create an object that inherits from the DocumentVisitor class.
            MyDocToTxtWriter myConverter = new MyDocToTxtWriter();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
            //
            // Note that every node in the object model has the Accept method so the visiting
            // can be executed not only for the whole document, but for any node in the document.
            doc.accept(myConverter);
        
            // Once the visiting is complete, we can retrieve the result of the operation,
            // that in this example, has accumulated in the visitor.
            System.out.println(myConverter.getText());
        }
        
        /**
         * Simple implementation of saving a document in the plain text format. Implemented as a Visitor.
         */
        public class MyDocToTxtWriter extends DocumentVisitor
        {
            public MyDocToTxtWriter()
            {
                mIsSkipText = false;
                mBuilder = new StringBuilder();
            }
        
            /**
             * Gets the plain text of the document that was accumulated by the visitor.
             */
            public String getText()
            {
                return mBuilder.toString();
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                appendText(run.getText());
        
                // Let the visitor continue visiting other nodes.
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart)
            {
                // In Microsoft Word, a field code (such as "MERGEFIELD FieldName") follows
                // after a field start character. We want to skip field codes and output field
                // result only, therefore we use a flag to suspend the output while inside a field code.
                //
                // Note this is a very simplistic implementation and will not work very well
                // if you have nested fields in a document.
                mIsSkipText = true;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator)
            {
                // Once reached a field separator node, we enable the output because we are
                // now entering the field result nodes.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd)
            {
                // Make sure we enable the output when reached a field end because some fields
                // do not have field separator and do not have field result.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Paragraph node is ended in the document.
             */
            public int visitParagraphEnd(Paragraph paragraph) throws Exception
            {
                // When outputting to plain text we output Cr+Lf characters.
                appendText(ControlChar.CR_LF);
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyStart(Body body)
            {
                // We can detect beginning and end of all composite nodes such as Section, Body,
                // Table, Paragraph etc and provide custom handling for them.
                mBuilder.append("*** Body Started ***\r\n");
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyEnd(Body body)
            {
                mBuilder.append("*** Body Ended ***\r\n");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a HeaderFooter node is encountered in the document.
             */
            public int visitHeaderFooterStart(HeaderFooter headerFooter)
            {
                // Returning this value from a visitor method causes visiting of this
                // node to stop and move on to visiting the next sibling node.
                // The net effect in this example is that the text of headers and footers
                // is not included in the resulting output.
                return VisitorAction.SKIP_THIS_NODE;
            }
        
            /**
             * Called when an AbsolutePositionTab is encountered in the document.
             */
            public int visitAbsolutePositionTab(AbsolutePositionTab tab)
            {
                mBuilder.append("\t");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkStart is encountered in the document.
             */
            public int visitBookmarkStart(BookmarkStart bookmarkStart)
            {
                mBuilder.append("[");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkEnd is encountered in the document.
             */
            public int visitBookmarkEnd(BookmarkEnd bookmarkEnd)
            {
                mBuilder.append("]");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Adds text to the current output. Honours the enabled/disabled output flag.
             */
            private void appendText(String text)
            {
                if (!mIsSkipText) mBuilder.append(text);
            }
        
            private final StringBuilder mBuilder;
            private boolean mIsSkipText;
        }
      • visitOfficeMathEnd

        public int visitOfficeMathEnd(OfficeMath officeMath)
                              throws java.lang.Exception
        Called when enumeration of a Office Math object has ended.
        Parameters:
        officeMath - The object that is being visited.
        Returns:
        A VisitorAction value that specifies how to continue the enumeration.
      • visitOfficeMathStart

        public int visitOfficeMathStart(OfficeMath officeMath)
                                throws java.lang.Exception
        Called when enumeration of a Office Math object has started.
        Parameters:
        officeMath - 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.

        Example:

        Shows how to use the Visitor pattern to add new operations to the Aspose.Words object model. In this case we create a simple document converter into a text format.
        public void toText() throws Exception
        {
            // Open the document we want to convert.
            Document doc = new Document(getMyDir() + "DocumentVisitor.Destination.docx");
        
            // Create an object that inherits from the DocumentVisitor class.
            MyDocToTxtWriter myConverter = new MyDocToTxtWriter();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
            //
            // Note that every node in the object model has the Accept method so the visiting
            // can be executed not only for the whole document, but for any node in the document.
            doc.accept(myConverter);
        
            // Once the visiting is complete, we can retrieve the result of the operation,
            // that in this example, has accumulated in the visitor.
            System.out.println(myConverter.getText());
        }
        
        /**
         * Simple implementation of saving a document in the plain text format. Implemented as a Visitor.
         */
        public class MyDocToTxtWriter extends DocumentVisitor
        {
            public MyDocToTxtWriter()
            {
                mIsSkipText = false;
                mBuilder = new StringBuilder();
            }
        
            /**
             * Gets the plain text of the document that was accumulated by the visitor.
             */
            public String getText()
            {
                return mBuilder.toString();
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                appendText(run.getText());
        
                // Let the visitor continue visiting other nodes.
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart)
            {
                // In Microsoft Word, a field code (such as "MERGEFIELD FieldName") follows
                // after a field start character. We want to skip field codes and output field
                // result only, therefore we use a flag to suspend the output while inside a field code.
                //
                // Note this is a very simplistic implementation and will not work very well
                // if you have nested fields in a document.
                mIsSkipText = true;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator)
            {
                // Once reached a field separator node, we enable the output because we are
                // now entering the field result nodes.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd)
            {
                // Make sure we enable the output when reached a field end because some fields
                // do not have field separator and do not have field result.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Paragraph node is ended in the document.
             */
            public int visitParagraphEnd(Paragraph paragraph) throws Exception
            {
                // When outputting to plain text we output Cr+Lf characters.
                appendText(ControlChar.CR_LF);
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyStart(Body body)
            {
                // We can detect beginning and end of all composite nodes such as Section, Body,
                // Table, Paragraph etc and provide custom handling for them.
                mBuilder.append("*** Body Started ***\r\n");
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyEnd(Body body)
            {
                mBuilder.append("*** Body Ended ***\r\n");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a HeaderFooter node is encountered in the document.
             */
            public int visitHeaderFooterStart(HeaderFooter headerFooter)
            {
                // Returning this value from a visitor method causes visiting of this
                // node to stop and move on to visiting the next sibling node.
                // The net effect in this example is that the text of headers and footers
                // is not included in the resulting output.
                return VisitorAction.SKIP_THIS_NODE;
            }
        
            /**
             * Called when an AbsolutePositionTab is encountered in the document.
             */
            public int visitAbsolutePositionTab(AbsolutePositionTab tab)
            {
                mBuilder.append("\t");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkStart is encountered in the document.
             */
            public int visitBookmarkStart(BookmarkStart bookmarkStart)
            {
                mBuilder.append("[");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkEnd is encountered in the document.
             */
            public int visitBookmarkEnd(BookmarkEnd bookmarkEnd)
            {
                mBuilder.append("]");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Adds text to the current output. Honours the enabled/disabled output flag.
             */
            private void appendText(String text)
            {
                if (!mIsSkipText) mBuilder.append(text);
            }
        
            private final StringBuilder mBuilder;
            private boolean mIsSkipText;
        }
      • 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.

        Example:

        Implements the Visitor Pattern to remove all content formatted as hidden from the document.
        public void removeHiddenContentFromDocument() throws Exception
        {
            // Open the document we want to remove hidden content from.
            Document doc = new Document(getMyDir() + "Font.Hidden.doc");
        
            // Create an object that inherits from the DocumentVisitor class.
            RemoveHiddenContentVisitor hiddenContentRemover = new RemoveHiddenContentVisitor();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
        
            // We can run it over the entire the document like so:
            doc.accept(hiddenContentRemover);
        
            // Or we can run it on only a specific node.
            Paragraph para = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 4, true);
            para.accept(hiddenContentRemover);
        
            // Or over a different type of node like below.
            Table table = (Table) doc.getChild(NodeType.TABLE, 0, true);
            table.accept(hiddenContentRemover);
        
            doc.save(getMyDir() + "\\Artifacts\\Font.Hidden.doc");
        
        }
        
        /**
         * This class when executed will remove all hidden content from the Document. Implemented as a Visitor.
         */
        private class RemoveHiddenContentVisitor extends DocumentVisitor
        {
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart) throws Exception
            {
                // If this node is hidden, then remove it.
                if (isHidden(fieldStart)) fieldStart.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd) throws Exception
            {
                if (isHidden(fieldEnd)) fieldEnd.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator) throws Exception
            {
                if (isHidden(fieldSeparator)) fieldSeparator.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                if (isHidden(run)) run.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Paragraph node is encountered in the document.
             */
            public int visitParagraphStart(Paragraph paragraph) throws Exception
            {
                if (isHidden(paragraph)) paragraph.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FormField is encountered in the document.
             */
            public int visitFormField(FormField field) throws Exception
            {
                if (isHidden(field)) field.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a GroupShape is encountered in the document.
             */
            public int visitGroupShapeStart(GroupShape groupShape) throws Exception
            {
                if (isHidden(groupShape)) groupShape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Shape is encountered in the document.
             */
            public int visitShapeStart(Shape shape) throws Exception
            {
                if (isHidden(shape)) shape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Comment is encountered in the document.
             */
            public int visitCommentStart(Comment comment) throws Exception
            {
                if (isHidden(comment)) comment.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Footnote is encountered in the document.
             */
            public int visitFootnoteStart(Footnote footnote) throws Exception
            {
                if (isHidden(footnote)) footnote.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Table node is ended in the document.
             */
            public int visitTableEnd(Table table)
            {
                // At the moment there is no way to tell if a particular Table/Row/Cell is hidden.
                // Instead, if the content of a table is hidden, then all inline child nodes of the table should be
                // hidden and thus removed by previous visits as well. This will result in the container being empty
                // so if this is the case we know to remove the table node.
                //
                // Note that a table which is not hidden but simply has no content will not be affected by this algorthim,
                // as technically they are not completely empty (for example a properly formed Cell will have at least
                // an empty paragraph in it)
                if (!table.hasChildNodes()) table.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Cell node is ended in the document.
             */
            public int visitCellEnd(Cell cell)
            {
                if (!cell.hasChildNodes() && cell.getParentNode() != null) cell.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Row node is ended in the document.
             */
            public int visitRowEnd(Row row)
            {
                if (!row.hasChildNodes() && row.getParentNode() != null) row.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a SpecialCharacter is encountered in the document.
             */
            public int visitSpecialChar(SpecialChar character) throws Exception
            {
                if (isHidden(character)) character.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Returns true if the node passed is set as hidden, returns false if it is visible.
             */
            private boolean isHidden(Node node)
            {
                if (node instanceof Inline)
                {
                    // If the node is Inline then cast it to retrieve the Font property which contains the hidden property
                    Inline currentNode = (Inline) node;
                    return currentNode.getFont().getHidden();
                } else if (node.getNodeType() == NodeType.PARAGRAPH)
                {
                    // If the node is a paragraph cast it to retrieve the ParagraphBreakFont which contains the hidden property
                    Paragraph para = (Paragraph) node;
                    return para.getParagraphBreakFont().getHidden();
                } else if (node instanceof ShapeBase)
                {
                    // Node is a shape or groupshape.
                    ShapeBase shape = (ShapeBase) node;
                    return shape.getFont().getHidden();
                } else if (node instanceof InlineStory)
                {
                    // Node is a comment or footnote.
                    InlineStory inlineStory = (InlineStory) node;
                    return inlineStory.getFont().getHidden();
                }
        
                // A node that is passed to this method which does not contain a hidden property will end up here.
                // By default nodes are not hidden so return false.
                return false;
            }
        }
      • visitRowEnd

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

        Example:

        Implements the Visitor Pattern to remove all content formatted as hidden from the document.
        public void removeHiddenContentFromDocument() throws Exception
        {
            // Open the document we want to remove hidden content from.
            Document doc = new Document(getMyDir() + "Font.Hidden.doc");
        
            // Create an object that inherits from the DocumentVisitor class.
            RemoveHiddenContentVisitor hiddenContentRemover = new RemoveHiddenContentVisitor();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
        
            // We can run it over the entire the document like so:
            doc.accept(hiddenContentRemover);
        
            // Or we can run it on only a specific node.
            Paragraph para = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 4, true);
            para.accept(hiddenContentRemover);
        
            // Or over a different type of node like below.
            Table table = (Table) doc.getChild(NodeType.TABLE, 0, true);
            table.accept(hiddenContentRemover);
        
            doc.save(getMyDir() + "\\Artifacts\\Font.Hidden.doc");
        
        }
        
        /**
         * This class when executed will remove all hidden content from the Document. Implemented as a Visitor.
         */
        private class RemoveHiddenContentVisitor extends DocumentVisitor
        {
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart) throws Exception
            {
                // If this node is hidden, then remove it.
                if (isHidden(fieldStart)) fieldStart.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd) throws Exception
            {
                if (isHidden(fieldEnd)) fieldEnd.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator) throws Exception
            {
                if (isHidden(fieldSeparator)) fieldSeparator.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                if (isHidden(run)) run.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Paragraph node is encountered in the document.
             */
            public int visitParagraphStart(Paragraph paragraph) throws Exception
            {
                if (isHidden(paragraph)) paragraph.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FormField is encountered in the document.
             */
            public int visitFormField(FormField field) throws Exception
            {
                if (isHidden(field)) field.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a GroupShape is encountered in the document.
             */
            public int visitGroupShapeStart(GroupShape groupShape) throws Exception
            {
                if (isHidden(groupShape)) groupShape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Shape is encountered in the document.
             */
            public int visitShapeStart(Shape shape) throws Exception
            {
                if (isHidden(shape)) shape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Comment is encountered in the document.
             */
            public int visitCommentStart(Comment comment) throws Exception
            {
                if (isHidden(comment)) comment.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Footnote is encountered in the document.
             */
            public int visitFootnoteStart(Footnote footnote) throws Exception
            {
                if (isHidden(footnote)) footnote.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Table node is ended in the document.
             */
            public int visitTableEnd(Table table)
            {
                // At the moment there is no way to tell if a particular Table/Row/Cell is hidden.
                // Instead, if the content of a table is hidden, then all inline child nodes of the table should be
                // hidden and thus removed by previous visits as well. This will result in the container being empty
                // so if this is the case we know to remove the table node.
                //
                // Note that a table which is not hidden but simply has no content will not be affected by this algorthim,
                // as technically they are not completely empty (for example a properly formed Cell will have at least
                // an empty paragraph in it)
                if (!table.hasChildNodes()) table.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Cell node is ended in the document.
             */
            public int visitCellEnd(Cell cell)
            {
                if (!cell.hasChildNodes() && cell.getParentNode() != null) cell.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Row node is ended in the document.
             */
            public int visitRowEnd(Row row)
            {
                if (!row.hasChildNodes() && row.getParentNode() != null) row.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a SpecialCharacter is encountered in the document.
             */
            public int visitSpecialChar(SpecialChar character) throws Exception
            {
                if (isHidden(character)) character.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Returns true if the node passed is set as hidden, returns false if it is visible.
             */
            private boolean isHidden(Node node)
            {
                if (node instanceof Inline)
                {
                    // If the node is Inline then cast it to retrieve the Font property which contains the hidden property
                    Inline currentNode = (Inline) node;
                    return currentNode.getFont().getHidden();
                } else if (node.getNodeType() == NodeType.PARAGRAPH)
                {
                    // If the node is a paragraph cast it to retrieve the ParagraphBreakFont which contains the hidden property
                    Paragraph para = (Paragraph) node;
                    return para.getParagraphBreakFont().getHidden();
                } else if (node instanceof ShapeBase)
                {
                    // Node is a shape or groupshape.
                    ShapeBase shape = (ShapeBase) node;
                    return shape.getFont().getHidden();
                } else if (node instanceof InlineStory)
                {
                    // Node is a comment or footnote.
                    InlineStory inlineStory = (InlineStory) node;
                    return inlineStory.getFont().getHidden();
                }
        
                // A node that is passed to this method which does not contain a hidden property will end up here.
                // By default nodes are not hidden so return false.
                return false;
            }
        }
      • visitRowStart

        public int visitRowStart(Row row)
                         throws java.lang.Exception
        Called when enumeration of a table row has started.
        Parameters:
        row - 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.

        Example:

        Shows how to use the Visitor pattern to add new operations to the Aspose.Words object model. In this case we create a simple document converter into a text format.
        public void toText() throws Exception
        {
            // Open the document we want to convert.
            Document doc = new Document(getMyDir() + "DocumentVisitor.Destination.docx");
        
            // Create an object that inherits from the DocumentVisitor class.
            MyDocToTxtWriter myConverter = new MyDocToTxtWriter();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
            //
            // Note that every node in the object model has the Accept method so the visiting
            // can be executed not only for the whole document, but for any node in the document.
            doc.accept(myConverter);
        
            // Once the visiting is complete, we can retrieve the result of the operation,
            // that in this example, has accumulated in the visitor.
            System.out.println(myConverter.getText());
        }
        
        /**
         * Simple implementation of saving a document in the plain text format. Implemented as a Visitor.
         */
        public class MyDocToTxtWriter extends DocumentVisitor
        {
            public MyDocToTxtWriter()
            {
                mIsSkipText = false;
                mBuilder = new StringBuilder();
            }
        
            /**
             * Gets the plain text of the document that was accumulated by the visitor.
             */
            public String getText()
            {
                return mBuilder.toString();
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                appendText(run.getText());
        
                // Let the visitor continue visiting other nodes.
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart)
            {
                // In Microsoft Word, a field code (such as "MERGEFIELD FieldName") follows
                // after a field start character. We want to skip field codes and output field
                // result only, therefore we use a flag to suspend the output while inside a field code.
                //
                // Note this is a very simplistic implementation and will not work very well
                // if you have nested fields in a document.
                mIsSkipText = true;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator)
            {
                // Once reached a field separator node, we enable the output because we are
                // now entering the field result nodes.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd)
            {
                // Make sure we enable the output when reached a field end because some fields
                // do not have field separator and do not have field result.
                mIsSkipText = false;
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Paragraph node is ended in the document.
             */
            public int visitParagraphEnd(Paragraph paragraph) throws Exception
            {
                // When outputting to plain text we output Cr+Lf characters.
                appendText(ControlChar.CR_LF);
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyStart(Body body)
            {
                // We can detect beginning and end of all composite nodes such as Section, Body,
                // Table, Paragraph etc and provide custom handling for them.
                mBuilder.append("*** Body Started ***\r\n");
        
                return VisitorAction.CONTINUE;
            }
        
            public int visitBodyEnd(Body body)
            {
                mBuilder.append("*** Body Ended ***\r\n");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a HeaderFooter node is encountered in the document.
             */
            public int visitHeaderFooterStart(HeaderFooter headerFooter)
            {
                // Returning this value from a visitor method causes visiting of this
                // node to stop and move on to visiting the next sibling node.
                // The net effect in this example is that the text of headers and footers
                // is not included in the resulting output.
                return VisitorAction.SKIP_THIS_NODE;
            }
        
            /**
             * Called when an AbsolutePositionTab is encountered in the document.
             */
            public int visitAbsolutePositionTab(AbsolutePositionTab tab)
            {
                mBuilder.append("\t");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkStart is encountered in the document.
             */
            public int visitBookmarkStart(BookmarkStart bookmarkStart)
            {
                mBuilder.append("[");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a BookmarkEnd is encountered in the document.
             */
            public int visitBookmarkEnd(BookmarkEnd bookmarkEnd)
            {
                mBuilder.append("]");
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Adds text to the current output. Honours the enabled/disabled output flag.
             */
            private void appendText(String text)
            {
                if (!mIsSkipText) mBuilder.append(text);
            }
        
            private final StringBuilder mBuilder;
            private boolean mIsSkipText;
        }
      • 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.

        Example:

        Implements the Visitor Pattern to remove all content formatted as hidden from the document.
        public void removeHiddenContentFromDocument() throws Exception
        {
            // Open the document we want to remove hidden content from.
            Document doc = new Document(getMyDir() + "Font.Hidden.doc");
        
            // Create an object that inherits from the DocumentVisitor class.
            RemoveHiddenContentVisitor hiddenContentRemover = new RemoveHiddenContentVisitor();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
        
            // We can run it over the entire the document like so:
            doc.accept(hiddenContentRemover);
        
            // Or we can run it on only a specific node.
            Paragraph para = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 4, true);
            para.accept(hiddenContentRemover);
        
            // Or over a different type of node like below.
            Table table = (Table) doc.getChild(NodeType.TABLE, 0, true);
            table.accept(hiddenContentRemover);
        
            doc.save(getMyDir() + "\\Artifacts\\Font.Hidden.doc");
        
        }
        
        /**
         * This class when executed will remove all hidden content from the Document. Implemented as a Visitor.
         */
        private class RemoveHiddenContentVisitor extends DocumentVisitor
        {
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart) throws Exception
            {
                // If this node is hidden, then remove it.
                if (isHidden(fieldStart)) fieldStart.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd) throws Exception
            {
                if (isHidden(fieldEnd)) fieldEnd.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator) throws Exception
            {
                if (isHidden(fieldSeparator)) fieldSeparator.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                if (isHidden(run)) run.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Paragraph node is encountered in the document.
             */
            public int visitParagraphStart(Paragraph paragraph) throws Exception
            {
                if (isHidden(paragraph)) paragraph.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FormField is encountered in the document.
             */
            public int visitFormField(FormField field) throws Exception
            {
                if (isHidden(field)) field.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a GroupShape is encountered in the document.
             */
            public int visitGroupShapeStart(GroupShape groupShape) throws Exception
            {
                if (isHidden(groupShape)) groupShape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Shape is encountered in the document.
             */
            public int visitShapeStart(Shape shape) throws Exception
            {
                if (isHidden(shape)) shape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Comment is encountered in the document.
             */
            public int visitCommentStart(Comment comment) throws Exception
            {
                if (isHidden(comment)) comment.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Footnote is encountered in the document.
             */
            public int visitFootnoteStart(Footnote footnote) throws Exception
            {
                if (isHidden(footnote)) footnote.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Table node is ended in the document.
             */
            public int visitTableEnd(Table table)
            {
                // At the moment there is no way to tell if a particular Table/Row/Cell is hidden.
                // Instead, if the content of a table is hidden, then all inline child nodes of the table should be
                // hidden and thus removed by previous visits as well. This will result in the container being empty
                // so if this is the case we know to remove the table node.
                //
                // Note that a table which is not hidden but simply has no content will not be affected by this algorthim,
                // as technically they are not completely empty (for example a properly formed Cell will have at least
                // an empty paragraph in it)
                if (!table.hasChildNodes()) table.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Cell node is ended in the document.
             */
            public int visitCellEnd(Cell cell)
            {
                if (!cell.hasChildNodes() && cell.getParentNode() != null) cell.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Row node is ended in the document.
             */
            public int visitRowEnd(Row row)
            {
                if (!row.hasChildNodes() && row.getParentNode() != null) row.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a SpecialCharacter is encountered in the document.
             */
            public int visitSpecialChar(SpecialChar character) throws Exception
            {
                if (isHidden(character)) character.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Returns true if the node passed is set as hidden, returns false if it is visible.
             */
            private boolean isHidden(Node node)
            {
                if (node instanceof Inline)
                {
                    // If the node is Inline then cast it to retrieve the Font property which contains the hidden property
                    Inline currentNode = (Inline) node;
                    return currentNode.getFont().getHidden();
                } else if (node.getNodeType() == NodeType.PARAGRAPH)
                {
                    // If the node is a paragraph cast it to retrieve the ParagraphBreakFont which contains the hidden property
                    Paragraph para = (Paragraph) node;
                    return para.getParagraphBreakFont().getHidden();
                } else if (node instanceof ShapeBase)
                {
                    // Node is a shape or groupshape.
                    ShapeBase shape = (ShapeBase) node;
                    return shape.getFont().getHidden();
                } else if (node instanceof InlineStory)
                {
                    // Node is a comment or footnote.
                    InlineStory inlineStory = (InlineStory) node;
                    return inlineStory.getFont().getHidden();
                }
        
                // A node that is passed to this method which does not contain a hidden property will end up here.
                // By default nodes are not hidden so return false.
                return false;
            }
        }
      • visitSmartTagEnd

        public int visitSmartTagEnd(SmartTag smartTag)
                            throws java.lang.Exception
        Called when enumeration of a smart tag has ended.
        Parameters:
        smartTag - The object that is being visited.
        Returns:
        A VisitorAction value that specifies how to continue the enumeration.
      • visitSmartTagStart

        public int visitSmartTagStart(SmartTag smartTag)
                              throws java.lang.Exception
        Called when enumeration of a smart tag has started.
        Parameters:
        smartTag - 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.

        Example:

        Implements the Visitor Pattern to remove all content formatted as hidden from the document.
        public void removeHiddenContentFromDocument() throws Exception
        {
            // Open the document we want to remove hidden content from.
            Document doc = new Document(getMyDir() + "Font.Hidden.doc");
        
            // Create an object that inherits from the DocumentVisitor class.
            RemoveHiddenContentVisitor hiddenContentRemover = new RemoveHiddenContentVisitor();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
        
            // We can run it over the entire the document like so:
            doc.accept(hiddenContentRemover);
        
            // Or we can run it on only a specific node.
            Paragraph para = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 4, true);
            para.accept(hiddenContentRemover);
        
            // Or over a different type of node like below.
            Table table = (Table) doc.getChild(NodeType.TABLE, 0, true);
            table.accept(hiddenContentRemover);
        
            doc.save(getMyDir() + "\\Artifacts\\Font.Hidden.doc");
        
        }
        
        /**
         * This class when executed will remove all hidden content from the Document. Implemented as a Visitor.
         */
        private class RemoveHiddenContentVisitor extends DocumentVisitor
        {
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart) throws Exception
            {
                // If this node is hidden, then remove it.
                if (isHidden(fieldStart)) fieldStart.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd) throws Exception
            {
                if (isHidden(fieldEnd)) fieldEnd.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator) throws Exception
            {
                if (isHidden(fieldSeparator)) fieldSeparator.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                if (isHidden(run)) run.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Paragraph node is encountered in the document.
             */
            public int visitParagraphStart(Paragraph paragraph) throws Exception
            {
                if (isHidden(paragraph)) paragraph.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FormField is encountered in the document.
             */
            public int visitFormField(FormField field) throws Exception
            {
                if (isHidden(field)) field.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a GroupShape is encountered in the document.
             */
            public int visitGroupShapeStart(GroupShape groupShape) throws Exception
            {
                if (isHidden(groupShape)) groupShape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Shape is encountered in the document.
             */
            public int visitShapeStart(Shape shape) throws Exception
            {
                if (isHidden(shape)) shape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Comment is encountered in the document.
             */
            public int visitCommentStart(Comment comment) throws Exception
            {
                if (isHidden(comment)) comment.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Footnote is encountered in the document.
             */
            public int visitFootnoteStart(Footnote footnote) throws Exception
            {
                if (isHidden(footnote)) footnote.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Table node is ended in the document.
             */
            public int visitTableEnd(Table table)
            {
                // At the moment there is no way to tell if a particular Table/Row/Cell is hidden.
                // Instead, if the content of a table is hidden, then all inline child nodes of the table should be
                // hidden and thus removed by previous visits as well. This will result in the container being empty
                // so if this is the case we know to remove the table node.
                //
                // Note that a table which is not hidden but simply has no content will not be affected by this algorthim,
                // as technically they are not completely empty (for example a properly formed Cell will have at least
                // an empty paragraph in it)
                if (!table.hasChildNodes()) table.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Cell node is ended in the document.
             */
            public int visitCellEnd(Cell cell)
            {
                if (!cell.hasChildNodes() && cell.getParentNode() != null) cell.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Row node is ended in the document.
             */
            public int visitRowEnd(Row row)
            {
                if (!row.hasChildNodes() && row.getParentNode() != null) row.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a SpecialCharacter is encountered in the document.
             */
            public int visitSpecialChar(SpecialChar character) throws Exception
            {
                if (isHidden(character)) character.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Returns true if the node passed is set as hidden, returns false if it is visible.
             */
            private boolean isHidden(Node node)
            {
                if (node instanceof Inline)
                {
                    // If the node is Inline then cast it to retrieve the Font property which contains the hidden property
                    Inline currentNode = (Inline) node;
                    return currentNode.getFont().getHidden();
                } else if (node.getNodeType() == NodeType.PARAGRAPH)
                {
                    // If the node is a paragraph cast it to retrieve the ParagraphBreakFont which contains the hidden property
                    Paragraph para = (Paragraph) node;
                    return para.getParagraphBreakFont().getHidden();
                } else if (node instanceof ShapeBase)
                {
                    // Node is a shape or groupshape.
                    ShapeBase shape = (ShapeBase) node;
                    return shape.getFont().getHidden();
                } else if (node instanceof InlineStory)
                {
                    // Node is a comment or footnote.
                    InlineStory inlineStory = (InlineStory) node;
                    return inlineStory.getFont().getHidden();
                }
        
                // A node that is passed to this method which does not contain a hidden property will end up here.
                // By default nodes are not hidden so return false.
                return false;
            }
        }
      • visitStructuredDocumentTagEnd

        public int visitStructuredDocumentTagEnd(StructuredDocumentTag sdt)
                                         throws java.lang.Exception
        Called when enumeration of a structured document tag has ended.
        Parameters:
        sdt - The object that is being visited.
        Returns:
        A VisitorAction value that specifies how to continue the enumeration.
      • visitStructuredDocumentTagStart

        public int visitStructuredDocumentTagStart(StructuredDocumentTag sdt)
                                           throws java.lang.Exception
        Called when enumeration of a structured document tag has started.
        Parameters:
        sdt - 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.
      • visitTableEnd

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

        Example:

        Implements the Visitor Pattern to remove all content formatted as hidden from the document.
        public void removeHiddenContentFromDocument() throws Exception
        {
            // Open the document we want to remove hidden content from.
            Document doc = new Document(getMyDir() + "Font.Hidden.doc");
        
            // Create an object that inherits from the DocumentVisitor class.
            RemoveHiddenContentVisitor hiddenContentRemover = new RemoveHiddenContentVisitor();
        
            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).
        
            // We can run it over the entire the document like so:
            doc.accept(hiddenContentRemover);
        
            // Or we can run it on only a specific node.
            Paragraph para = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 4, true);
            para.accept(hiddenContentRemover);
        
            // Or over a different type of node like below.
            Table table = (Table) doc.getChild(NodeType.TABLE, 0, true);
            table.accept(hiddenContentRemover);
        
            doc.save(getMyDir() + "\\Artifacts\\Font.Hidden.doc");
        
        }
        
        /**
         * This class when executed will remove all hidden content from the Document. Implemented as a Visitor.
         */
        private class RemoveHiddenContentVisitor extends DocumentVisitor
        {
            /**
             * Called when a FieldStart node is encountered in the document.
             */
            public int visitFieldStart(FieldStart fieldStart) throws Exception
            {
                // If this node is hidden, then remove it.
                if (isHidden(fieldStart)) fieldStart.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldEnd node is encountered in the document.
             */
            public int visitFieldEnd(FieldEnd fieldEnd) throws Exception
            {
                if (isHidden(fieldEnd)) fieldEnd.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FieldSeparator node is encountered in the document.
             */
            public int visitFieldSeparator(FieldSeparator fieldSeparator) throws Exception
            {
                if (isHidden(fieldSeparator)) fieldSeparator.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Run node is encountered in the document.
             */
            public int visitRun(Run run) throws Exception
            {
                if (isHidden(run)) run.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Paragraph node is encountered in the document.
             */
            public int visitParagraphStart(Paragraph paragraph) throws Exception
            {
                if (isHidden(paragraph)) paragraph.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a FormField is encountered in the document.
             */
            public int visitFormField(FormField field) throws Exception
            {
                if (isHidden(field)) field.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a GroupShape is encountered in the document.
             */
            public int visitGroupShapeStart(GroupShape groupShape) throws Exception
            {
                if (isHidden(groupShape)) groupShape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Shape is encountered in the document.
             */
            public int visitShapeStart(Shape shape) throws Exception
            {
                if (isHidden(shape)) shape.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Comment is encountered in the document.
             */
            public int visitCommentStart(Comment comment) throws Exception
            {
                if (isHidden(comment)) comment.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a Footnote is encountered in the document.
             */
            public int visitFootnoteStart(Footnote footnote) throws Exception
            {
                if (isHidden(footnote)) footnote.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Table node is ended in the document.
             */
            public int visitTableEnd(Table table)
            {
                // At the moment there is no way to tell if a particular Table/Row/Cell is hidden.
                // Instead, if the content of a table is hidden, then all inline child nodes of the table should be
                // hidden and thus removed by previous visits as well. This will result in the container being empty
                // so if this is the case we know to remove the table node.
                //
                // Note that a table which is not hidden but simply has no content will not be affected by this algorthim,
                // as technically they are not completely empty (for example a properly formed Cell will have at least
                // an empty paragraph in it)
                if (!table.hasChildNodes()) table.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Cell node is ended in the document.
             */
            public int visitCellEnd(Cell cell)
            {
                if (!cell.hasChildNodes() && cell.getParentNode() != null) cell.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when visiting of a Row node is ended in the document.
             */
            public int visitRowEnd(Row row)
            {
                if (!row.hasChildNodes() && row.getParentNode() != null) row.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Called when a SpecialCharacter is encountered in the document.
             */
            public int visitSpecialChar(SpecialChar character) throws Exception
            {
                if (isHidden(character)) character.remove();
        
                return VisitorAction.CONTINUE;
            }
        
            /**
             * Returns true if the node passed is set as hidden, returns false if it is visible.
             */
            private boolean isHidden(Node node)
            {
                if (node instanceof Inline)
                {
                    // If the node is Inline then cast it to retrieve the Font property which contains the hidden property
                    Inline currentNode = (Inline) node;
                    return currentNode.getFont().getHidden();
                } else if (node.getNodeType() == NodeType.PARAGRAPH)
                {
                    // If the node is a paragraph cast it to retrieve the ParagraphBreakFont which contains the hidden property
                    Paragraph para = (Paragraph) node;
                    return para.getParagraphBreakFont().getHidden();
                } else if (node instanceof ShapeBase)
                {
                    // Node is a shape or groupshape.
                    ShapeBase shape = (ShapeBase) node;
                    return shape.getFont().getHidden();
                } else if (node instanceof InlineStory)
                {
                    // Node is a comment or footnote.
                    InlineStory inlineStory = (InlineStory) node;
                    return inlineStory.getFont().getHidden();
                }
        
                // A node that is passed to this method which does not contain a hidden property will end up here.
                // By default nodes are not hidden so return false.
                return false;
            }
        }
      • visitTableStart

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