}
client.notifyStarted(modules.size());
try {
ZipFile zf = new ZipFile(new File(parent.getPath(), main.getName().toLowerCase() + "_export.zip"));
for (DcModule module : modules) {
if (canceled) break;
// only export custom modules
// adds the module jar file to the distribution
if (module.isCustomModule() && module.getXmlModule() != null) {
XmlModule xmlModule = module.getXmlModule();
String jarName = xmlModule.getJarFilename();
byte[] content = Utilities.readFile(new File(DataCrow.moduleDir, jarName));
zf.addEntry(jarName, content);
}
// settings export
File file = module.getSettings().getSettings().getSettingsFile();
module.getSettings().save();
if (file.exists()) {
byte[] content = Utilities.readFile(file);
zf.addEntry(file.getName(), content);
}
// reports
if (module.hasReports()) {
String reportDir = DataCrow.reportDir + module.getName().toLowerCase().replaceAll("[/\\*%., ]", "");
Directory dir = new Directory(reportDir, true, new String[] {"xsl, xslt"});
for (String filename : dir.read()) {
byte[] content = Utilities.readFile(new File(filename));
String name = filename.substring(filename.indexOf(File.separator + "reports" + File.separator) + 9);
zf.addEntry(name, content);
}
}
// item export
if (!module.isChildModule() &&
(((module.getIndex() == parent.getModule() || module instanceof ExternalReferenceModule) && parent.isExportData()) ||
(!(module instanceof ExternalReferenceModule) && module.getIndex() != parent.getModule() && parent.isExportDataRelatedMods()))) {
try {
exportData(module.getIndex());
// get the XML
file = new File(parent.getPath(), module.getTableName() + ".xml");
if (file.exists() && !canceled) {
byte[] data = Utilities.readFile(file);
zf.addEntry(module.getTableName() + ".xml", data);
// get the images
File imgPath = new File(parent.getPath(), module.getTableName() + "_images");
if (imgPath.exists()) {
for (String image : imgPath.list()) {
if (canceled) break;
// add the image
File imgFile = new File(imgPath.toString(), image);
byte[] img = Utilities.readFile(imgFile);
zf.addEntry(module.getTableName() + "_" + image, img);
imgFile.delete();
}
imgPath.delete();
}
new File(parent.getPath(), module.getTableName() + ".xsd").delete();
file.delete();
}
} catch (Exception e) {
client.notifyError(e);
}
}
client.notifyMessage(DcResources.getText("msgExportedModule", module.getLabel()));
client.notifyProcessed();
}
zf.close();
} catch (Exception e) {
client.notifyError(e);
}
client.notifyFinished();