diff --git a/domino-jna/src/main/java/com/mindoo/domino/jna/NotesItem.java b/domino-jna/src/main/java/com/mindoo/domino/jna/NotesItem.java index 3214c6bc..8f0c97c7 100644 --- a/domino-jna/src/main/java/com/mindoo/domino/jna/NotesItem.java +++ b/domino-jna/src/main/java/com/mindoo/domino/jna/NotesItem.java @@ -676,6 +676,40 @@ public void copyToNote(NotesNote targetNote, boolean overwrite) { } } + /** + * Copies this item to another note and renames it. + * + * @param targetNote target note + * @param newItemName name of the item copy + * @param overwrite true to overwrite an existing item in the target note; otherwise, the target note may contain multiple items with the same name + */ + public void copyToNote(NotesNote targetNote, String newItemName, boolean overwrite) { + m_parentNote.checkHandle(); + targetNote.checkHandle(); + + if (overwrite) { + if (targetNote.hasItem(newItemName)) { + targetNote.removeItem(newItemName); + } + } + Memory newItemNameMem = NotesStringUtils.toLMBCS(newItemName, true); + + NotesBlockIdStruct.ByValue itemBlockIdByVal = NotesBlockIdStruct.ByValue.newInstance(); + itemBlockIdByVal.pool = m_itemBlockId.pool; + itemBlockIdByVal.block = m_itemBlockId.block; + + if (PlatformUtils.is64Bit()) { + short result = NotesNativeAPI64.get().NSFItemCopyAndRename(targetNote.getHandle64(), + itemBlockIdByVal, newItemNameMem); + NotesErrorUtils.checkResult(result); + } + else { + short result = NotesNativeAPI32.get().NSFItemCopyAndRename(targetNote.getHandle32(), + itemBlockIdByVal, newItemNameMem); + NotesErrorUtils.checkResult(result); + } + } + /** * Removes the item from the parent note */ diff --git a/domino-jna/src/main/java/com/mindoo/domino/jna/internal/INotesNativeAPI32.java b/domino-jna/src/main/java/com/mindoo/domino/jna/internal/INotesNativeAPI32.java index 79163ec5..1e5fafef 100644 --- a/domino-jna/src/main/java/com/mindoo/domino/jna/internal/INotesNativeAPI32.java +++ b/domino-jna/src/main/java/com/mindoo/domino/jna/internal/INotesNativeAPI32.java @@ -404,7 +404,9 @@ public short NSFNoteOpenWithLock( IntByReference rethNote); public short NSFItemCopy(int note_handle, NotesBlockIdStruct.ByValue item_blockid); - + @UndocumentedAPI + public short NSFItemCopyAndRename (int hNote, NotesBlockIdStruct.ByValue bhItem, Memory pszNewItemName); + public short IDCreateTable (int alignment, IntByReference rethTable); public short IDDestroyTable(int hTable); public short IDInsert (int hTable, int id, IntByReference retfInserted); diff --git a/domino-jna/src/main/java/com/mindoo/domino/jna/internal/INotesNativeAPI64.java b/domino-jna/src/main/java/com/mindoo/domino/jna/internal/INotesNativeAPI64.java index 92aafe5c..96d26eea 100644 --- a/domino-jna/src/main/java/com/mindoo/domino/jna/internal/INotesNativeAPI64.java +++ b/domino-jna/src/main/java/com/mindoo/domino/jna/internal/INotesNativeAPI64.java @@ -404,6 +404,9 @@ public short NSFNoteOpenWithLock( LongByReference rethNote); public short NSFItemCopy(long note_handle, NotesBlockIdStruct.ByValue item_blockid); + @UndocumentedAPI + public short NSFItemCopyAndRename (long hNote, NotesBlockIdStruct.ByValue bhItem, Memory pszNewItemName); + public short IDCreateTable (int alignment, LongByReference rethTable); public short IDDestroyTable(long hTable); public short IDInsert (long hTable, int id, IntByReference retfInserted); diff --git a/domino-jna/src/main/java/com/mindoo/domino/jna/internal/NotesNativeAPI32.java b/domino-jna/src/main/java/com/mindoo/domino/jna/internal/NotesNativeAPI32.java index 94a49295..80759ea0 100644 --- a/domino-jna/src/main/java/com/mindoo/domino/jna/internal/NotesNativeAPI32.java +++ b/domino-jna/src/main/java/com/mindoo/domino/jna/internal/NotesNativeAPI32.java @@ -393,6 +393,7 @@ public native short NSFNoteOpenWithLock(int hDB, int NoteID, int LockFlags, int IntByReference rethLockers, IntByReference retLength, IntByReference rethNote); public native short NSFItemCopy(int note_handle, NotesBlockIdStruct.ByValue item_blockid); + public native short NSFItemCopyAndRename(int hNote, ByValue bhItem, Memory pszNewItemName); public native short IDCreateTable (int alignment, IntByReference rethTable); public native short IDDestroyTable(int hTable); diff --git a/domino-jna/src/main/java/com/mindoo/domino/jna/internal/NotesNativeAPI64.java b/domino-jna/src/main/java/com/mindoo/domino/jna/internal/NotesNativeAPI64.java index 7323bcd2..05be1f54 100644 --- a/domino-jna/src/main/java/com/mindoo/domino/jna/internal/NotesNativeAPI64.java +++ b/domino-jna/src/main/java/com/mindoo/domino/jna/internal/NotesNativeAPI64.java @@ -392,6 +392,8 @@ public native short NSFNoteOpenWithLock(long hDB, int NoteID, int LockFlags, int LongByReference rethLockers, IntByReference retLength, LongByReference rethNote); public native short NSFItemCopy(long note_handle, NotesBlockIdStruct.ByValue item_blockid); + public native short NSFItemCopyAndRename(long hNote, ByValue bhItem, Memory pszNewItemName); + public native short IDCreateTable (int alignment, LongByReference rethTable); public native short IDDestroyTable(long hTable); public native short IDInsert (long hTable, int id, IntByReference retfInserted);