com.aspose.words
Class VisitorAction

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

public class VisitorAction 
extends java.lang.Object

Utility class containing constants. Allows the visitor to control the enumeration of nodes.

Example:

Shows how to process absolute position tab characters with a document visitor.
public void documentToTxt() throws Exception {
    Document doc = new Document(getMyDir() + "Absolute position tab.docx");

    // Extract the text contents of our document by accepting this custom document visitor.
    DocTextExtractor myDocTextExtractor = new DocTextExtractor();
    Section fisrtSection = doc.getFirstSection();
    fisrtSection.getBody().accept(myDocTextExtractor);
    // Visit only start of the document body.
    fisrtSection.getBody().acceptStart(myDocTextExtractor);
    // Visit only end of the document body.
    fisrtSection.getBody().acceptEnd(myDocTextExtractor);

    // The absolute position tab, which has no equivalent in string form, has been explicitly converted to a tab character.
    Assert.assertEquals("Before AbsolutePositionTab\tAfter AbsolutePositionTab", myDocTextExtractor.getText());

    // An AbsolutePositionTab can accept a DocumentVisitor by itself too.
    AbsolutePositionTab absPositionTab = (AbsolutePositionTab) doc.getFirstSection().getBody().getFirstParagraph().getChild(NodeType.SPECIAL_CHAR, 0, true);

    myDocTextExtractor = new DocTextExtractor();
    absPositionTab.accept(myDocTextExtractor);

    Assert.assertEquals("\t", myDocTextExtractor.getText());
}

/// <summary>
/// Collects the text contents of all runs in the visited document. Replaces all absolute tab characters with ordinary tabs.
/// </summary>
public static class DocTextExtractor extends DocumentVisitor {
    public DocTextExtractor() {
        mBuilder = new StringBuilder();
    }

    /// <summary>
    /// Called when a Run node is encountered in the document.
    /// </summary>
    public int visitRun(final Run run) {
        appendText(run.getText());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when an AbsolutePositionTab node is encountered in the document.
    /// </summary>
    public int visitAbsolutePositionTab(final AbsolutePositionTab tab) {
        mBuilder.append("\t");

        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Adds text to the current output. Honors the enabled/disabled output flag.
    /// </summary>
    public void appendText(final String text) {
        mBuilder.append(text);
    }

    /// <summary>
    /// Plain text of the document that was accumulated by the visitor.
    /// </summary>
    public String getText() {
        return mBuilder.toString();
    }

    private final StringBuilder mBuilder;
}

Field Summary
static final intCONTINUE = 0
           The visitor requests the enumeration to continue.
static final intSKIP_THIS_NODE = 1
           The visitor requests to skip the current node and continue enumeration.
static final intSTOP = 2
           The visitor requests the enumeration of nodes to stop.
 

Field Detail

CONTINUE = 0

public static final int CONTINUE
The visitor requests the enumeration to continue.

SKIP_THIS_NODE = 1

public static final int SKIP_THIS_NODE
The visitor requests to skip the current node and continue enumeration.

STOP = 2

public static final int STOP
The visitor requests the enumeration of nodes to stop.

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