Search in sources :

Example 1 with CommonsSwiperOutputStream

use of org.openntf.nsfodp.exporter.io.CommonsSwiperOutputStream in project org.openntf.nsfodp by OpenNTF.

the class ODPExporter method exportExplicitNote.

/**
 * Exports a note to the provided path.
 *
 * @param note the note to export
 * @param exporter the exporter to use for the process
 * @param baseDir the base directory for export operations
 * @param path the relative file path to export to within the base dir
 * @throws IOException
 */
private void exportExplicitNote(NNote note, NDXLExporter exporter, Path baseDir, Path path) throws IOException {
    Path fullPath = baseDir.resolve(path.toString());
    Files.createDirectories(fullPath.getParent());
    try (OutputStream os = new CommonsSwiperOutputStream(fullPath, isSwiperFilter())) {
        exporter.export(note, os);
    }
}
Also used : Path(java.nio.file.Path) CommonsSwiperOutputStream(org.openntf.nsfodp.exporter.io.CommonsSwiperOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) CommonsSwiperOutputStream(org.openntf.nsfodp.exporter.io.CommonsSwiperOutputStream)

Example 2 with CommonsSwiperOutputStream

use of org.openntf.nsfodp.exporter.io.CommonsSwiperOutputStream 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)2 OutputStream (java.io.OutputStream)2 Path (java.nio.file.Path)2 CommonsSwiperOutputStream (org.openntf.nsfodp.exporter.io.CommonsSwiperOutputStream)2 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