Thursday 22 December 2011

Retrieve name of current user of Lotus Notes by java

Retrieve name of current user of Lotus Notes by java
This task use java to retrieve name of current user of Lotus Notes.
Extract name of current user of Lotus Notes
  1. Create getUsername method as following
  2. Call getUsername method as following
Call method
try {
    String idfile = "path to your id file";
    String password = "your password";
    NotesThread.sinitThread();
    Session s = NotesFactory.createSessionWithFullAccess();
    s.createRegistration().switchToID(idfile, password);
    String username = getUsername(s);
    logger.info(username);
} catch (Exception e) {
    logger.info("", e);
}
    
getUsername method
private String getUsername(Session session) throws Exception {
    String noteUser = session.getUserName();
    String[] fields = noteUser.split("/");
    for (int i = 0; i < fields.length; i++) {
        int pos = fields[i].indexOf("=");
        if (i == 0) {
            noteUser = fields[i].substring(pos + 1);
        } else {
            noteUser += "/" + fields[i].substring(pos + 1);
        }
    }
    return noteUser;
}
    

  Protected by Copyscape Online Copyright Protection

No comments:

Post a Comment