XML-Enabling Your Lotus Notes Application
XML-Enabling Your Lotus Notes Application
Branavan Ganesan
IBM software developer
IBM
07 Feb 2003
This tutorial shows how the team at developerWorks used the XML capabilities of
Lotus Domino to extract data and transfer it to DB2. The same technique can be
used to transform and transfer data to any other relational database engine.
In this tutorial, you'll get a hands-on approach to the design techniques discussed in
"Managing and moving data using Java technology, XML, DB2, and Lotus Notes".
This tutorial shows you how to gather publish-ready metadata documents for
articles, surface them as XML, and invoke an external Java servlet from within Notes
that reads, transforms, converts the information, and updates DB2 accordingly.
Because this tutorial will focus on the Domino portion of this exercise, we won't
cover the external servlet in any detail.
You will be using the JDK 1.1 that ships with Domino to develop the agent within
Domino. If you are feeling adventurous, you might want to try your hand at an
external servlet that acts on the agent. If you need the Java 2 SDK, 1.3.0, you can
download it from http://java.sun.com/j2se/1.3.0_01/index.html. This tutorial does not
cover the coding of the external Java servlet.
Initial setup
Now that the database is downloaded, let's quickly check that everything is in place.
Introduction
Before we dive into the data transfer function, it's a good idea to understand exactly
what the data looks like. In this chapter we'll review:
There is no rocket science here. The first two sections, "General document
information" and "Document searchable information," contain facts about the record.
The last section, "Document tracking information," contains fields that support and
facilitate work management.
Data fields
The data fields in this form describe the characteristics of an article that is published
on the production Web site. Collectively, this constitutes the metadata for a given
article.
Now that we have an overview of the content management form, we'll proceed to the
XML display form, which takes data created and edited using the content
management form and displays it in XML-ready format. Using a form that users are
familiar with in the Domino environment helps keep the back-office work a non-factor
when determining your solution. Users familiar with this form will not need any
training, or changes, for you to implement your data transfer solutions.
The goal is to code the field values so they are interpreted correctly both by the
Domino translation engine and by a parser that is expecting a well-formed XML
document.
• All the fields in the form are set to be computed for display. This is to
avoid data overwrites during an accidental save when viewing documents
using this form.
• The second line is a processing instruction with a reference to the
stylesheet stored as a page design element within the database.
<?xml-stylesheet href="http://hostname.ibm.com/dir/xmlcptut.nsf/datatransfer.xsl"
type="text/xsl"?>
• The XML file will be read as text, with an encoding of UTF-8. Therefore, a
date/time datatype will not be recognized. We change the datatype to text
in the display formula.
• Our database engine is configured to accept dates in the mm-dd-yyyy
format.
Enter the following code into the formula field in the last_mod_date field:
In this case, the function @ReplaceSubstring takes the sourceList, which in this
case is lastmodifieddate, and replaces values in the fromList (/) with the values
in the toList (-). The one twist is that we change the datatype of the date field before
manipulating it.
<contenttopics>
<topic>614708929906D77186256B7B005C919D</topic>
<topic>FCD74466386C241386256B7B005E3AC5</topic>
</contenttopics>
Note the additional snag. In our DB2 tables, the content topics are stored in lookup
tables, so we need to supply the unique id, which will function as the foreign key into
the lookup table. The unique id is obtained using @DbLookup.
We are beginning to get a handle on things. We now have a form that will display a
Notes record as an XML document, but we have more work to do before it can be
tested.
Introduction
Now that we have the display form set up, we'll set up the necessary views to
support it. In this chapter we will look at the main work management view, and build
a view that facilitates the servlet call to Domino.
• The search view, used by the servlet call to locate the document it is
supposed to read in as XML.
• The working view, which allows editors to manipulate which documents
are to be published, updated, deleted, and so on.
There is a third utility view that acts as a DBLookup view, and provides the ability to
substitute content topic value with the corresponding unique id. We won't examine it
in this tutorial because it's standard Domino fare.
Since we are using the form to display data as XML, the views will not be used to
perform this function. But, they will serve as necessary elements to form and
manipulate document collections.
2. Build a new view and call it "XML Document view" with an alias of
"servletview."
This formula corresponds to the status fields in the content submission form, and
ensures that only documents intended to be published appear in this view.
2. Set up the "form formula" for this view to show documents using the XML
display form by entering "XML display form".
Note that this view and the editorial working view could be collapsed by making the
unique id the first sorted column in the view. However, conventional wisdom shows
that collapsing utility functions and work management functions in the same view
can cause complications during later development and enhancement efforts. To test
this view:
1. Open the database using the Domino client and go to the XML document
view.
3. You should see the document opened up in the the display form, showing
the data in the record in XML format.
Good work! Now that this view is set up, you have the essential utility elements
necessary to access Notes data in XML format both within the Domino environment
and from any external call over HTTP.
Working view
It's now time to take care of the end users. Users of the database do not really care
that you are using Java and XML-based technologies to transfer and manipulate
their data. They just want a database that is reliable and easy to use. Creating
design elements to support this is essential for a successful application.
For this application, there are a few pre-built views to support end user work
management. These are by no means exhaustive, but are there to show the types of
supporting views that can be built. As developers of Domino applications, these
views should be familiar to you. Let's take a quick look at the view that shows
publishable documents. This view lets the end user control which documents are
going to be moved to be published.
The progressStatus field and publish_flag field give end users two ways to facilitate
work management and to control which documents are moved for publication.
Showing additional values such as the title and content type give the documents
more meaning.
Introduction
This section of the tutorial takes a quick look at how to build and store Extensible
Stylesheet Language for Transformations (XSLT) stylesheets that transform your
XML documents and store them along with the data. XSLT intricacies and
frustrations constitute a whole subject area unto itself. While it is not covered
extensively in this tutorial, investigation into XSLT is a must for any developer doing
serious work involving XML.
process.
Showtitle.xsl
Type the following code into the body of the page element:
This stylesheet can now be called from our XML document by using the processing
instruction:
<?xml-stylesheet href=
"http://hostname.ibm.com/dir/xmlcptut.nsf/datatransfer.xsl"
type="text/xsl"?>
An Easter egg
In addition to the stylesheet we just went through, I've included another stylesheet as
a page design element in the demo database. We used this stylesheet in the project
to take the data from the XML document we used and generate an SQL statement. It
is provided as is.
Introduction
We will finish this tutorial by looking at the section of a Java agent that invokes an
external servlet. Information about the XML document is passed in the call. Using
this technique allows the inclusion of code outside the Domino environment in the
overall application solution. We will concentrate on the following aspects of the
agent:
The agent
To speed things along, the shell of the agent has been pre-coded. Much of this is
self evident. We will add the method that generates the Notes URL, and will add the
portion of the code that invokes our external servlet.
Notice that the while loop that holds the servlet invocation has been set up in the
main method. The document collection is generated by using the
AgentContext.getUnprocessedDocuments() method. This way, the collection
can change from selected documents to all the documents in the view, depending on
the setting you use for the Which document(s) should it act on property.
Because this code is executed from an agent, a check is added to ensure that the
publish_flag value is not 1. An agent can potentially be invoked from any view
against any document in the database.
Last but not least, note that prior to invoking the servlet, the status fields and
modified date value are changed within the agent. Doing this automatically within the
agent gives users a data value showing what has been promoted and when.
3. Add the following method to the agent before the main method:
e.printStackTrace();
}
return fullURL;
}
Enter the following code under the comment in the main method:
URL servletURL =
new URL("http://hostname.ibm.com/servlet/DataTransfer?notesURL="
+ url + "UNID="+ uniqueid + "propID=IDENTIFIER");
URLConnection uc = servletURL.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(uc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
This code makes use of the URL and URLConnection classes. Once the
connection is set up, the page contents are read by an input stream. We make use
of a BufferedReader, as it has a very helpful readLine() method.
If such a precaution is not necessary, then this step need not be taken. Allowing the
agent to be invoked from the actions list allows users greater flexibity in terms of
which views to use when identifying documents that need to be promoted.
Section 7. Wrapup
Summary
This tutorial has shown you how to collect Domino documents and surface them as
XML documents. We reviewed the data that's in the Notes forms, built views and a
stylesheet to handle the data, and then looked at a Java agent that invokes an
external servlet. With this information in hand, you should be able to apply these
techniques to your own Notes documents.
Resources
• Read the article that accompanies this tutorial, "Managing and moving data
using Java technology, XML, DB2, and Lotus Notes."
Download the demo database called xmlcptut.nsf, which has the base elements
that we'll develop in this tutorial.
There are innumerable resources to guide you on your path to mastering XSLT.
Listed below are some resources that provide basic groundwork, along with
some that are specific to using the XML-enablement capabilities of Lotus
Domino.
• Exercising XML in Domino Designer (Lotus Developer Domain, January
2001)
• "Publishing XML Data using Notes/Domino 6" (Lotus Developer Domain)
• Take the tutorial, "Manipulating data with XSL" (developerWorks, October
2001).
• Take the Introduction to XML tutorial (developerWorks, August 2002)