Monday 26 December 2011

Retrieve list of Lotus Notes forms

Retrieve list of Lotus Notes forms
This task retrieve list of Lotus Notes forms including name and xml data.
Retrieve list of Lotus Notes forms using java, DxlExporter and jsoup
  1. Create getFormList as following
  2. Call getFormList method as following
Call method
try {
    String idfile = "";
    String password = "";
    String server = "";
    String filepath = "";
    NotesThread.sinitThread();
    Session s = NotesFactory.createSessionWithFullAccess();
    s.createRegistration().switchToID(idfile, password);
    Database d = s.getDatabase(server, filepath);
    Map<String, String> forms = getFormList(d);
    for (String key : forms.keySet()) {
        logger.info("Form: " + key);
        logger.info(forms.get(key));
    }
} catch (Exception e) {
    logger.error("", e);
}
    
getFormList method
public Map<String, String> getFormList(Database db) {
    Map<String, String> tag = new HashMap<String, String>();
    try {
        NoteCollection nc = db.createNoteCollection(false);
        nc.setSelectForms(true);
        nc.buildCollection();
        String noteId = nc.getFirstNoteID();
        int fileNo = 0;
        while (noteId != null) {
            try {
                lotus.domino.Document doc = db.getDocumentByID(noteId);
                DxlExporter dxl = db.getParent().createDxlExporter();
                dxl.setConvertNotesBitmapsToGIF(true);
                String xml = dxl.exportDxl(doc);
                dxl.recycle();
                doc.recycle();

                xml = xml.substring(xml.indexOf("<form "));
                org.jsoup.nodes.Document jdoc = Jsoup.parse(xml);
                Element element = jdoc.select("form").first();
                tag.put(element.attr("name"), xml);
            } catch (Exception e) {
                logger.error("", e);
            }
       
            fileNo++;
            if (fileNo == nc.getCount()) {
                noteId = null;
            } else {
                noteId = nc.getNextNoteID(noteId);
            }
        }
        nc.recycle();
    } catch (Exception e) {
        logger.error("", e);
    }
    return tag;
}
    

  Protected by Copyscape Online Copyright Protection

No comments:

Post a Comment