com.aspose.words
Interface INodeChangingCallback


public interface INodeChangingCallback 

Implement this interface if you want to receive notifications when nodes are inserted or removed in the document.

Example:

Shows how to implement custom logic over node insertion in the document by changing the font of inserted HTML content.
public void testNodeChangingInDocument() throws Exception
{
    // Create a blank document object
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Set up and pass the object which implements the handler methods.
    doc.setNodeChangingCallback(new HandleNodeChanging_FontChanger());

    // Insert sample HTML content
    builder.insertHtml("<p>Hello World</p>");

    doc.save(getMyDir() + "Document.FontChanger Out.doc");

    // Check that the inserted content has the correct formatting
    Run run = (Run)doc.getChild(NodeType.RUN, 0, true);
    Assert.assertEquals(run.getFont().getSize(), 24.0);
    Assert.assertEquals(run.getFont().getName(), "Arial");
}

public class HandleNodeChanging_FontChanger implements INodeChangingCallback
{
    // Implement the NodeInserted handler to set default font settings for every Run node inserted into the Document
    public void nodeInserted(NodeChangingArgs args) throws Exception
    {
        // Change the font of inserted text contained in the Run nodes.
        if (args.getNode().getNodeType() == NodeType.RUN)
        {
            Font font = ((Run)args.getNode()).getFont();
            font.setSize(24);
            font.setName("Arial");
        }
    }

    public void nodeInserting(NodeChangingArgs args) throws Exception
    {
        // Do Nothing
    }

    public void nodeRemoved(NodeChangingArgs args) throws Exception
    {
        // Do Nothing
    }

    public void nodeRemoving(NodeChangingArgs args) throws Exception
    {
        // Do Nothing
    }
}

Method Summary
abstract voidnodeInserted(NodeChangingArgs args)
           Called when a node belonging to this document has been inserted into another node.
abstract voidnodeInserting(NodeChangingArgs args)
           Called just before a node belonging to this document is about to be inserted into another node.
abstract voidnodeRemoved(NodeChangingArgs args)
           Called when a node belonging to this document has been removed from its parent.
abstract voidnodeRemoving(NodeChangingArgs args)
           Called just before a node belonging to this document is about to be removed from the document.
 

Method Detail

nodeInserted

public abstract void nodeInserted(NodeChangingArgs args)
                               throws java.lang.Exception
Called when a node belonging to this document has been inserted into another node.

Example:

Shows how to implement custom logic over node insertion in the document by changing the font of inserted HTML content.
public void testNodeChangingInDocument() throws Exception
{
    // Create a blank document object
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Set up and pass the object which implements the handler methods.
    doc.setNodeChangingCallback(new HandleNodeChanging_FontChanger());

    // Insert sample HTML content
    builder.insertHtml("<p>Hello World</p>");

    doc.save(getMyDir() + "Document.FontChanger Out.doc");

    // Check that the inserted content has the correct formatting
    Run run = (Run)doc.getChild(NodeType.RUN, 0, true);
    Assert.assertEquals(run.getFont().getSize(), 24.0);
    Assert.assertEquals(run.getFont().getName(), "Arial");
}

public class HandleNodeChanging_FontChanger implements INodeChangingCallback
{
    // Implement the NodeInserted handler to set default font settings for every Run node inserted into the Document
    public void nodeInserted(NodeChangingArgs args) throws Exception
    {
        // Change the font of inserted text contained in the Run nodes.
        if (args.getNode().getNodeType() == NodeType.RUN)
        {
            Font font = ((Run)args.getNode()).getFont();
            font.setSize(24);
            font.setName("Arial");
        }
    }

    public void nodeInserting(NodeChangingArgs args) throws Exception
    {
        // Do Nothing
    }

    public void nodeRemoved(NodeChangingArgs args) throws Exception
    {
        // Do Nothing
    }

    public void nodeRemoving(NodeChangingArgs args) throws Exception
    {
        // Do Nothing
    }
}

nodeInserting

public abstract void nodeInserting(NodeChangingArgs args)
                                throws java.lang.Exception
Called just before a node belonging to this document is about to be inserted into another node.

Example:

Shows how to implement custom logic over node insertion in the document by changing the font of inserted HTML content.
public void testNodeChangingInDocument() throws Exception
{
    // Create a blank document object
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Set up and pass the object which implements the handler methods.
    doc.setNodeChangingCallback(new HandleNodeChanging_FontChanger());

    // Insert sample HTML content
    builder.insertHtml("<p>Hello World</p>");

    doc.save(getMyDir() + "Document.FontChanger Out.doc");

    // Check that the inserted content has the correct formatting
    Run run = (Run)doc.getChild(NodeType.RUN, 0, true);
    Assert.assertEquals(run.getFont().getSize(), 24.0);
    Assert.assertEquals(run.getFont().getName(), "Arial");
}

public class HandleNodeChanging_FontChanger implements INodeChangingCallback
{
    // Implement the NodeInserted handler to set default font settings for every Run node inserted into the Document
    public void nodeInserted(NodeChangingArgs args) throws Exception
    {
        // Change the font of inserted text contained in the Run nodes.
        if (args.getNode().getNodeType() == NodeType.RUN)
        {
            Font font = ((Run)args.getNode()).getFont();
            font.setSize(24);
            font.setName("Arial");
        }
    }

    public void nodeInserting(NodeChangingArgs args) throws Exception
    {
        // Do Nothing
    }

    public void nodeRemoved(NodeChangingArgs args) throws Exception
    {
        // Do Nothing
    }

    public void nodeRemoving(NodeChangingArgs args) throws Exception
    {
        // Do Nothing
    }
}

nodeRemoved

public abstract void nodeRemoved(NodeChangingArgs args)
                              throws java.lang.Exception
Called when a node belonging to this document has been removed from its parent.

Example:

Shows how to implement custom logic over node insertion in the document by changing the font of inserted HTML content.
public void testNodeChangingInDocument() throws Exception
{
    // Create a blank document object
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Set up and pass the object which implements the handler methods.
    doc.setNodeChangingCallback(new HandleNodeChanging_FontChanger());

    // Insert sample HTML content
    builder.insertHtml("<p>Hello World</p>");

    doc.save(getMyDir() + "Document.FontChanger Out.doc");

    // Check that the inserted content has the correct formatting
    Run run = (Run)doc.getChild(NodeType.RUN, 0, true);
    Assert.assertEquals(run.getFont().getSize(), 24.0);
    Assert.assertEquals(run.getFont().getName(), "Arial");
}

public class HandleNodeChanging_FontChanger implements INodeChangingCallback
{
    // Implement the NodeInserted handler to set default font settings for every Run node inserted into the Document
    public void nodeInserted(NodeChangingArgs args) throws Exception
    {
        // Change the font of inserted text contained in the Run nodes.
        if (args.getNode().getNodeType() == NodeType.RUN)
        {
            Font font = ((Run)args.getNode()).getFont();
            font.setSize(24);
            font.setName("Arial");
        }
    }

    public void nodeInserting(NodeChangingArgs args) throws Exception
    {
        // Do Nothing
    }

    public void nodeRemoved(NodeChangingArgs args) throws Exception
    {
        // Do Nothing
    }

    public void nodeRemoving(NodeChangingArgs args) throws Exception
    {
        // Do Nothing
    }
}

nodeRemoving

public abstract void nodeRemoving(NodeChangingArgs args)
                               throws java.lang.Exception
Called just before a node belonging to this document is about to be removed from the document.

Example:

Shows how to implement custom logic over node insertion in the document by changing the font of inserted HTML content.
public void testNodeChangingInDocument() throws Exception
{
    // Create a blank document object
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Set up and pass the object which implements the handler methods.
    doc.setNodeChangingCallback(new HandleNodeChanging_FontChanger());

    // Insert sample HTML content
    builder.insertHtml("<p>Hello World</p>");

    doc.save(getMyDir() + "Document.FontChanger Out.doc");

    // Check that the inserted content has the correct formatting
    Run run = (Run)doc.getChild(NodeType.RUN, 0, true);
    Assert.assertEquals(run.getFont().getSize(), 24.0);
    Assert.assertEquals(run.getFont().getName(), "Arial");
}

public class HandleNodeChanging_FontChanger implements INodeChangingCallback
{
    // Implement the NodeInserted handler to set default font settings for every Run node inserted into the Document
    public void nodeInserted(NodeChangingArgs args) throws Exception
    {
        // Change the font of inserted text contained in the Run nodes.
        if (args.getNode().getNodeType() == NodeType.RUN)
        {
            Font font = ((Run)args.getNode()).getFont();
            font.setSize(24);
            font.setName("Arial");
        }
    }

    public void nodeInserting(NodeChangingArgs args) throws Exception
    {
        // Do Nothing
    }

    public void nodeRemoved(NodeChangingArgs args) throws Exception
    {
        // Do Nothing
    }

    public void nodeRemoving(NodeChangingArgs args) throws Exception
    {
        // Do Nothing
    }
}

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