com.aspose.words

Class NodeChangingAction

  • java.lang.Object
    • com.aspose.words.NodeChangingAction
public class NodeChangingAction 
extends java.lang.Object

Utility class containing constants. Specifies the type of node change.

Example:

Shows how to use a NodeChangingCallback to monitor changes to the document tree as it is edited.
public void nodeChangingCallback() throws Exception {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Set the NodeChangingCallback attribute to a custom printer
    doc.setNodeChangingCallback(new NodeChangingPrinter());

    // All node additions and removals will be printed to the console as we edit the document
    builder.writeln("Hello world!");
    builder.startTable();
    builder.insertCell();
    builder.write("Cell 1");
    builder.insertCell();
    builder.write("Cell 2");
    builder.endTable();

    builder.insertImage(getImageDir() + "Logo.jpg");
    builder.getCurrentParagraph().getParentNode().removeAllChildren();
}

/// <summary>
/// Prints all inserted/removed nodes as well as their parent nodes.
/// </summary>
private static class NodeChangingPrinter implements INodeChangingCallback {
    public void nodeInserting(NodeChangingArgs args) {
        Assert.assertEquals(args.getAction(), NodeChangingAction.INSERT);
        Assert.assertEquals(args.getOldParent(), null);
    }

    public void nodeInserted(NodeChangingArgs args) {
        Assert.assertEquals(args.getAction(), NodeChangingAction.INSERT);
        Assert.assertNotNull(args.getNewParent());

        System.out.println("Inserted node:");
        System.out.println(MessageFormat.format("\tType:\t{0}", args.getNode().getNodeType()));

        if (!"".equals(args.getNode().getText().trim())) {
            System.out.println(MessageFormat.format("\tText:\t\"{0}\"", args.getNode().getText().trim()));
        }

        System.out.println(MessageFormat.format("\tHash:\t{0}", args.getNode().hashCode()));
        System.out.println(MessageFormat.format("\tParent:\t{0} ({1})", args.getNewParent().getNodeType(), args.getNewParent().hashCode()));
    }

    public void nodeRemoving(NodeChangingArgs args) {
        Assert.assertEquals(args.getAction(), NodeChangingAction.REMOVE);
    }

    public void nodeRemoved(NodeChangingArgs args) {
        Assert.assertEquals(args.getAction(), NodeChangingAction.REMOVE);
        Assert.assertNull(args.getNewParent());

        System.out.println(MessageFormat.format("Removed node: {0} ({1})", args.getNode().getNodeType(), args.getNode().hashCode()));
    }
}
See Also:
NodeChangingArgs, NodeChangingArgs.Action

Field Summary
static final intINSERT = 0
A node is being inserted in the tree.
static final intREMOVE = 1
A node is being removed from the tree.
 

    • Field Detail

      • INSERT = 0

        public static final int INSERT
        A node is being inserted in the tree.
      • REMOVE = 1

        public static final int REMOVE
        A node is being removed from the tree.