public interface INodeChangingCallback
Example:
public void fontChangeViaCallback() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Set up and pass the object which implements the handler methods
doc.setNodeChangingCallback(new HandleNodeChangingFontChanger());
// Insert sample HTML content
builder.insertHtml("<p>Hello World</p>");
doc.save(getArtifactsDir() + "Document.FontChangeViaCallback.docx");
}
public class HandleNodeChangingFontChanger implements INodeChangingCallback {
// Implement the NodeInserted handler to set default font settings for every Run node inserted into the Document
public void nodeInserted(final NodeChangingArgs args) {
// 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(final NodeChangingArgs args) {
// Do Nothing
}
public void nodeRemoved(final NodeChangingArgs args) {
// Do Nothing
}
public void nodeRemoving(final NodeChangingArgs args) {
// Do Nothing
}
}
Method Summary | ||
---|---|---|
abstract void | nodeInserted(NodeChangingArgs args) | |
Called when a node belonging to this document has been inserted into another node. | ||
abstract void | nodeInserting(NodeChangingArgs args) | |
Called just before a node belonging to this document is about to be inserted into another node. | ||
abstract void | nodeRemoved(NodeChangingArgs args) | |
Called when a node belonging to this document has been removed from its parent. | ||
abstract void | nodeRemoving(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 |
Example:
Shows how to implement custom logic over node insertion in the document by changing the font of inserted HTML content.public void fontChangeViaCallback() throws Exception { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Set up and pass the object which implements the handler methods doc.setNodeChangingCallback(new HandleNodeChangingFontChanger()); // Insert sample HTML content builder.insertHtml("<p>Hello World</p>"); doc.save(getArtifactsDir() + "Document.FontChangeViaCallback.docx"); } public class HandleNodeChangingFontChanger implements INodeChangingCallback { // Implement the NodeInserted handler to set default font settings for every Run node inserted into the Document public void nodeInserted(final NodeChangingArgs args) { // 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(final NodeChangingArgs args) { // Do Nothing } public void nodeRemoved(final NodeChangingArgs args) { // Do Nothing } public void nodeRemoving(final NodeChangingArgs args) { // Do Nothing } }
nodeInserting | |
public abstract void nodeInserting(NodeChangingArgs args) throws java.lang.Exception |
Example:
Shows how to implement custom logic over node insertion in the document by changing the font of inserted HTML content.public void fontChangeViaCallback() throws Exception { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Set up and pass the object which implements the handler methods doc.setNodeChangingCallback(new HandleNodeChangingFontChanger()); // Insert sample HTML content builder.insertHtml("<p>Hello World</p>"); doc.save(getArtifactsDir() + "Document.FontChangeViaCallback.docx"); } public class HandleNodeChangingFontChanger implements INodeChangingCallback { // Implement the NodeInserted handler to set default font settings for every Run node inserted into the Document public void nodeInserted(final NodeChangingArgs args) { // 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(final NodeChangingArgs args) { // Do Nothing } public void nodeRemoved(final NodeChangingArgs args) { // Do Nothing } public void nodeRemoving(final NodeChangingArgs args) { // Do Nothing } }
nodeRemoved | |
public abstract void nodeRemoved(NodeChangingArgs args) throws java.lang.Exception |
Example:
Shows how to implement custom logic over node insertion in the document by changing the font of inserted HTML content.public void fontChangeViaCallback() throws Exception { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Set up and pass the object which implements the handler methods doc.setNodeChangingCallback(new HandleNodeChangingFontChanger()); // Insert sample HTML content builder.insertHtml("<p>Hello World</p>"); doc.save(getArtifactsDir() + "Document.FontChangeViaCallback.docx"); } public class HandleNodeChangingFontChanger implements INodeChangingCallback { // Implement the NodeInserted handler to set default font settings for every Run node inserted into the Document public void nodeInserted(final NodeChangingArgs args) { // 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(final NodeChangingArgs args) { // Do Nothing } public void nodeRemoved(final NodeChangingArgs args) { // Do Nothing } public void nodeRemoving(final NodeChangingArgs args) { // Do Nothing } }
nodeRemoving | |
public abstract void nodeRemoving(NodeChangingArgs args) throws java.lang.Exception |
Example:
Shows how to implement custom logic over node insertion in the document by changing the font of inserted HTML content.public void fontChangeViaCallback() throws Exception { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Set up and pass the object which implements the handler methods doc.setNodeChangingCallback(new HandleNodeChangingFontChanger()); // Insert sample HTML content builder.insertHtml("<p>Hello World</p>"); doc.save(getArtifactsDir() + "Document.FontChangeViaCallback.docx"); } public class HandleNodeChangingFontChanger implements INodeChangingCallback { // Implement the NodeInserted handler to set default font settings for every Run node inserted into the Document public void nodeInserted(final NodeChangingArgs args) { // 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(final NodeChangingArgs args) { // Do Nothing } public void nodeRemoved(final NodeChangingArgs args) { // Do Nothing } public void nodeRemoving(final NodeChangingArgs args) { // Do Nothing } }