Retrieve list of documents in Lotus Notes database
This task use java to retrieve list of documents in Lotus Notes database.
Filter documents with aliases
- Create getDocuments method as following
- Call getDocuments method as following
try { String idfile = "path to your id file"; String password = "your password"; // <server>!!<filepath> | <filepath> String filename = "path to database file"; String form = "your form"; String filter = "your document filter"; NotesThread.sinitThread(); Session s = NotesFactory.createSessionWithFullAccess(); s.createRegistration().switchToID(idfile, password); Database d = openDatabase(s, filename); DocumentCollection dc = getDocuments(d, form, filter); logger.info(dc.getCount()); d.recycle(); s.recycle(); } catch (Exception e) { logger.info("", e); }getDocuments method
public DocumentCollection getDocuments(Database database, String form, String filter) throws Exception { if (filter.trim().length() == 0) { return database.search(grabFormCond(database, form)); } else { return database.search(grabFormCond(database, form) + " & (" + filter + ")"); } } private String grabFormCond(Database database, String form) throws Exception { String target = "((Form='" + form + "')"; try { Vector aliases = database.getForm(form).getAliases(); for (int i = 0; i < aliases.size(); i++) { target += "|(Form='" + aliases.get(i) + "')"; } } catch (Exception e) { logger.error("", e); } return target + ")"; }
No comments:
Post a Comment