use of org.openntf.nsfodp.commons.odp.notesapi.NDXLExporter in project org.openntf.nsfodp by OpenNTF.
the class ODPExporter method export.
/**
* Exports the NSF to an on-disk project using the configured settings.
*
* @return a {@link Path} to the on-disk project root, either a directory or a ZIP file
* @throws IOException if there is a problem reading or writing filesystem data
*/
public Path export() throws IOException {
Path target;
Path returnPath;
ODPType odpType = this.odpType == null ? ODPType.DIRECTORY : this.odpType;
switch(odpType) {
case ZIP:
// $NON-NLS-1$ //$NON-NLS-2$
returnPath = Files.createTempFile(NSFODPUtil.getTempDirectory(), "org.openntf.nsfodp.exporter", ".zip");
// $NON-NLS-1$
target = NSFODPUtil.openZipPath(returnPath).getPath("/");
break;
case DIRECTORY:
default:
target = returnPath = Files.createTempDirectory(getClass().getName());
break;
}
try (NDXLExporter exporter = database.getAPI().createDXLExporter()) {
// Output database.properties in encapsulated format
// $NON-NLS-1$ //$NON-NLS-2$
Path databaseProperties = target.resolve("AppProperties").resolve("database.properties");
Files.createDirectories(databaseProperties.getParent());
Set<Integer> iconColl = new HashSet<>();
iconColl.add(NOTE_ID_SPECIAL | NOTE_CLASS_ICON);
try (NNote acl = database.getNoteByID(NOTE_ID_SPECIAL | NOTE_CLASS_ACL)) {
iconColl.add(acl.getNoteID());
}
try (OutputStream os = new CommonsSwiperOutputStream(databaseProperties, isSwiperFilter())) {
exporter.export(database, iconColl, os);
}
// Output the rest according to the settings
exporter.setForceNoteFormat(isBinaryDxl());
exporter.setRichTextAsItemData(isRichTextAsItemData());
database.eachDesignNote((noteId, note) -> {
NoteType type = null;
try {
type = NoteTypeUtil.forNote(note);
exportNote(note, exporter, target);
} catch (Throwable e) {
System.out.println(StringUtil.format(Messages.ODPExporter_nativeExceptionNoteId, Integer.toString(noteId, 16), e.getMessage(), type));
e.printStackTrace(System.out);
}
});
// Export several notes specially
int[] specialIds = new int[] { NOTE_CLASS_ICON, NOTE_CLASS_HELP, NOTE_CLASS_INFO };
for (int id : specialIds) {
try {
try (NNote iconNote = database.getNoteByID(NOTE_ID_SPECIAL | id)) {
if (iconNote != null && iconNote.isRefValid()) {
exportNote(iconNote, exporter, target);
}
}
} catch (NDominoException e) {
switch(e.getStatus()) {
case 578:
// "Special database object cannot be located", which is fine
break;
default:
e.printStackTrace();
System.out.println(StringUtil.format(Messages.ODPExporter_nativeExceptionSpecialNote, id, e.getMessage()));
break;
}
} catch (Throwable e) {
e.printStackTrace();
System.out.println(StringUtil.format(Messages.ODPExporter_nativeExceptionSpecialNote, id, e.getMessage()));
}
}
generateManifestMf(target);
generateEclipseProjectFile(target);
createClasspathDirectories(target);
createStubFiles(target);
}
if (odpType == ODPType.ZIP) {
target.getFileSystem().close();
}
return returnPath;
}
Aggregations