// Conduct the export and template processes, in the background under the dialog.
static void processTemplate(
File[] files, XmlDocument template, BatchConfig conf
) {
ImageFileExportOptions export = conf.export;
boolean ignoreResize =
export.resizeWidth.getValue() == 0 &&
export.resizeHeight.getValue() == 0;
// Remember the requested output width and height, because they may get
// mutated each time a file is processed. See these methods:
// createTemplateSaveOptions()
// conformExportOptions()
// Engine.write()
int exportWidth = export.resizeWidth.getValue();
int exportHeight = export.resizeHeight.getValue();
for (int n=0; n<files.length; n++) {
if (Canceled)
break;
if (Interrupted) {
synchronized(Thread) {
Thread.notifyAll();
return;
}
}
try {
File file = files[n];
Image.setCachedFile(file);
logStart(file);
Document doc = Application.createDocumentHeadless(file);
File outFile;
String outName;
// Enforce the original requested output dimensions, since
// the ImageExportOptions may have been mutated on a previous
// iteration.
export.resizeWidth.setValue(exportWidth);
export.resizeHeight.setValue(exportHeight);
if (template != null) {
XmlNode root = template.getRoot();
doc.applyTemplate(root);
SaveOptions save = doc.getSaveOptions();
if (save == null) {
save = createTemplateSaveOptions(doc, export, ignoreResize);
}
doc.setSaveOptions(save);
ComboFrame frame = (ComboFrame) Dialog.getOwner();
DocumentWriter.save(doc, frame, false, Progress);
outFile = save.getFile();
outName = outFile.getName();
DocumentDatabase.addDocumentFile(outFile);
} else {
conformExportOptions(doc, conf, ignoreResize);
Engine engine = doc.getEngine();
DocumentWriter.export(engine, export, Progress);
outFile = export.getExportFile();
outName = outFile.getName();
}
doc.dispose();