Connect Lotus Domino Server through Standalone Application with CORBA

This article discusses Lotus Domino Notes, especially how to access to the documents stored in it with CORBA. This feature allow developers to write standalone applications that will use documents of Lotus. Moreover, the developer won’t have to learn CORBA because the Lotus Domino Server has already mapped all interfaces, so we are pure users of an API. This article assumes you already have installed a Lotus Domino Server, configured the IIOP properly, and that you know how to create nsf database files.

What is Lotus Domino?

Lotus Domino is a documental database server, which include additional services such as a web server, mail server, LDAP server for users, a client designer to make applications for Lotus Notes, and connectivity to other database management systems.


First of all we have to configure Lotus Domino Server because it can accept IIOP requests. After this, we suppose we have already developed the database in Lotus Domino, (this article does not cover this topic), we have to download (from IBM site or see in resource link at the end of this article), the API to connect. The API called NCSO.jar or NCSW.jar. This API has classes and a lot of interfaces that represent all the objects and connections that we may have in a Lotus Notes. 

Get the Database

The first step we take, is get a connection from database.

Session s = NotesFactory.createSession(Ip,Usr,Passwd);
Database database = s.getDatabase(“”,”firstfact.nsf”);

We create a session object. To create it, we must specify the IP of the server, the username, and the password. After this, we must return an interface of the database we want to work — in this case firstfact.nsf. 

{mospagebreak title=Start Working with Documents}

Creating a Document

Creating a document and filling the information is as easy as:

Document Doc = this.database.createDocument();
Doc.replaceItemValue(“name”,”Alex Soto Bueno”);

We have to create the document and call the method replaceItemValue, where the first argument is the name of the field, and the second, its content. The content argument is a class java.lang.Object. This is because in single value fields, we pass a String, but in multiple values fields we can put a java.util.Vector with all the Strings we want to save.

Furthermore, we have the ability of attach files. Note: the files must be resident in Lotus Domino Server, not in the client application. A good solution can be to upload them beforehand with FTP. When the file is already attached in the server, we must do this:

RichTextItem body = doc.createRichTextItem(“Body”);
body.embedObject(EmbeddedObject.EMBED_ATTACHMENT ,””, “c:inetpubftproot22572.txt”, “22572.txt”);

We will use RichTextItem class. This class has methods to transform the data into XML, copy attachments, consult its content …

What we do in the code is to create in field called Body, a RichTextItem, and in this case we paste a file that is located in c:inetpubftproot22572.txt in the SERVER.

Document class has a lot of methods to interact with a Lotus Document. It’s simple, and by consulting javadoc, you will be able to execute all operations against Domino.

The last thing you must do is to save a document. This is obvious but it easy to forget.; 

{mospagebreak title=Looking for Documents}

We explain methods to search documents, with a View, object and with the Database object.

With Database, we search with method Search or method FTSearch. The differences are, Search have an argument which represents notes @function formula that specifies the selection criteria.

DocumentCollection dc =“Subject = “” + mySubject + “””);

With FTSearch executes a full-text query.

DocumentCollection dc = db.FTSearch(“red & blue”, 100);

Return all documents that match red and blue, but at maximum of 100.

With a View, prior we must have created it in the Domino, we can search documents as simple as:

View view = db.getView(“By Category”); DocumentCollection dc = view.getAllDocumentsByKey(“Leather”);

This code gets all the documents in the category “Leather” in the By Category view of the current database The DocumentCollection class is a collection, and you navigate through it.

DocumentCollection dc = database.getAllDocuments();
Document doc = dc.getFirstDocument();
while (doc != null)
    doc = dc.getNextDocument();

We put all documents of given database into DocumentCollection, and then we print the value of the field Subject.

{mospagebreak title=Working with Received Mails}

As you know, Lotus Notes is a document management tool, but also is an email client. An email document is treated like any other document in Lotus, but they have a special fields to consult:

  • Posted Date
  • Delivered Date
  • From
  • Send To
  • Subject
  • Body
  • Attachments

And a lot of more information. To view this values, you only have to make the connection to your email repository. After that, you can retrieve a document collection object. With every document , using getItemValue() and getItemValueString() depends of what attribute you want, you will retrieve all information. With attachments, it’s a bit different, but with the next simple example, all will be understood.

Attribute NameAttributeReturn Type
SendToSend To (cc too)java.util.Vector
PostedDatePosted Datejava.lang.String
DeliveredDateDelivered Datejava.lang.String

*) the body of an email, it’s save in a multiple RichTextItem, so you must use a StringBuffer to catching all information. Because we use this method in the theme Deleting Attachments, please refer to this section the see an example.


Also note that with dates, you can also retrieve an object of lotus.domino.DateTime with method getItemValueDateTimeArray(“…”). This method will return a vector of DateTime objects, and then you will loop through the vector.

Retrieving Attachments
Vector list = new Vector();
if (pDocument.hasEmbedded())
     Enumeration e = pDocument.getItems().elements();
     while (e.hasMoreElements())
         Item it = (Item)e.nextElement();
         if (it.getType()==Item.ATTACHMENT)
     return list;

What you can see in the previous code is that, firstly you look if the document has embedded information, if it has you return an enumeration of all Items that are into the document. Then you filter all documents, only allowing attachments, and then you save it into a vector object. What you save into the vector is an EmbeddedObject.

Once fact this, with EmbeddedObject you can save it to disk using:

String Filename = oEmbeddedObject.getSource();
oEmbeddedObject.extractFile(Path + Filename);

With extractFile method will copy the attachment where you pass with parameter.

Like all Lotus documents, you can delete fields, modify, copy, extract attachments, delete attachments. This is a very important feature, because you could filter all e-mails. 

{mospagebreak title=Deleting Attachments}

Deleting attachments from a file isn’t as easy as we think because the attachments could go with body text, and an email could have more than one body. Because of that, we need to retrieve all Body fields, save them to a buffer, (only text), remove it, and then recreate only with the buffer information.

String bod = new String();
RichTextItem body = (RichTextItem)oDocument.getFirstItem(“Body”);
    bod +=new String(body.getFormattedText(false, 0, 0));
    body = (RichTextItem)oDocument.getFirstItem(“Body”);
RichTextItem body2 = oDocument.createRichTextItem(“Body”);

As you can see in the first part of the algorithm, what we do is save all text information into a String object and we remove the body section. It would be better use StringBuffer. Then we create a new body, and we append all the text previously kept. 

Linking Documents

Linking documents to other documents is a very important feature because you can divide one document in multiple documents, with all documents linked, so when you consult, you can navigate through documents.

RichTextItem body = oDocument.createRichTextItem(“Body”);
body.appendText(“Link to Other Document”);

The code is so simple; we create a RichTextItem object, first we append a text, and then we append a document. What we would see is a document icon, and when we push it, we will jump to the document we have already appended. 

{mospagebreak title=Conclusion}

As you can see, it’s simple to access to Lotus Domino Notes from an external resource. You don’t need to learn CORBA, and it is similar to accessing in RDBMS.

Now you have the ability to create standalone applications that can connect to a Lotus Domino Server and execute operations. This document only resumes the common operations, and it’s a base to understand the next operations you are able to execute under Domino server.

All examples here have been proven in Domino Server 5.0 and Domino Server 6.5. One common problem is the configuration of DIIOP. When you try to connect with Domino, it jumps an ConnectException caused by “unable to connect to IOP”. Please be sure to configure it properly, and sometimes, when it has been configured, you must restart the IOP Server.

For any problems, feel free for sending an email, and I will reply when I have a free moment. 

References and Resources

1. Lotus DeveloperWorks Homepage
2. Download NCSO.jar or NCSOW.jar 

[gp-comments width="770" linklove="off" ]

chat sex hikayeleri Ensest hikaye