Search in sources :

Example 1 with NDXLExporter

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;
}
Also used : Path(java.nio.file.Path) CommonsSwiperOutputStream(org.openntf.nsfodp.exporter.io.CommonsSwiperOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) NNote(org.openntf.nsfodp.commons.odp.notesapi.NNote) NDominoException(org.openntf.nsfodp.commons.odp.notesapi.NDominoException) NoteType(org.openntf.nsfodp.commons.NoteType) NDXLExporter(org.openntf.nsfodp.commons.odp.notesapi.NDXLExporter) CommonsSwiperOutputStream(org.openntf.nsfodp.exporter.io.CommonsSwiperOutputStream) HashSet(java.util.HashSet)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 NoteType (org.openntf.nsfodp.commons.NoteType)1 NDXLExporter (org.openntf.nsfodp.commons.odp.notesapi.NDXLExporter)1 NDominoException (org.openntf.nsfodp.commons.odp.notesapi.NDominoException)1 NNote (org.openntf.nsfodp.commons.odp.notesapi.NNote)1 CommonsSwiperOutputStream (org.openntf.nsfodp.exporter.io.CommonsSwiperOutputStream)1