The applet explained below best describes one of the many advantages , and in fact only way(not using agents etc), of java in Lotus Domino.
About the Applet : It displays a progress bar with the current mail file size & quota (if set), and % used.(updated every 10000 Millisecs). Thus giving the user an indication about their mail file usage.
Logic : The applet starts a Thread as soon as it loads and establishes a session with domino. The Thread runs in a infinite loop .ie.,thread sleeps for 10000 millisecs and then fetches the db size, quota and calculates % used. If their is a change in these parameters, the repaint() method of the applet is called to update the progress bar.
How to use : Compile the program (with the right classpath set), create an applet resource. Insert the applet in a form. Set its height ,width to 100 pixels and 30 pixels resp. Create a field near to the applet and find your mail quota and set to this field using postopen method. Ensure Enable java applets is selected in the user preferences.
Applicability : We have customized the welcome page for our organisation and my applet has taken up a corner of it(occupies very little space). So it can be used in the welcome page, mail frameset ,portals etc.
Restriction: Works fine in client. It can be further modified to work on web also (CORBA).
Code
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Font;
import lotus.domino.Session;
import lotus.domino.DbDirectory;
import lotus.domino.Database;
import lotus.domino.AppletBase;
import lotus.domino.NotesThread;
public class Simple extends AppletBase implements Runnable
{
private Session session=null;
private DbDirectory dbDir=null;
private Database mailDb=null;
private double quota=0.0,prevQuota=0.0;
private double fileSize=0.0,prevFileSize=0.0;
private Thread listener=null;
private int usedVal=0;
public void notesAppletInit()
{
try
{
NotesThread.sinitThread();
session = this.getSession();
dbDir = session.getDbDirectory(null);
mailDb = dbDir.openMailDatabase();
setBackground(new Color(239,239,239));
if(mailDb!=null)
{
quota = mailDb.getSizeQuota();
if(quota<=0)
{
repaint();
}
else
{
listener = new Thread(this);
listener.start();
}
}
}
catch(Exception e)
{
System.out.println("Notes Applet Start Exception " + e);
}
finally
{
NotesThread.stermThread();
}
}
public void run()
{
try
{
NotesThread.sinitThread();
while(true)
{
if(mailDb!=null)
{
quota = mailDb.getSizeQuota();
fileSize = mailDb.getSize();
}
if(quota!=0.0 && fileSize!=0.0)
{
quota = quota/1024;
fileSize = fileSize/(1024*1024);
usedVal = (int) Math.floor((fileSize/quota)*100);
if(quota!=prevQuota || fileSize!=prevFileSize)
{
prevQuota = quota;
prevFileSize = fileSize;
repaint();
}
listener.sleep(10000);
}
}
}
catch(Exception e)
{
System.out.println("Run Exception " + e);
}
finally
{
listener=null;
NotesThread.stermThread();
}
}
public void paint(Graphics g)
{
try
{
NotesThread.sinitThread();
if(quota<=0)
{
g.drawString("Mail quota is not set",1,15);
}
else
{
g.setColor(new Color(11,148,212));
g.fill3DRect(0,0,usedVal,30,true);
g.setColor(Color.black);
g.setFont(new Font("Arial",Font.PLAIN,9));
if(usedVal<=15)
{
g.drawString(Math.ceil(fileSize)+" mb",10,12);
g.drawString(usedVal +" %",10,28);
}
else if(usedVal>=85)
{
g.drawString(usedVal +" %",75,28);
g.drawString(Math.ceil(fileSize)+" mb",60,12);
}
else
{
g.drawString(usedVal +" %",usedVal-12,28);
g.drawString(Math.ceil(fileSize)+" mb",usedVal-12,12);
}
}
}
catch(Exception e)
{
System.out.println("Paint Exception " + e);
}
finally
{
NotesThread.stermThread();
}
}
public void notesAppletDestroy()
{
try
{
session = null;
dbDir = null;
mailDb = null;
}
catch(Exception e)
{
System.out.println("Destroy Exception " + e);
}
}
}