Search in sources :

Example 1 with NDominoException

use of org.openntf.nsfodp.commons.odp.notesapi.NDominoException in project org.openntf.nsfodp by OpenNTF.

the class DarwinoNDatabase method eachDesignNote.

@Override
public void eachDesignNote(BiConsumer<Integer, NNote> consumer) {
    NSFSEARCHPROC proc = new NSFSEARCHPROC() {

        @Override
        public short callback(long searchMatchPtr, long summaryBufferPtr) throws DominoException {
            SEARCH_MATCH searchMatch = new SEARCH_MATCH();
            C.memcpy(searchMatch.getDataPtr(), 0, searchMatchPtr, 0, SEARCH_MATCH.sizeOf);
            short noteClass = searchMatch.getNoteClass();
            int noteId = searchMatch.getId().getNoteId();
            byte retFlags = searchMatch.getSERetFlags();
            boolean deleted = (noteClass & DominoAPI.NOTE_CLASS_NOTIFYDELETION) != 0;
            // The use of "since" means that non-matching notes will be returned; check this flag to make sure
            boolean isSearchMatch = (retFlags & DominoAPI.SE_FMATCH) != 0;
            if (isSearchMatch && !deleted) {
                try (NNote note = getNoteByID(noteId)) {
                    consumer.accept(noteId, note);
                }
            }
            return DominoAPI.NOERROR;
        }
    };
    try {
        // $NON-NLS-1$
        database.search("@All", proc, (short) 0, DominoAPI.NOTE_CLASS_ALLNONDATA, null, null);
    } catch (DominoException e) {
        throw new NDominoException(e.getStatus(), e);
    } catch (FormulaException e) {
        throw new NDominoException(0, e);
    }
}
Also used : NNote(org.openntf.nsfodp.commons.odp.notesapi.NNote) NDominoException(org.openntf.nsfodp.commons.odp.notesapi.NDominoException) NSFSEARCHPROC(com.darwino.domino.napi.proc.NSFSEARCHPROC) SEARCH_MATCH(com.darwino.domino.napi.struct.SEARCH_MATCH) FormulaException(com.darwino.domino.napi.wrap.FormulaException) DominoException(com.darwino.domino.napi.DominoException) NDominoException(org.openntf.nsfodp.commons.odp.notesapi.NDominoException)

Example 2 with NDominoException

use of org.openntf.nsfodp.commons.odp.notesapi.NDominoException in project org.openntf.nsfodp by OpenNTF.

the class DarwinoNotesAPI method createDXLExporter.

@Override
public NDXLExporter createDXLExporter() {
    try {
        NSFDXLExporter exporter = session.createDXLExporter();
        exporter.setExportCharset(DXL_EXPORT_CHARSET.Utf8);
        exporter.setOutputDoctype(false);
        return new DarwinoNDXLExporter(exporter);
    } catch (DominoException e) {
        throw new NDominoException(e.getStatus(), e);
    }
}
Also used : NDominoException(org.openntf.nsfodp.commons.odp.notesapi.NDominoException) NSFDXLExporter(com.darwino.domino.napi.wrap.NSFDXLExporter) DominoException(com.darwino.domino.napi.DominoException) NDominoException(org.openntf.nsfodp.commons.odp.notesapi.NDominoException)

Example 3 with NDominoException

use of org.openntf.nsfodp.commons.odp.notesapi.NDominoException in project org.openntf.nsfodp by OpenNTF.

the class DarwinoNDXLExporter method export.

@Override
public void export(NNote note, OutputStream os) {
    try {
        NSFNote n = ((DarwinoNNote) note).getNSFNote();
        this.exporter.export(n, os);
    } catch (DominoException e) {
        throw new NDominoException(e.getStatus(), e);
    }
}
Also used : NDominoException(org.openntf.nsfodp.commons.odp.notesapi.NDominoException) NSFNote(com.darwino.domino.napi.wrap.NSFNote) DominoException(com.darwino.domino.napi.DominoException) NDominoException(org.openntf.nsfodp.commons.odp.notesapi.NDominoException)

Example 4 with NDominoException

use of org.openntf.nsfodp.commons.odp.notesapi.NDominoException in project org.openntf.nsfodp by OpenNTF.

the class ODPCompiler method compileLotusScript.

private void compileLotusScript(NDatabase database, List<Integer> noteIds, boolean retry) {
    if (!noteIds.isEmpty()) {
        try {
            // $NON-NLS-1$
            Class.forName("lotus.domino.websvc.client.Stub");
        } catch (ClassNotFoundException e) {
            subTask(Messages.ODPCompiler_webServiceNotFound1);
            subTask(Messages.ODPCompiler_webServiceNotFound2);
            return;
        }
        subTask(Messages.ODPCompiler_compilingLotusScript);
        // In lieu of a dependency graph, just keep bashing at the list until it's done
        Queue<Integer> remaining = new ArrayDeque<>(noteIds);
        Map<Integer, String> titles = new HashMap<>();
        for (int i = 0; i < noteIds.size(); i++) {
            Queue<Integer> nextPass = new ArrayDeque<>();
            Integer noteId;
            while ((noteId = remaining.poll()) != null) {
                String title = null;
                try (NNote note = database.getNoteByID(noteId)) {
                    // Check to see if this is the Shared Actions note, which we should skip to avoid trouble
                    if ((note.getNoteClassValue() & NsfNote.NOTE_CLASS_NONPRIV) == NsfNote.NOTE_CLASS_FORM) {
                        String flags = note.getAsString(StdNames.DESIGN_FLAGS, ' ');
                        if (NSFODPUtil.matchesFlagsPattern(flags, DFLAGPAT_SACTIONS_DESIGN)) {
                            continue;
                        }
                    }
                    // $NON-NLS-1$
                    title = note.get("$TITLE", String.class);
                    titles.put(noteId, title);
                    note.compileLotusScript();
                    note.sign();
                    note.save();
                } catch (NLotusScriptCompilationException err) {
                    nextPass.add(noteId);
                    // $NON-NLS-1$
                    titles.put(noteId, title + " - " + err);
                } catch (NDominoException err) {
                    if (err.getStatus() == 12051) {
                        // Same as above, but not encapsulated
                        // $NON-NLS-1$
                        titles.put(noteId, title + " - " + err);
                        nextPass.add(noteId);
                    } else if (err.getStatus() == 0x222) {
                    // Note item not found - occurs for non-LS elements
                    } else {
                        throw err;
                    }
                }
            }
            remaining = nextPass;
            if (nextPass.isEmpty()) {
                break;
            }
        }
        if (!retry && !remaining.isEmpty()) {
            String notes = remaining.stream().map(// $NON-NLS-1$ //$NON-NLS-2$
            noteId -> "Note ID " + noteId + ": " + titles.get(noteId)).collect(// $NON-NLS-1$
            Collectors.joining("\n"));
            throw new RuntimeException(MessageFormat.format(Messages.ODPCompiler_unableToCompileLotusScript, notes));
        }
    }
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) NDominoException(org.openntf.nsfodp.commons.odp.notesapi.NDominoException) FileResource(org.openntf.nsfodp.commons.odp.FileResource) NNote(org.openntf.nsfodp.commons.odp.notesapi.NNote) NotesAPI(org.openntf.nsfodp.commons.odp.notesapi.NotesAPI) CustomControl(org.openntf.nsfodp.commons.odp.CustomControl) ByteArrayInputStream(java.io.ByteArrayInputStream) Document(org.w3c.dom.Document) Map(java.util.Map) Bundle(org.osgi.framework.Bundle) Path(java.nio.file.Path) XPage(org.openntf.nsfodp.commons.odp.XPage) DynamicFacesClassLoader(com.ibm.xsp.extlib.interpreter.DynamicFacesClassLoader) DateFormat(java.text.DateFormat) JavaSourceClassLoader(com.ibm.xsp.extlib.javacompiler.JavaSourceClassLoader) MultiPathResourceBundleSource(org.openntf.nsfodp.compiler.util.MultiPathResourceBundleSource) PrintWriter(java.io.PrintWriter) Os(com.ibm.domino.napi.c.Os) Collection(java.util.Collection) NsfNote(org.openntf.nsfodp.commons.h.NsfNote) DFLAGPAT_SACTIONS_DESIGN(org.openntf.nsfodp.commons.h.StdNames.DFLAGPAT_SACTIONS_DESIGN) CompilerUtil(org.openntf.nsfodp.compiler.util.CompilerUtil) Set(java.util.Set) Collectors(java.util.stream.Collectors) XSPCompilationResult(org.openntf.nsfodp.commons.odp.XSPCompilationResult) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) BundleContext(org.osgi.framework.BundleContext) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) NSFODPUtil(org.openntf.nsfodp.commons.NSFODPUtil) FacesClassLoader(com.ibm.xsp.library.FacesClassLoader) FacesSharableRegistry(com.ibm.xsp.registry.FacesSharableRegistry) LotusScriptLibrary(org.openntf.nsfodp.commons.odp.LotusScriptLibrary) NDXLImporter(org.openntf.nsfodp.commons.odp.notesapi.NDXLImporter) CompositeComponentDefinitionImpl(com.ibm.xsp.registry.CompositeComponentDefinitionImpl) Queue(java.util.Queue) Pattern(java.util.regex.Pattern) ODPUtil(org.openntf.nsfodp.commons.odp.util.ODPUtil) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AbstractSplitDesignElement(org.openntf.nsfodp.commons.odp.AbstractSplitDesignElement) NDatabase(org.openntf.nsfodp.commons.odp.notesapi.NDatabase) DXLError(org.openntf.nsfodp.compiler.dxl.DxlImporterLog.DXLError) JavaCompilerException(com.ibm.xsp.extlib.javacompiler.JavaCompilerException) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) Function(java.util.function.Function) StandardCopyOption(java.nio.file.StandardCopyOption) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) StdNames(org.openntf.nsfodp.commons.h.StdNames) DxlImporterLog(org.openntf.nsfodp.compiler.dxl.DxlImporterLog) OnDiskProject(org.openntf.nsfodp.commons.odp.OnDiskProject) ConfigParserFactory(com.ibm.xsp.registry.parse.ConfigParserFactory) NLotusScriptCompilationException(org.openntf.nsfodp.commons.odp.notesapi.NLotusScriptCompilationException) ConfigParser(com.ibm.xsp.registry.parse.ConfigParser) OutputStream(java.io.OutputStream) LibraryFragmentImpl(com.ibm.xsp.registry.LibraryFragmentImpl) Properties(java.util.Properties) Files(java.nio.file.Files) StringWriter(java.io.StringWriter) DXLUtil(org.openntf.nsfodp.commons.dxl.DXLUtil) IOException(java.io.IOException) JavaSource(org.openntf.nsfodp.commons.odp.JavaSource) DXLFatalError(org.openntf.nsfodp.compiler.dxl.DxlImporterLog.DXLFatalError) UpdatableLibrary(com.ibm.xsp.registry.UpdatableLibrary) Element(org.w3c.dom.Element) StringUtil(com.ibm.commons.util.StringUtil) NException(com.ibm.domino.napi.NException) StreamUtil(com.ibm.commons.util.io.StreamUtil) NSFODPDomUtil(org.openntf.nsfodp.commons.xml.NSFODPDomUtil) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) InputStream(java.io.InputStream) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) NLotusScriptCompilationException(org.openntf.nsfodp.commons.odp.notesapi.NLotusScriptCompilationException) ArrayDeque(java.util.ArrayDeque) NNote(org.openntf.nsfodp.commons.odp.notesapi.NNote) NDominoException(org.openntf.nsfodp.commons.odp.notesapi.NDominoException)

Example 5 with NDominoException

use of org.openntf.nsfodp.commons.odp.notesapi.NDominoException 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

NDominoException (org.openntf.nsfodp.commons.odp.notesapi.NDominoException)8 DominoException (com.darwino.domino.napi.DominoException)6 NNote (org.openntf.nsfodp.commons.odp.notesapi.NNote)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 Path (java.nio.file.Path)2 NSFSEARCHPROC (com.darwino.domino.napi.proc.NSFSEARCHPROC)1 SEARCH_MATCH (com.darwino.domino.napi.struct.SEARCH_MATCH)1 FormulaException (com.darwino.domino.napi.wrap.FormulaException)1 NSFDXLExporter (com.darwino.domino.napi.wrap.NSFDXLExporter)1 NSFDXLImporter (com.darwino.domino.napi.wrap.NSFDXLImporter)1 NSFDatabase (com.darwino.domino.napi.wrap.NSFDatabase)1 NSFNote (com.darwino.domino.napi.wrap.NSFNote)1 NSFNoteIDCollection (com.darwino.domino.napi.wrap.NSFNoteIDCollection)1 StringUtil (com.ibm.commons.util.StringUtil)1 StreamUtil (com.ibm.commons.util.io.StreamUtil)1 NotesAPIException (com.ibm.designer.domino.napi.NotesAPIException)1 NotesDatabase (com.ibm.designer.domino.napi.NotesDatabase)1 NotesNote (com.ibm.designer.domino.napi.NotesNote)1 NotesSession (com.ibm.designer.domino.napi.NotesSession)1