我正在使用 Lotus Notes/Domino 的 Java-API。我需要将 Lotus-Documents 放入 auf Lotus-Folders( View )中,这些文件夹的组织方式类似于文件系统中的文件夹。
要查找并可选地创建一个文件夹,我使用以下代码。路径字符串使用反斜杠分隔符(即“TestFolder/SubFolder1/SubSubFolder1”)。文件夹将按预期创建并显示在笔记客户端中。
View view = database.getView(path);
if (view == null) {
db.enableFolder(path);
view = db.getView(path);
}
如何查找特定文件夹的所有子文件夹?
现在我正在使用这个解决方法。恕我直言,这不是很好,因为我总是在阅读所有目录。当结构变大时,这可能会对性能产生影响。
List<View> result = new ArrayList<View>();
String prefix = getPath() + getSeparator();
for (Object obj : database.getViews()) {
View view = (View)obj;
if (view.isFolder()) {
String path = view.getName();
if (path.startsWith(prefix)) {
String suffix = path.substring(prefix.length());
if (suffix.indexOf(getSeparator()) == -1) {
result.add(view);
}
}
}
}
最佳答案
不幸的是,没有真正快速的方法来做到这一点。如果您确实需要性能,那么显着加快速度的唯一方法是使用 NoteCollectionClass 并获取所有文件夹。然后运行代表文件夹的 NotesDocuments 并读取项目“$Title”。以下是执行此操作的示例代码:
NoteCollection nc = database.createNoteCollection(false);
nc.setSelectFolders(true);
nc.buildCollection();
String id = nc.getFirstNoteID();
while (id.length() > 0) {
String strFolderName = ""
Document docFolder = database.getDocumentByID(strFolderId);
strFolderName = docFolder.getItemValueString("$Title");
if (strFolderName.startsWith(prefix)) {
....
}
}
在我的测试中,这比使用 getViews() 方法快 2-3 倍。
关于java - 如何在 Lotus Notes 中查找文件夹( View )的所有子文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22660132/