Pages

Monday, December 28, 2009

Get the names of all databases to which you have access to

/**
* Method to get the names of all databases to which you have access to
* @param : serverName- name of the server from which the database names needs to be retrieved
* @param : userName- name of the user having access to
* @return : boolean
* @see : boolean checkAccessToDatabase(Database targetDB, String userName) ---> http://ozinisle.blogspot.com/2009/12/check-access-to-lotusnotes-database.html
*/

public Vector getAllDatabases(Session session, String serverName,String userName) {
Vector allDbs = new Vector();
int incre = 0 ;
int countedDbs=0;
try {
DbDirectory dir = session.getDbDirectory(serverName);
Database db = dir.getFirstDatabase(DbDirectory.TEMPLATE_CANDIDATE);
while (db != null) {
incre = incre + 1;
if (checkAccessToDatabase(db,userName)) {
countedDbs++;
allDbs.add(db.getFilePath());
}
db = dir.getNextDatabase();
}
//System.out.println("You have access to "+countedDbs+" out of "+incre+ " databases");
session.recycle();
} catch(Exception e) {
e.printStackTrace();
}
return allDbs;
}

No comments:

Post a Comment