public interface INodeChangingCallback
Example:
public void fontChangeViaCallback() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Set the node changing callback to custom implementation,
// then add/remove nodes to get it to generate a log.
HandleNodeChangingFontChanger callback = new HandleNodeChangingFontChanger();
doc.setNodeChangingCallback(callback);
builder.writeln("Hello world!");
builder.writeln("Hello again!");
builder.insertField(" HYPERLINK \"https://www.google.com/\" ");
builder.insertShape(ShapeType.RECTANGLE, 300.0, 300.0);
doc.getRange().getFields().get(0).remove();
System.out.println(callback.getLog());
}
/// <summary>
/// Logs the date and time of each node insertion and removal,
/// and also set a custom font name/size for the text contents of Run nodes.
/// </summary>
public static class HandleNodeChangingFontChanger implements INodeChangingCallback {
public void nodeInserted(NodeChangingArgs args) {
mLog.append(MessageFormat.format("\tType:\t{0}", args.getNode().getNodeType()));
mLog.append(MessageFormat.format("\tHash:\t{0}", args.getNode().hashCode()));
if (args.getNode().getNodeType() == NodeType.RUN) {
Font font = ((Run) args.getNode()).getFont();
mLog.append(MessageFormat.format("\tFont:\tChanged from \"{0}\" {1}pt", font.getName(), font.getSize()));
font.setSize(24.0);
font.setName("Arial");
mLog.append(MessageFormat.format(" to \"{0}\" {1}pt", font.getName(), font.getSize()));
mLog.append(MessageFormat.format("\tContents:\n\t\t\"{0}\"", args.getNode().getText()));
}
}
public void nodeInserting(NodeChangingArgs args) {
mLog.append(MessageFormat.format("\n{0}\tNode insertion:", new Date()));
}
public void nodeRemoved(NodeChangingArgs args) {
mLog.append(MessageFormat.format("\tType:\t{0}", args.getNode().getNodeType()));
mLog.append(MessageFormat.format("\tHash code:\t{0}", args.getNode().hashCode()));
}
public void nodeRemoving(NodeChangingArgs args) {
mLog.append(MessageFormat.format("\n{0}\tNode removal:", new Date()));
}
public String getLog() {
return mLog.toString();
}
private final StringBuilder mLog = new StringBuilder();
}
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 customize node changing with a callback.public void fontChangeViaCallback() throws Exception { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Set the node changing callback to custom implementation, // then add/remove nodes to get it to generate a log. HandleNodeChangingFontChanger callback = new HandleNodeChangingFontChanger(); doc.setNodeChangingCallback(callback); builder.writeln("Hello world!"); builder.writeln("Hello again!"); builder.insertField(" HYPERLINK \"https://www.google.com/\" "); builder.insertShape(ShapeType.RECTANGLE, 300.0, 300.0); doc.getRange().getFields().get(0).remove(); System.out.println(callback.getLog()); } /// <summary> /// Logs the date and time of each node insertion and removal, /// and also set a custom font name/size for the text contents of Run nodes. /// </summary> public static class HandleNodeChangingFontChanger implements INodeChangingCallback { public void nodeInserted(NodeChangingArgs args) { mLog.append(MessageFormat.format("\tType:\t{0}", args.getNode().getNodeType())); mLog.append(MessageFormat.format("\tHash:\t{0}", args.getNode().hashCode())); if (args.getNode().getNodeType() == NodeType.RUN) { Font font = ((Run) args.getNode()).getFont(); mLog.append(MessageFormat.format("\tFont:\tChanged from \"{0}\" {1}pt", font.getName(), font.getSize())); font.setSize(24.0); font.setName("Arial"); mLog.append(MessageFormat.format(" to \"{0}\" {1}pt", font.getName(), font.getSize())); mLog.append(MessageFormat.format("\tContents:\n\t\t\"{0}\"", args.getNode().getText())); } } public void nodeInserting(NodeChangingArgs args) { mLog.append(MessageFormat.format("\n{0}\tNode insertion:", new Date())); } public void nodeRemoved(NodeChangingArgs args) { mLog.append(MessageFormat.format("\tType:\t{0}", args.getNode().getNodeType())); mLog.append(MessageFormat.format("\tHash code:\t{0}", args.getNode().hashCode())); } public void nodeRemoving(NodeChangingArgs args) { mLog.append(MessageFormat.format("\n{0}\tNode removal:", new Date())); } public String getLog() { return mLog.toString(); } private final StringBuilder mLog = new StringBuilder(); }
nodeInserting | |
public abstract void nodeInserting(NodeChangingArgs args) throws java.lang.Exception |
Example:
Shows how customize node changing with a callback.public void fontChangeViaCallback() throws Exception { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Set the node changing callback to custom implementation, // then add/remove nodes to get it to generate a log. HandleNodeChangingFontChanger callback = new HandleNodeChangingFontChanger(); doc.setNodeChangingCallback(callback); builder.writeln("Hello world!"); builder.writeln("Hello again!"); builder.insertField(" HYPERLINK \"https://www.google.com/\" "); builder.insertShape(ShapeType.RECTANGLE, 300.0, 300.0); doc.getRange().getFields().get(0).remove(); System.out.println(callback.getLog()); } /// <summary> /// Logs the date and time of each node insertion and removal, /// and also set a custom font name/size for the text contents of Run nodes. /// </summary> public static class HandleNodeChangingFontChanger implements INodeChangingCallback { public void nodeInserted(NodeChangingArgs args) { mLog.append(MessageFormat.format("\tType:\t{0}", args.getNode().getNodeType())); mLog.append(MessageFormat.format("\tHash:\t{0}", args.getNode().hashCode())); if (args.getNode().getNodeType() == NodeType.RUN) { Font font = ((Run) args.getNode()).getFont(); mLog.append(MessageFormat.format("\tFont:\tChanged from \"{0}\" {1}pt", font.getName(), font.getSize())); font.setSize(24.0); font.setName("Arial"); mLog.append(MessageFormat.format(" to \"{0}\" {1}pt", font.getName(), font.getSize())); mLog.append(MessageFormat.format("\tContents:\n\t\t\"{0}\"", args.getNode().getText())); } } public void nodeInserting(NodeChangingArgs args) { mLog.append(MessageFormat.format("\n{0}\tNode insertion:", new Date())); } public void nodeRemoved(NodeChangingArgs args) { mLog.append(MessageFormat.format("\tType:\t{0}", args.getNode().getNodeType())); mLog.append(MessageFormat.format("\tHash code:\t{0}", args.getNode().hashCode())); } public void nodeRemoving(NodeChangingArgs args) { mLog.append(MessageFormat.format("\n{0}\tNode removal:", new Date())); } public String getLog() { return mLog.toString(); } private final StringBuilder mLog = new StringBuilder(); }
nodeRemoved | |
public abstract void nodeRemoved(NodeChangingArgs args) throws java.lang.Exception |
Example:
Shows how customize node changing with a callback.public void fontChangeViaCallback() throws Exception { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Set the node changing callback to custom implementation, // then add/remove nodes to get it to generate a log. HandleNodeChangingFontChanger callback = new HandleNodeChangingFontChanger(); doc.setNodeChangingCallback(callback); builder.writeln("Hello world!"); builder.writeln("Hello again!"); builder.insertField(" HYPERLINK \"https://www.google.com/\" "); builder.insertShape(ShapeType.RECTANGLE, 300.0, 300.0); doc.getRange().getFields().get(0).remove(); System.out.println(callback.getLog()); } /// <summary> /// Logs the date and time of each node insertion and removal, /// and also set a custom font name/size for the text contents of Run nodes. /// </summary> public static class HandleNodeChangingFontChanger implements INodeChangingCallback { public void nodeInserted(NodeChangingArgs args) { mLog.append(MessageFormat.format("\tType:\t{0}", args.getNode().getNodeType())); mLog.append(MessageFormat.format("\tHash:\t{0}", args.getNode().hashCode())); if (args.getNode().getNodeType() == NodeType.RUN) { Font font = ((Run) args.getNode()).getFont(); mLog.append(MessageFormat.format("\tFont:\tChanged from \"{0}\" {1}pt", font.getName(), font.getSize())); font.setSize(24.0); font.setName("Arial"); mLog.append(MessageFormat.format(" to \"{0}\" {1}pt", font.getName(), font.getSize())); mLog.append(MessageFormat.format("\tContents:\n\t\t\"{0}\"", args.getNode().getText())); } } public void nodeInserting(NodeChangingArgs args) { mLog.append(MessageFormat.format("\n{0}\tNode insertion:", new Date())); } public void nodeRemoved(NodeChangingArgs args) { mLog.append(MessageFormat.format("\tType:\t{0}", args.getNode().getNodeType())); mLog.append(MessageFormat.format("\tHash code:\t{0}", args.getNode().hashCode())); } public void nodeRemoving(NodeChangingArgs args) { mLog.append(MessageFormat.format("\n{0}\tNode removal:", new Date())); } public String getLog() { return mLog.toString(); } private final StringBuilder mLog = new StringBuilder(); }
nodeRemoving | |
public abstract void nodeRemoving(NodeChangingArgs args) throws java.lang.Exception |
Example:
Shows how customize node changing with a callback.public void fontChangeViaCallback() throws Exception { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Set the node changing callback to custom implementation, // then add/remove nodes to get it to generate a log. HandleNodeChangingFontChanger callback = new HandleNodeChangingFontChanger(); doc.setNodeChangingCallback(callback); builder.writeln("Hello world!"); builder.writeln("Hello again!"); builder.insertField(" HYPERLINK \"https://www.google.com/\" "); builder.insertShape(ShapeType.RECTANGLE, 300.0, 300.0); doc.getRange().getFields().get(0).remove(); System.out.println(callback.getLog()); } /// <summary> /// Logs the date and time of each node insertion and removal, /// and also set a custom font name/size for the text contents of Run nodes. /// </summary> public static class HandleNodeChangingFontChanger implements INodeChangingCallback { public void nodeInserted(NodeChangingArgs args) { mLog.append(MessageFormat.format("\tType:\t{0}", args.getNode().getNodeType())); mLog.append(MessageFormat.format("\tHash:\t{0}", args.getNode().hashCode())); if (args.getNode().getNodeType() == NodeType.RUN) { Font font = ((Run) args.getNode()).getFont(); mLog.append(MessageFormat.format("\tFont:\tChanged from \"{0}\" {1}pt", font.getName(), font.getSize())); font.setSize(24.0); font.setName("Arial"); mLog.append(MessageFormat.format(" to \"{0}\" {1}pt", font.getName(), font.getSize())); mLog.append(MessageFormat.format("\tContents:\n\t\t\"{0}\"", args.getNode().getText())); } } public void nodeInserting(NodeChangingArgs args) { mLog.append(MessageFormat.format("\n{0}\tNode insertion:", new Date())); } public void nodeRemoved(NodeChangingArgs args) { mLog.append(MessageFormat.format("\tType:\t{0}", args.getNode().getNodeType())); mLog.append(MessageFormat.format("\tHash code:\t{0}", args.getNode().hashCode())); } public void nodeRemoving(NodeChangingArgs args) { mLog.append(MessageFormat.format("\n{0}\tNode removal:", new Date())); } public String getLog() { return mLog.toString(); } private final StringBuilder mLog = new StringBuilder(); }