I am using the Java-API for Lotus Notes/Domino. I need to place Lotus-Documents inside auf Lotus-Folders (Views) which are organised like folders in the file system.
To find and optionaly create a folder I use the following code. The path-String uses the backslash separator (i.e. "TestFolder/SubFolder1/SubSubFolder1". The folders are created and displayed in the notes client as expected.
View view = database.getView(path);
if (view == null) {
db.enableFolder(path);
view = db.getView(path);
}
How can I find all subfolders of a specific folder?
Right now I am using this workaround. Imho this ist not very nice, because I am always reading ALL directories. When the structure gets larger, this will probably have an impact on the performance.
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);
}
}
}
}
Unfortunately there is no really fast way of doing this. If you really need performance, then the only way to make it a significantly faster is to work with NoteCollection- Class and get all folders. Then run through the NotesDocuments representing the folders and read the item "$Title". Here is example code of doing this:
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)) {
....
}
}
In my tests this was factor 2-3 faster than using the getViews()- method.