public interface IDocumentSavingCallback
Examples:
Shows how to manage a document while saving to html.
public void progressCallback(int saveFormat, String ext) throws Exception
{
Document doc = new Document(getMyDir() + "Big document.docx");
// Following formats are supported: Html, Mhtml, Epub.
HtmlSaveOptions saveOptions = new HtmlSaveOptions(saveFormat);
{
saveOptions.setProgressCallback(new SavingProgressCallback());
}
try {
doc.save(getArtifactsDir() + MessageFormat.format("HtmlSaveOptions.ProgressCallback.{0}", ext), saveOptions);
}
catch (IllegalStateException exception) {
Assert.assertTrue(exception.getMessage().contains("EstimatedProgress"));
}
}
public static Object[][] progressCallbackDataProvider() throws Exception
{
return new Object[][]
{
{SaveFormat.HTML, "html"},
{SaveFormat.MHTML, "mhtml"},
{SaveFormat.EPUB, "epub"},
};
}
/// <summary>
/// Saving progress callback. Cancel a document saving after the "MaxDuration" seconds.
/// </summary>
public static class SavingProgressCallback implements IDocumentSavingCallback
{
/// <summary>
/// Ctr.
/// </summary>
public SavingProgressCallback()
{
mSavingStartedAt = new Date();
}
/// <summary>
/// Callback method which called during document saving.
/// </summary>
/// <param name="args">Saving arguments.</param>
public void notify(DocumentSavingArgs args)
{
Date canceledAt = new Date();
long diff = canceledAt.getTime() - mSavingStartedAt.getTime();
long ellapsedSeconds = TimeUnit.MILLISECONDS.toSeconds(diff);
if (ellapsedSeconds > MAX_DURATION)
throw new IllegalStateException(MessageFormat.format("EstimatedProgress = {0}; CanceledAt = {1}", args.getEstimatedProgress(), canceledAt));
}
/// <summary>
/// Date and time when document saving is started.
/// </summary>
private Date mSavingStartedAt;
/// <summary>
/// Maximum allowed duration in sec.
/// </summary>
private static final double MAX_DURATION = 0.01d;
}
Shows how to manage a document while saving to docx.
public void progressCallback(int saveFormat, String ext) throws Exception
{
Document doc = new Document(getMyDir() + "Big document.docx");
// Following formats are supported: Docx, FlatOpc, Docm, Dotm, Dotx.
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(saveFormat);
{
saveOptions.setProgressCallback(new SavingProgressCallback());
}
try {
doc.save(getArtifactsDir() + MessageFormat.format("OoxmlSaveOptions.ProgressCallback.{0}", ext), saveOptions);
}
catch (IllegalStateException exception) {
Assert.assertTrue(exception.getMessage().contains("EstimatedProgress"));
}
}
public static Object[][] progressCallbackDataProvider() throws Exception
{
return new Object[][]
{
{SaveFormat.DOCX, "docx"},
{SaveFormat.DOCM, "docm"},
{SaveFormat.DOTM, "dotm"},
{SaveFormat.DOTX, "dotx"},
{SaveFormat.FLAT_OPC, "flatopc"},
};
}
/// <summary>
/// Saving progress callback. Cancel a document saving after the "MaxDuration" seconds.
/// </summary>
public static class SavingProgressCallback implements IDocumentSavingCallback
{
/// <summary>
/// Ctr.
/// </summary>
public SavingProgressCallback()
{
mSavingStartedAt = new Date();
}
/// <summary>
/// Callback method which called during document saving.
/// </summary>
/// <param name="args">Saving arguments.</param>
public void notify(DocumentSavingArgs args)
{
Date canceledAt = new Date();
long diff = canceledAt.getTime() - mSavingStartedAt.getTime();
long ellapsedSeconds = TimeUnit.MILLISECONDS.toSeconds(diff);
if (ellapsedSeconds > MAX_DURATION)
throw new IllegalStateException(MessageFormat.format("EstimatedProgress = {0}; CanceledAt = {1}", args.getEstimatedProgress(), canceledAt));
}
/// <summary>
/// Date and time when document saving is started.
/// </summary>
private Date mSavingStartedAt;
/// <summary>
/// Maximum allowed duration in sec.
/// </summary>
private static final double MAX_DURATION = 0.01d;
}
| Modifier and Type | Method and Description |
|---|---|
void |
notify(DocumentSavingArgs args)
This is called to notify of document saving progress.
|
void notify(DocumentSavingArgs args)
Remarks:
The primary uses for this interface is to allow application code to obtain progress status and abort saving process.
An exception should be threw from the progress callback for abortion and it should be caught in the consumer code.
Examples:
Shows how to manage a document while saving to xamlflow.
public void progressCallback(int saveFormat, String ext) throws Exception
{
Document doc = new Document(getMyDir() + "Big document.docx");
// Following formats are supported: XamlFlow, XamlFlowPack.
XamlFlowSaveOptions saveOptions = new XamlFlowSaveOptions(saveFormat);
{
saveOptions.setProgressCallback(new SavingProgressCallback());
}
try {
doc.save(getArtifactsDir() + MessageFormat.format("XamlFlowSaveOptions.ProgressCallback.{0}", ext), saveOptions);
}
catch (IllegalStateException exception) {
Assert.assertTrue(exception.getMessage().contains("EstimatedProgress"));
}
}
public static Object[][] progressCallbackDataProvider() throws Exception
{
return new Object[][]
{
{SaveFormat.XAML_FLOW, "xamlflow"},
{SaveFormat.XAML_FLOW_PACK, "xamlflowpack"},
};
}
/// <summary>
/// Saving progress callback. Cancel a document saving after the "MaxDuration" seconds.
/// </summary>
public static class SavingProgressCallback implements IDocumentSavingCallback
{
/// <summary>
/// Ctr.
/// </summary>
public SavingProgressCallback()
{
mSavingStartedAt = new Date();
}
/// <summary>
/// Callback method which called during document saving.
/// </summary>
/// <param name="args">Saving arguments.</param>
public void notify(DocumentSavingArgs args)
{
Date canceledAt = new Date();
long diff = canceledAt.getTime() - mSavingStartedAt.getTime();
long ellapsedSeconds = TimeUnit.MILLISECONDS.toSeconds(diff);
if (ellapsedSeconds > MAX_DURATION)
throw new IllegalStateException(MessageFormat.format("EstimatedProgress = {0}; CanceledAt = {1}", args.getEstimatedProgress(), canceledAt));
}
/// <summary>
/// Date and time when document saving is started.
/// </summary>
private Date mSavingStartedAt;
/// <summary>
/// Maximum allowed duration in sec.
/// </summary>
private static final double MAX_DURATION = 0.01d;
}
Shows how to manage a document while saving to html.
public void progressCallback(int saveFormat, String ext) throws Exception
{
Document doc = new Document(getMyDir() + "Big document.docx");
// Following formats are supported: Html, Mhtml, Epub.
HtmlSaveOptions saveOptions = new HtmlSaveOptions(saveFormat);
{
saveOptions.setProgressCallback(new SavingProgressCallback());
}
try {
doc.save(getArtifactsDir() + MessageFormat.format("HtmlSaveOptions.ProgressCallback.{0}", ext), saveOptions);
}
catch (IllegalStateException exception) {
Assert.assertTrue(exception.getMessage().contains("EstimatedProgress"));
}
}
public static Object[][] progressCallbackDataProvider() throws Exception
{
return new Object[][]
{
{SaveFormat.HTML, "html"},
{SaveFormat.MHTML, "mhtml"},
{SaveFormat.EPUB, "epub"},
};
}
/// <summary>
/// Saving progress callback. Cancel a document saving after the "MaxDuration" seconds.
/// </summary>
public static class SavingProgressCallback implements IDocumentSavingCallback
{
/// <summary>
/// Ctr.
/// </summary>
public SavingProgressCallback()
{
mSavingStartedAt = new Date();
}
/// <summary>
/// Callback method which called during document saving.
/// </summary>
/// <param name="args">Saving arguments.</param>
public void notify(DocumentSavingArgs args)
{
Date canceledAt = new Date();
long diff = canceledAt.getTime() - mSavingStartedAt.getTime();
long ellapsedSeconds = TimeUnit.MILLISECONDS.toSeconds(diff);
if (ellapsedSeconds > MAX_DURATION)
throw new IllegalStateException(MessageFormat.format("EstimatedProgress = {0}; CanceledAt = {1}", args.getEstimatedProgress(), canceledAt));
}
/// <summary>
/// Date and time when document saving is started.
/// </summary>
private Date mSavingStartedAt;
/// <summary>
/// Maximum allowed duration in sec.
/// </summary>
private static final double MAX_DURATION = 0.01d;
}
Shows how to manage a document while saving to docx.
public void progressCallback(int saveFormat, String ext) throws Exception
{
Document doc = new Document(getMyDir() + "Big document.docx");
// Following formats are supported: Docx, FlatOpc, Docm, Dotm, Dotx.
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(saveFormat);
{
saveOptions.setProgressCallback(new SavingProgressCallback());
}
try {
doc.save(getArtifactsDir() + MessageFormat.format("OoxmlSaveOptions.ProgressCallback.{0}", ext), saveOptions);
}
catch (IllegalStateException exception) {
Assert.assertTrue(exception.getMessage().contains("EstimatedProgress"));
}
}
public static Object[][] progressCallbackDataProvider() throws Exception
{
return new Object[][]
{
{SaveFormat.DOCX, "docx"},
{SaveFormat.DOCM, "docm"},
{SaveFormat.DOTM, "dotm"},
{SaveFormat.DOTX, "dotx"},
{SaveFormat.FLAT_OPC, "flatopc"},
};
}
/// <summary>
/// Saving progress callback. Cancel a document saving after the "MaxDuration" seconds.
/// </summary>
public static class SavingProgressCallback implements IDocumentSavingCallback
{
/// <summary>
/// Ctr.
/// </summary>
public SavingProgressCallback()
{
mSavingStartedAt = new Date();
}
/// <summary>
/// Callback method which called during document saving.
/// </summary>
/// <param name="args">Saving arguments.</param>
public void notify(DocumentSavingArgs args)
{
Date canceledAt = new Date();
long diff = canceledAt.getTime() - mSavingStartedAt.getTime();
long ellapsedSeconds = TimeUnit.MILLISECONDS.toSeconds(diff);
if (ellapsedSeconds > MAX_DURATION)
throw new IllegalStateException(MessageFormat.format("EstimatedProgress = {0}; CanceledAt = {1}", args.getEstimatedProgress(), canceledAt));
}
/// <summary>
/// Date and time when document saving is started.
/// </summary>
private Date mSavingStartedAt;
/// <summary>
/// Maximum allowed duration in sec.
/// </summary>
private static final double MAX_DURATION = 0.01d;
}
args - An argument of the event.